Bug 1683299 - Restore semi-broken behaviour before bug 1676410 and bug 1676973; r=ttung, a=RyanVM
authorJan Varga <jvarga@mozilla.com>
Thu, 14 Jan 2021 09:32:00 +0000
changeset 627404 716b5f48799e16a56ff592ec9230508965a4b8fe
parent 627403 a61d27eef45e3b284cb3d5419e3cebc3d350fd60
child 627405 854247b3a4ebc2bdb2a8674e2aaaec547ef4702f
push id15031
push userryanvm@gmail.com
push dateFri, 15 Jan 2021 19:25:13 +0000
treeherdermozilla-beta@38febe1e15c4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttung, RyanVM
bugs1683299, 1676410, 1676973
milestone85.0
Bug 1683299 - Restore semi-broken behaviour before bug 1676410 and bug 1676973; r=ttung, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D101726
dom/storage/StorageDBThread.cpp
--- a/dom/storage/StorageDBThread.cpp
+++ b/dom/storage/StorageDBThread.cpp
@@ -988,16 +988,24 @@ nsresult StorageDBThread::DBOperation::P
       // The loop condition's call to ExecuteStep() may have terminated because
       // !NS_SUCCEEDED(), we need an early return to cover that case.  This also
       // covers success cases as well, but that's inductively safe.
       NS_ENSURE_SUCCESS(rv, rv);
       break;
     }
 
     case opGetUsage: {
+      // Bug 1676410 fixed a regression caused by bug 1165214. However, it
+      // turns out that 100% correct checking of the eTLD+1 usage is not
+      // possible to recover easily, see bug 1683299.
+#if 0
+      // This is how it should be done, but due to other problems like lack
+      // of usage synchronization between content processes, we temporarily
+      // disabled the matching using "%".
+
       nsCOMPtr<mozIStorageStatement> stmt =
           aThread->mWorkerStatements.GetCachedStatement(
               "SELECT SUM(LENGTH(key) + LENGTH(value)) FROM webappsstore2 "
               "WHERE (originAttributes || ':' || originKey) LIKE :usageOrigin "
               "ESCAPE '\\'");
       NS_ENSURE_STATE(stmt);
 
       mozStorageStatementScoper scope(stmt);
@@ -1019,16 +1027,34 @@ nsresult StorageDBThread::DBOperation::P
       nsAutoCString originScopeEscaped;
       rv = stmt->EscapeUTF8StringForLIKE(mUsage->OriginScope(), '\\',
                                          originScopeEscaped);
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = stmt->BindUTF8StringByName("usageOrigin"_ns,
                                       originScopeEscaped + "%"_ns);
       NS_ENSURE_SUCCESS(rv, rv);
+#else
+      // This is the code before bug 1676410 and bug 1676973. The returned
+      // usage will be zero in most of the cases, but due to lack of usage
+      // synchronization between content processes we have to live with this
+      // semi-broken behaviour because it causes less harm than the matching
+      // using "%".
+
+      nsCOMPtr<mozIStorageStatement> stmt =
+          aThread->mWorkerStatements.GetCachedStatement(
+              "SELECT SUM(LENGTH(key) + LENGTH(value)) FROM webappsstore2 "
+              "WHERE (originAttributes || ':' || originKey) LIKE :usageOrigin");
+      NS_ENSURE_STATE(stmt);
+
+      mozStorageStatementScoper scope(stmt);
+
+      rv = stmt->BindUTF8StringByName("usageOrigin"_ns, mUsage->OriginScope());
+      NS_ENSURE_SUCCESS(rv, rv);
+#endif
 
       bool exists;
       rv = stmt->ExecuteStep(&exists);
       NS_ENSURE_SUCCESS(rv, rv);
 
       int64_t usage = 0;
       if (exists) {
         rv = stmt->GetInt64(0, &usage);