Bug 1372116 - P1: Create originInfo after creating metadata if the temporay storage has been initialized for persist(). r=janv
authorTom Tung <shes050117@gmail.com>
Tue, 27 Jun 2017 04:41:38 -0700
changeset 368726 7bfcb0aeb065c4807ee94c039f17044c6fd19b55
parent 368725 fc27e4fc79a38461033e573f3bf9d799aa558f63
child 368727 76538de6b9b2d952bd32f95bab4400eed999e4f7
push id32167
push usercbook@mozilla.com
push dateThu, 13 Jul 2017 14:35:41 +0000
treeherdermozilla-central@d4e6f45db733 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1372116
milestone56.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 1372116 - P1: Create originInfo after creating metadata if the temporay storage has been initialized for persist(). r=janv
dom/quota/ActorsParent.cpp
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -7644,41 +7644,54 @@ PersistOp::DoDirectoryWork(QuotaManager*
 {
   AssertIsOnIOThread();
   MOZ_ASSERT(!mPersistenceType.IsNull());
   MOZ_ASSERT(mPersistenceType.Value() == PERSISTENCE_TYPE_DEFAULT);
   MOZ_ASSERT(mOriginScope.IsOrigin());
 
   AUTO_PROFILER_LABEL("PersistOp::DoDirectoryWork", OTHER);
 
-  // Update directory metadata on disk first.
+  // Update directory metadata on disk first. Then, create/update the originInfo
+  // if needed.
   nsCOMPtr<nsIFile> directory;
   nsresult rv = aQuotaManager->GetDirectoryForOrigin(mPersistenceType.Value(),
                                                      mOriginScope.GetOrigin(),
                                                      getter_AddRefs(directory));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   bool created;
   rv = EnsureOriginDirectory(directory, &created);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (created) {
+    int64_t timestamp;
     rv = CreateDirectoryMetadataFiles(directory,
                                       /* aPersisted */ true,
                                       mSuffix,
                                       mGroup,
                                       mOriginScope.GetOrigin(),
-                                      /* aTimestamp */ nullptr);
+                                      &timestamp);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
+
+    // Directory metadata has been successfully created.
+    // Create OriginInfo too if temporary storage was already initialized.
+    if (aQuotaManager->IsTemporaryStorageInitialized()) {
+      aQuotaManager->InitQuotaForOrigin(mPersistenceType.Value(),
+                                        mGroup,
+                                        mOriginScope.GetOrigin(),
+                                        /* aUsageBytes */ 0,
+                                        timestamp,
+                                        /* aPersisted */ true);
+    }
   } else {
     // Get the persisted flag (restore the metadata file if necessary).
     bool persisted;
     rv =
       aQuotaManager->GetDirectoryMetadata2WithRestore(directory,
                                                       /* aPersistent */ false,
                                                       /* aTimestamp */ nullptr,
                                                       &persisted);
@@ -7713,21 +7726,23 @@ PersistOp::DoDirectoryWork(QuotaManager*
       }
 
       // Set the persisted flag to true.
       rv = stream->WriteBoolean(true);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
-  }
-
-  // Directory metadata has been successfully created/updated, try to update
-  // OriginInfo too (it's ok if OriginInfo doesn't exist yet).
-  aQuotaManager->PersistOrigin(mGroup, mOriginScope.GetOrigin());
+
+    // Directory metadata has been successfully updated.
+    // Update OriginInfo too if temporary storage was already initialized.
+    if (aQuotaManager->IsTemporaryStorageInitialized()) {
+      aQuotaManager->PersistOrigin(mGroup, mOriginScope.GetOrigin());
+    }
+  }
 
   return NS_OK;
 }
 
 void
 PersistOp::GetResponse(RequestResponse& aResponse)
 {
   AssertIsOnOwningThread();