Bug 1546723 - Part 5: Generalize code for getting datastores; r=asuth a=jcristau
authorJan Varga <jan.varga@gmail.com>
Wed, 15 May 2019 06:11:11 +0200
changeset 536841 e23ee28c87d7fc3bd4e37b43a5f4a0b845ddaa38
parent 536840 ac0e29e198c468325fb2d9bbe4ec9c684f6595c7
child 536842 0a94dff558b1e7fc4ca7779e25c5d1f777574b4d
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth, jcristau
bugs1546723
milestone68.0
Bug 1546723 - Part 5: Generalize code for getting datastores; r=asuth a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D31200
dom/localstorage/ActorsParent.cpp
--- a/dom/localstorage/ActorsParent.cpp
+++ b/dom/localstorage/ActorsParent.cpp
@@ -2871,16 +2871,32 @@ bool IsOnConnectionThread() {
   return gConnectionThread->IsOnConnectionThread();
 }
 
 void AssertIsOnConnectionThread() {
   MOZ_ASSERT(gConnectionThread);
   gConnectionThread->AssertIsOnConnectionThread();
 }
 
+already_AddRefed<Datastore> GetDatastore(const nsACString& aOrigin) {
+  AssertIsOnBackgroundThread();
+
+  if (gDatastores) {
+    CheckedUnsafePtr<Datastore> datastore;
+    if (gDatastores->Get(aOrigin, &datastore)) {
+      MOZ_ASSERT(datastore);
+
+      RefPtr<Datastore> result(datastore);
+      return result.forget();
+    }
+  }
+
+  return nullptr;
+}
+
 void InitUsageForOrigin(const nsACString& aOrigin, int64_t aUsage) {
   AssertIsOnIOThread();
 
   if (!gUsages) {
     gUsages = new UsageHashtable();
   }
 
   MOZ_ASSERT(!gUsages->Contains(aOrigin));
@@ -6740,18 +6756,17 @@ nsresult PrepareDatastoreOp::CheckClosin
   MOZ_ASSERT(mState == State::Nesting);
   MOZ_ASSERT(mNestedState == NestedState::CheckClosingDatastore);
   MOZ_ASSERT(!QuotaClient::IsShuttingDownOnBackgroundThread());
   MOZ_ASSERT(MayProceed());
 
   mNestedState = NestedState::PreparationPending;
 
   RefPtr<Datastore> datastore;
-  if (gDatastores && (datastore = gDatastores->Get(mOrigin)) &&
-      datastore->IsClosed()) {
+  if ((datastore = GetDatastore(mOrigin)) && datastore->IsClosed()) {
     datastore->WaitForConnectionToComplete(this);
 
     return NS_OK;
   }
 
   nsresult rv = BeginDatastorePreparationInternal();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
@@ -6780,17 +6795,17 @@ nsresult PrepareDatastoreOp::BeginDatast
 
 nsresult PrepareDatastoreOp::BeginDatastorePreparationInternal() {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mState == State::Nesting);
   MOZ_ASSERT(mNestedState == NestedState::PreparationPending);
   MOZ_ASSERT(!QuotaClient::IsShuttingDownOnBackgroundThread());
   MOZ_ASSERT(MayProceed());
 
-  if (gDatastores && (mDatastore = gDatastores->Get(mOrigin))) {
+  if ((mDatastore = GetDatastore(mOrigin))) {
     MOZ_ASSERT(!mDatastore->IsClosed());
 
     mDatastore->NoteLivePrepareDatastoreOp(this);
 
     FinishNesting();
 
     return NS_OK;
   }
@@ -8093,18 +8108,17 @@ nsresult PreloadedOp::Open() {
 
 void PreloadedOp::GetResponse(LSSimpleRequestResponse& aResponse) {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mState == State::SendingResults);
   MOZ_ASSERT(NS_SUCCEEDED(ResultCode()));
 
   bool preloaded;
   RefPtr<Datastore> datastore;
-  if (gDatastores && (datastore = gDatastores->Get(mOrigin)) &&
-      !datastore->IsClosed()) {
+  if ((datastore = GetDatastore(mOrigin)) && !datastore->IsClosed()) {
     preloaded = true;
   } else {
     preloaded = false;
   }
 
   LSSimpleRequestPreloadedResponse preloadedResponse;
   preloadedResponse.preloaded() = preloaded;