Bug 1252998 - StorageActivityService - part 7 - StorageActivityService in QuotaManager, r=janv
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 18 Apr 2018 18:19:13 +0200
changeset 467878 830a2e991b0c1a3a9f9684b469172e28ec689383
parent 467877 185d6fcf4eee894e3a062b21bfddd899f5ef0ba7
child 467879 428f49f692ce707cd7e492217f23cfc3a23915b2
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1252998
milestone61.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 1252998 - StorageActivityService - part 7 - StorageActivityService in QuotaManager, r=janv
dom/quota/ActorsParent.cpp
dom/quota/QuotaObject.h
dom/storage/StorageActivityService.cpp
dom/storage/StorageActivityService.h
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -31,16 +31,17 @@
 #include "mozilla/CondVar.h"
 #include "mozilla/dom/PContent.h"
 #include "mozilla/dom/asmjscache/AsmJSCache.h"
 #include "mozilla/dom/cache/QuotaClient.h"
 #include "mozilla/dom/indexedDB/ActorsParent.h"
 #include "mozilla/dom/quota/PQuotaParent.h"
 #include "mozilla/dom/quota/PQuotaRequestParent.h"
 #include "mozilla/dom/quota/PQuotaUsageRequestParent.h"
+#include "mozilla/dom/StorageActivityService.h"
 #include "mozilla/ipc/BackgroundParent.h"
 #include "mozilla/ipc/BackgroundUtils.h"
 #include "mozilla/IntegerRange.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/TextUtils.h"
@@ -3020,16 +3021,21 @@ QuotaObject::EnableQuotaCheck()
 bool
 QuotaObject::LockedMaybeUpdateSize(int64_t aSize, bool aTruncate)
 {
   QuotaManager* quotaManager = QuotaManager::Get();
   MOZ_ASSERT(quotaManager);
 
   quotaManager->mQuotaMutex.AssertCurrentThreadOwns();
 
+  if (mWritingDone == false && mOriginInfo) {
+    mWritingDone = true;
+    StorageActivityService::SendActivity(mOriginInfo->mOrigin);
+  }
+
   if (mQuotaCheckDisabled) {
     return true;
   }
 
   if (mSize == aSize) {
     return true;
   }
 
--- a/dom/quota/QuotaObject.h
+++ b/dom/quota/QuotaObject.h
@@ -51,16 +51,17 @@ public:
   EnableQuotaCheck();
 
 private:
   QuotaObject(OriginInfo* aOriginInfo, const nsAString& aPath, int64_t aSize)
     : mOriginInfo(aOriginInfo)
     , mPath(aPath)
     , mSize(aSize)
     , mQuotaCheckDisabled(false)
+    , mWritingDone(false)
   {
     MOZ_COUNT_CTOR(QuotaObject);
   }
 
   ~QuotaObject()
   {
     MOZ_COUNT_DTOR(QuotaObject);
   }
@@ -81,13 +82,14 @@ private:
 
   mozilla::ThreadSafeAutoRefCnt mRefCnt;
 
   OriginInfo* mOriginInfo;
   nsString mPath;
   int64_t mSize;
 
   bool mQuotaCheckDisabled;
+  bool mWritingDone;
 };
 
 END_QUOTA_NAMESPACE
 
 #endif // mozilla_dom_quota_quotaobject_h__
--- a/dom/storage/StorageActivityService.cpp
+++ b/dom/storage/StorageActivityService.cpp
@@ -59,16 +59,44 @@ StorageActivityService::SendActivity(con
         mozilla::ipc::PrincipalInfoToPrincipal(aPrincipalInfo);
 
       StorageActivityService::SendActivity(principal);
     });
 
   SystemGroup::Dispatch(TaskCategory::Other, r.forget());
 }
 
+/* static */ void
+StorageActivityService::SendActivity(const nsACString& aOrigin)
+{
+  MOZ_ASSERT(XRE_IsParentProcess());
+
+  nsCString origin;
+  origin.Assign(aOrigin);
+
+  RefPtr<Runnable> r = NS_NewRunnableFunction(
+    "StorageActivityService::SendActivity",
+    [origin] () {
+      MOZ_ASSERT(NS_IsMainThread());
+
+      RefPtr<StorageActivityService> service = GetOrCreate();
+      if (NS_WARN_IF(!service)) {
+        return;
+      }
+
+      service->SendActivityInternal(origin);
+    });
+
+  if (NS_IsMainThread()) {
+    Unused << r->Run();
+  } else {
+    SystemGroup::Dispatch(TaskCategory::Other, r.forget());
+  }
+}
+
 /* static */ already_AddRefed<StorageActivityService>
 StorageActivityService::GetOrCreate()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!gStorageActivityService && !gStorageActivityShutdown) {
     RefPtr<StorageActivityService> service = new StorageActivityService();
 
@@ -113,18 +141,25 @@ StorageActivityService::SendActivityInte
   }
 
   nsAutoCString origin;
   nsresult rv = aPrincipal->GetOrigin(origin);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
-  mActivities.Put(origin, PR_Now());
+  SendActivityInternal(origin);
+}
 
+void
+StorageActivityService::SendActivityInternal(const nsACString& aOrigin)
+{
+  MOZ_ASSERT(XRE_IsParentProcess());
+
+  mActivities.Put(aOrigin, PR_Now());
   MaybeStartTimer();
 }
 
 void
 StorageActivityService::SendActivityToParent(nsIPrincipal* aPrincipal)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!XRE_IsParentProcess());
--- a/dom/storage/StorageActivityService.h
+++ b/dom/storage/StorageActivityService.h
@@ -34,28 +34,35 @@ public:
   // Main-thread only.
   static void
   SendActivity(nsIPrincipal* aPrincipal);
 
   // Thread-safe.
   static void
   SendActivity(const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
 
+  // Thread-safe but for parent process only!
+  static void
+  SendActivity(const nsACString& aOrigin);
+
   // Used by XPCOM. Don't use it, use SendActivity() instead.
   static already_AddRefed<StorageActivityService>
   GetOrCreate();
 
 private:
   StorageActivityService();
   ~StorageActivityService();
 
   void
   SendActivityInternal(nsIPrincipal* aPrincipal);
 
   void
+  SendActivityInternal(const nsACString& aOrigin);
+
+  void
   SendActivityToParent(nsIPrincipal* aPrincipal);
 
   void
   MaybeStartTimer();
 
   void
   MaybeStopTimer();