Bug 1526891 - Part 15: Remove CreateRunnable; r=asuth
authorJan Varga <jan.varga@gmail.com>
Sat, 23 Feb 2019 17:33:55 +0100
changeset 520828 5e8ac40eca965684e299befb6dc3c7d563787a4a
parent 520827 830813029a78357c3d45378e4af6be4e68508704
child 520829 85e6118f8a009f01717f4e580c27b9b43e094b94
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 15: Remove CreateRunnable; r=asuth Differential Revision: https://phabricator.services.mozilla.com/D20924
dom/quota/ActorsParent.cpp
dom/quota/QuotaManager.h
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -416,53 +416,16 @@ class DirectoryLockImpl final : public D
   }
 
   NS_INLINE_DECL_REFCOUNTING(DirectoryLockImpl, override)
 
  private:
   ~DirectoryLockImpl();
 };
 
-class QuotaManager::CreateRunnable final : public BackgroundThreadObject,
-                                           public Runnable {
-  nsTArray<nsCOMPtr<nsIRunnable>> mCallbacks;
-  RefPtr<QuotaManager> mManager;
-  nsresult mResultCode;
-
-  enum class State { Initial, CallingCallbacks, Completed };
-
-  State mState;
-
- public:
-  CreateRunnable()
-      : Runnable("dom::quota::QuotaManager::CreateRunnable"),
-        mResultCode(NS_OK),
-        mState(State::Initial) {
-    AssertIsOnBackgroundThread();
-  }
-
-  void AddCallback(nsIRunnable* aCallback) {
-    AssertIsOnOwningThread();
-    MOZ_ASSERT(aCallback);
-
-    mCallbacks.AppendElement(aCallback);
-  }
-
- private:
-  ~CreateRunnable() {}
-
-  nsresult Init();
-
-  void CallCallbacks();
-
-  State GetNextState(nsCOMPtr<nsIEventTarget>& aThread);
-
-  NS_DECL_NSIRUNNABLE
-};
-
 class QuotaManager::Observer final : public nsIObserver {
   static Observer* sInstance;
 
   bool mPendingProfileChange;
   bool mShutdownComplete;
 
  public:
   static nsresult Initialize();
@@ -1348,17 +1311,16 @@ namespace {
 nsString gBaseDirPath;
 
 #ifdef DEBUG
 bool gQuotaManagerInitialized = false;
 #endif
 
 StaticRefPtr<QuotaManager> gInstance;
 bool gCreateFailed = false;
-StaticRefPtr<QuotaManager::CreateRunnable> gCreateRunnable;
 mozilla::Atomic<bool> gShutdown(false);
 
 // Constants for temporary storage limit computing.
 static const int32_t kDefaultFixedLimitKB = -1;
 static const uint32_t kDefaultChunkSizeKB = 10 * 1024;
 Atomic<int32_t, Relaxed> gFixedLimitKB(kDefaultFixedLimitKB);
 Atomic<uint32_t, Relaxed> gChunkSizeKB(kDefaultChunkSizeKB);
 
@@ -2309,105 +2271,16 @@ void DirectoryLockImpl::NotifyOpenListen
     mOpenListener->DirectoryLockAcquired(this);
   }
 
   mOpenListener = nullptr;
 
   mQuotaManager->RemovePendingDirectoryLock(this);
 }
 
-nsresult QuotaManager::CreateRunnable::Init() {
-  AssertIsOnOwningThread();
-  MOZ_ASSERT(mState == State::Initial);
-  MOZ_ASSERT(!gBaseDirPath.IsEmpty());
-
-  mManager = new QuotaManager();
-
-  nsresult rv = mManager->Init(gBaseDirPath);
-  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;
-  } else {
-    gInstance = mManager;
-  }
-
-  mManager = nullptr;
-
-  nsTArray<nsCOMPtr<nsIRunnable>> callbacks;
-  mCallbacks.SwapElements(callbacks);
-
-  for (nsCOMPtr<nsIRunnable>& callback : callbacks) {
-    Unused << callback->Run();
-  }
-}
-
-auto QuotaManager::CreateRunnable::GetNextState(
-    nsCOMPtr<nsIEventTarget>& aThread) -> State {
-  switch (mState) {
-    case State::Initial:
-      aThread = mOwningThread;
-      return State::CallingCallbacks;
-    case State::CallingCallbacks:
-      aThread = nullptr;
-      return State::Completed;
-    default:
-      MOZ_CRASH("Bad state!");
-  }
-}
-
-NS_IMETHODIMP
-QuotaManager::CreateRunnable::Run() {
-  nsresult rv;
-
-  switch (mState) {
-    case State::Initial:
-      rv = Init();
-      break;
-
-    case State::CallingCallbacks:
-      CallCallbacks();
-      rv = NS_OK;
-      break;
-
-    case State::Completed:
-    default:
-      MOZ_CRASH("Bad state!");
-  }
-
-  nsCOMPtr<nsIEventTarget> thread;
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    if (NS_SUCCEEDED(mResultCode)) {
-      mResultCode = rv;
-    }
-
-    mState = State::CallingCallbacks;
-    thread = mOwningThread;
-  } else {
-    mState = GetNextState(thread);
-  }
-
-  if (thread) {
-    MOZ_ALWAYS_SUCCEEDS(thread->Dispatch(this, NS_DISPATCH_NORMAL));
-  }
-
-  return NS_OK;
-}
-
 QuotaManager::Observer* QuotaManager::Observer::sInstance = nullptr;
 
 // static
 nsresult QuotaManager::Observer::Initialize() {
   MOZ_ASSERT(NS_IsMainThread());
 
   RefPtr<Observer> observer = new Observer();
 
@@ -2898,28 +2771,29 @@ void QuotaManager::GetOrCreate(nsIRunnab
   AssertIsOnBackgroundThread();
 
   if (IsShuttingDown()) {
     MOZ_ASSERT(false, "Calling GetOrCreate() after shutdown!");
     return;
   }
 
   if (gInstance || gCreateFailed) {
-    MOZ_ASSERT(!gCreateRunnable);
     MOZ_ASSERT_IF(gCreateFailed, !gInstance);
-
-    MOZ_ALWAYS_SUCCEEDS(NS_DispatchToCurrentThread(aCallback));
   } else {
-    if (!gCreateRunnable) {
-      gCreateRunnable = new CreateRunnable();
-      NS_DispatchToCurrentThread(gCreateRunnable);
-    }
-
-    gCreateRunnable->AddCallback(aCallback);
-  }
+    RefPtr<QuotaManager> manager = new QuotaManager();
+
+    nsresult rv = manager->Init(gBaseDirPath);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      gCreateFailed = true;
+    } else {
+      gInstance = manager;
+    }
+  }
+
+  MOZ_ALWAYS_SUCCEEDS(NS_DispatchToCurrentThread(aCallback));
 }
 
 // static
 QuotaManager* QuotaManager::Get() {
   // Does not return an owning reference.
   return gInstance;
 }
 
--- a/dom/quota/QuotaManager.h
+++ b/dom/quota/QuotaManager.h
@@ -90,20 +90,16 @@ class QuotaManager final : public Backgr
   friend class GroupInfo;
   friend class OriginInfo;
   friend class QuotaObject;
 
   typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
   typedef nsClassHashtable<nsCStringHashKey, nsTArray<DirectoryLockImpl*>>
       DirectoryLockTable;
 
- public:
-  class CreateRunnable;
-
- private:
   class Observer;
 
  public:
   NS_INLINE_DECL_REFCOUNTING(QuotaManager)
 
   static nsresult Initialize();
 
   static bool IsRunningXPCShellTests() {