Bug 1517089 - Part 5: Move storage service initialization to InitializeLocalStorage; r=asuth
authorJan Varga <jan.varga@gmail.com>
Thu, 07 Feb 2019 19:51:22 +0100
changeset 457572 6e9e487f5d16c287831f7a525833639a380e99e1
parent 457571 2c48efbd5486c0019a2468ccf004d66bdaef8942
child 457573 08d6d7646f18e161e5b0aa4553f93db89efba407
push id35515
push userrmaries@mozilla.com
push dateThu, 07 Feb 2019 21:44:23 +0000
treeherdermozilla-central@4e98200ee530 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1517089
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 1517089 - Part 5: Move storage service initialization to InitializeLocalStorage; r=asuth
dom/localstorage/ActorsParent.cpp
dom/quota/QuotaManager.h
--- a/dom/localstorage/ActorsParent.cpp
+++ b/dom/localstorage/ActorsParent.cpp
@@ -2939,16 +2939,24 @@ void SnapshotPrefillPrefChangedCallback(
  * Exported functions
  ******************************************************************************/
 
 void InitializeLocalStorage() {
   MOZ_ASSERT(XRE_IsParentProcess());
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!gLocalStorageInitialized);
 
+  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(QuotaClient::Initialize())) {
     NS_WARNING("Failed to initialize quota client!");
   }
 
   if (NS_FAILED(Preferences::AddAtomicUintVarCache(
           &gOriginLimitKB, kDefaultQuotaPref, kDefaultOriginLimitKB))) {
     NS_WARNING("Unable to respond to default quota pref changes!");
   }
@@ -5647,22 +5655,16 @@ nsresult PrepareDatastoreOp::Open() {
     }
 
     mArchivedOriginScope = ArchivedOriginScope::CreateFromOrigin(principal);
     if (NS_WARN_IF(!mArchivedOriginScope)) {
       return NS_ERROR_FAILURE;
     }
   }
 
-  // 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)))) {
-    return NS_ERROR_FAILURE;
-  }
-
   mState = State::Nesting;
   mNestedState = NestedState::CheckExistingOperations;
 
   MOZ_ALWAYS_SUCCEEDS(OwningEventTarget()->Dispatch(this, NS_DISPATCH_NORMAL));
 
   return NS_OK;
 }
 
--- a/dom/quota/QuotaManager.h
+++ b/dom/quota/QuotaManager.h
@@ -99,16 +99,21 @@ class QuotaManager final : public Backgr
   NS_INLINE_DECL_REFCOUNTING(QuotaManager)
 
   static bool IsRunningXPCShellTests() {
     static bool kRunningXPCShellTests =
         !!PR_GetEnv("XPCSHELL_TEST_PROFILE_DIR");
     return kRunningXPCShellTests;
   }
 
+  static bool IsRunningGTests() {
+    static bool kRunningGTests = !!PR_GetEnv("MOZ_RUN_GTEST");
+    return kRunningGTests;
+  }
+
   static const char kReplaceChars[];
 
   static void GetOrCreate(nsIRunnable* aCallback,
                           nsIEventTarget* aMainEventTarget = nullptr);
 
   // Returns a non-owning reference.
   static QuotaManager* Get();