Bug 1526891 - Part 14: Move storage service initialization to InitializeQuotaManager; r=asuth
authorJan Varga <jan.varga@gmail.com>
Sat, 23 Feb 2019 17:32:26 +0100
changeset 520827 830813029a78357c3d45378e4af6be4e68508704
parent 520826 992bfd5a7b28e5ef2709bb32eb7c464c8c580a1c
child 520828 5e8ac40eca965684e299befb6dc3c7d563787a4a
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1526891
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1526891 - Part 14: Move storage service initialization to InitializeQuotaManager; r=asuth Differential Revision: https://phabricator.services.mozilla.com/D20923
dom/quota/ActorsParent.cpp
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -418,34 +418,27 @@ class DirectoryLockImpl final : public D
   NS_INLINE_DECL_REFCOUNTING(DirectoryLockImpl, override)
 
  private:
   ~DirectoryLockImpl();
 };
 
 class QuotaManager::CreateRunnable final : public BackgroundThreadObject,
                                            public Runnable {
-  nsCOMPtr<nsIEventTarget> mMainEventTarget;
   nsTArray<nsCOMPtr<nsIRunnable>> mCallbacks;
   RefPtr<QuotaManager> mManager;
   nsresult mResultCode;
 
-  enum class State {
-    Initial,
-    RegisteringObserver,
-    CallingCallbacks,
-    Completed
-  };
+  enum class State { Initial, CallingCallbacks, Completed };
 
   State mState;
 
  public:
-  explicit CreateRunnable(nsIEventTarget* aMainEventTarget)
+  CreateRunnable()
       : Runnable("dom::quota::QuotaManager::CreateRunnable"),
-        mMainEventTarget(aMainEventTarget),
         mResultCode(NS_OK),
         mState(State::Initial) {
     AssertIsOnBackgroundThread();
   }
 
   void AddCallback(nsIRunnable* aCallback) {
     AssertIsOnOwningThread();
     MOZ_ASSERT(aCallback);
@@ -453,18 +446,16 @@ class QuotaManager::CreateRunnable final
     mCallbacks.AppendElement(aCallback);
   }
 
  private:
   ~CreateRunnable() {}
 
   nsresult Init();
 
-  nsresult RegisterObserver();
-
   void CallCallbacks();
 
   State GetNextState(nsCOMPtr<nsIEventTarget>& aThread);
 
   NS_DECL_NSIRUNNABLE
 };
 
 class QuotaManager::Observer final : public nsIObserver {
@@ -2161,16 +2152,24 @@ nsresult GetTemporaryStorageLimit(nsIFil
  * Exported functions
  ******************************************************************************/
 
 void InitializeQuotaManager() {
   MOZ_ASSERT(XRE_IsParentProcess());
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!gQuotaManagerInitialized);
 
+  if (!QuotaManager::IsRunningGTests()) {
+    // This service has to be started on the main thread currently.
+    nsCOMPtr<mozIStorageService> ss;
+    if (NS_WARN_IF(!(ss = do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID)))) {
+      NS_WARNING("Failed to get storage service!");
+    }
+  }
+
   if (NS_FAILED(QuotaManager::Initialize())) {
     NS_WARNING("Failed to initialize quota manager!");
   }
 
    if (NS_FAILED(Preferences::AddAtomicIntVarCache(
            &gFixedLimitKB, PREF_FIXED_LIMIT, kDefaultFixedLimitKB)) ||
        NS_FAILED(Preferences::AddAtomicUintVarCache(
            &gChunkSizeKB, PREF_CHUNK_SIZE, kDefaultChunkSizeKB))) {
@@ -2325,32 +2324,16 @@ nsresult QuotaManager::CreateRunnable::I
   nsresult rv = mManager->Init(gBaseDirPath);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
-nsresult QuotaManager::CreateRunnable::RegisterObserver() {
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(mState == State::RegisteringObserver);
-
-  nsresult rv;
-
-  // This service has to be started on the main thread currently.
-  nsCOMPtr<mozIStorageService> ss =
-      do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID, &rv);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
 void QuotaManager::CreateRunnable::CallCallbacks() {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mState == State::CallingCallbacks);
 
   gCreateRunnable = nullptr;
 
   if (NS_FAILED(mResultCode)) {
     gCreateFailed = true;
@@ -2367,23 +2350,16 @@ void QuotaManager::CreateRunnable::CallC
     Unused << callback->Run();
   }
 }
 
 auto QuotaManager::CreateRunnable::GetNextState(
     nsCOMPtr<nsIEventTarget>& aThread) -> State {
   switch (mState) {
     case State::Initial:
-      if (mMainEventTarget) {
-        aThread = mMainEventTarget;
-      } else {
-        aThread = GetMainThreadEventTarget();
-      }
-      return State::RegisteringObserver;
-    case State::RegisteringObserver:
       aThread = mOwningThread;
       return State::CallingCallbacks;
     case State::CallingCallbacks:
       aThread = nullptr;
       return State::Completed;
     default:
       MOZ_CRASH("Bad state!");
   }
@@ -2393,20 +2369,16 @@ NS_IMETHODIMP
 QuotaManager::CreateRunnable::Run() {
   nsresult rv;
 
   switch (mState) {
     case State::Initial:
       rv = Init();
       break;
 
-    case State::RegisteringObserver:
-      rv = RegisterObserver();
-      break;
-
     case State::CallingCallbacks:
       CallCallbacks();
       rv = NS_OK;
       break;
 
     case State::Completed:
     default:
       MOZ_CRASH("Bad state!");
@@ -2932,17 +2904,17 @@ void QuotaManager::GetOrCreate(nsIRunnab
 
   if (gInstance || gCreateFailed) {
     MOZ_ASSERT(!gCreateRunnable);
     MOZ_ASSERT_IF(gCreateFailed, !gInstance);
 
     MOZ_ALWAYS_SUCCEEDS(NS_DispatchToCurrentThread(aCallback));
   } else {
     if (!gCreateRunnable) {
-      gCreateRunnable = new CreateRunnable(aMainEventTarget);
+      gCreateRunnable = new CreateRunnable();
       NS_DispatchToCurrentThread(gCreateRunnable);
     }
 
     gCreateRunnable->AddCallback(aCallback);
   }
 }
 
 // static