ls log wip draft ls-log-and-fixes
authorAndrew Sutherland <asutherland@asutherland.org>
Sat, 23 Sep 2017 12:01:33 -0400
changeset 420359 f5fc83e01d5a097b6bbbb07ac5c25f0ceb843319
parent 420358 ffe6cc09ccf38cca6f0e727837bbc6cb722d1e71
push id5
push userbugmail@asutherland.org
push dateSat, 23 Sep 2017 16:52:09 +0000
milestone57.0a1
ls log wip
dom/storage/LocalStorage.cpp
dom/storage/LocalStorageManager.cpp
--- a/dom/storage/LocalStorage.cpp
+++ b/dom/storage/LocalStorage.cpp
@@ -18,29 +18,32 @@
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/PermissionMessageUtils.h"
 #include "mozilla/dom/StorageBinding.h"
 #include "mozilla/dom/StorageEvent.h"
 #include "mozilla/dom/StorageEventBinding.h"
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ipc/PBackgroundChild.h"
-#include "mozilla/Services.h"
+#include "mozilla/EnumSet.h"
 #include "mozilla/Preferences.h"
-#include "mozilla/EnumSet.h"
+#include "mozilla/Logging.h"
+#include "mozilla/Services.h"
 #include "nsThreadUtils.h"
 #include "nsContentUtils.h"
 #include "nsServiceManagerUtils.h"
 
 namespace mozilla {
 
 using namespace ipc;
 
 namespace dom {
 
+extern LazyLogModule gLocalStorage;
+
 NS_IMPL_CYCLE_COLLECTION_INHERITED(LocalStorage, Storage, mManager);
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(LocalStorage)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END_INHERITING(Storage)
 
 NS_IMPL_ADDREF_INHERITED(LocalStorage, Storage)
 NS_IMPL_RELEASE_INHERITED(LocalStorage, Storage)
@@ -52,21 +55,26 @@ LocalStorage::LocalStorage(nsPIDOMWindow
                            nsIPrincipal* aPrincipal,
                            bool aIsPrivate)
   : Storage(aWindow, aPrincipal)
   , mManager(aManager)
   , mCache(aCache)
   , mDocumentURI(aDocumentURI)
   , mIsPrivate(aIsPrivate)
 {
+  MOZ_LOG(gLocalStorage, LogLevel::Debug,
+          ("LocalStorage::LocalStorage this=%p cache=%p innerWindow=%p",
+           this, aCache, aWindow));
   mCache->Preload();
 }
 
 LocalStorage::~LocalStorage()
 {
+  MOZ_LOG(gLocalStorage, LogLevel::Debug,
+          ("LocalStorage::~LocalStorage this=%p cache=%p", this, mCache));
 }
 
 int64_t
 LocalStorage::GetOriginQuotaUsage() const
 {
   return mCache->GetOriginQuotaUsage(this);
 }
 
@@ -76,42 +84,48 @@ LocalStorage::GetLength(nsIPrincipal& aS
 {
   if (!CanUseStorage(aSubjectPrincipal)) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return 0;
   }
 
   uint32_t length;
   aRv = mCache->GetLength(this, &length);
+  MOZ_LOG(gLocalStorage, LogLevel::Verbose,
+          ("LocalStorage::GetLength this=%p length=%d", this, length));
   return length;
 }
 
 void
 LocalStorage::Key(uint32_t aIndex, nsAString& aResult,
                   nsIPrincipal& aSubjectPrincipal,
                   ErrorResult& aRv)
 {
   if (!CanUseStorage(aSubjectPrincipal)) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return;
   }
 
+  MOZ_LOG(gLocalStorage, LogLevel::Verbose,
+          ("LocalStorage::GetKey this=%p", this));
   aRv = mCache->GetKey(this, aIndex, aResult);
 }
 
 void
 LocalStorage::GetItem(const nsAString& aKey, nsAString& aResult,
                       nsIPrincipal& aSubjectPrincipal,
                       ErrorResult& aRv)
 {
   if (!CanUseStorage(aSubjectPrincipal)) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return;
   }
 
+  MOZ_LOG(gLocalStorage, LogLevel::Verbose,
+          ("LocalStorage::GetItem this=%p", this));
   aRv = mCache->GetItem(this, aKey, aResult);
 }
 
 void
 LocalStorage::SetItem(const nsAString& aKey, const nsAString& aData,
                       nsIPrincipal& aSubjectPrincipal,
                       ErrorResult& aRv)
 {
@@ -122,16 +136,18 @@ LocalStorage::SetItem(const nsAString& a
 
   nsString data;
   bool ok = data.Assign(aData, fallible);
   if (!ok) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     return;
   }
 
+  MOZ_LOG(gLocalStorage, LogLevel::Verbose,
+          ("LocalStorage::SetItem this=%p", this));
   nsString old;
   aRv = mCache->SetItem(this, aKey, data, old);
   if (aRv.Failed()) {
     return;
   }
 
   if (!aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION)) {
     BroadcastChangeNotification(aKey, old, aData);
@@ -143,16 +159,18 @@ LocalStorage::RemoveItem(const nsAString
                          ErrorResult& aRv)
 {
   if (!CanUseStorage(aSubjectPrincipal)) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return;
   }
 
   nsAutoString old;
+  MOZ_LOG(gLocalStorage, LogLevel::Verbose,
+          ("LocalStorage::RemoveItem this=%p", this));
   aRv = mCache->RemoveItem(this, aKey, old);
   if (aRv.Failed()) {
     return;
   }
 
   if (!aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION)) {
     BroadcastChangeNotification(aKey, old, NullString());
   }
@@ -161,16 +179,18 @@ LocalStorage::RemoveItem(const nsAString
 void
 LocalStorage::Clear(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv)
 {
   if (!CanUseStorage(aSubjectPrincipal)) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return;
   }
 
+  MOZ_LOG(gLocalStorage, LogLevel::Verbose,
+          ("LocalStorage::Clear this=%p", this));
   aRv = mCache->Clear(this);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
   if (!aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION)) {
     BroadcastChangeNotification(NullString(), NullString(), NullString());
   }
@@ -225,27 +245,33 @@ LocalStorage::ApplyEvent(StorageEvent* a
   nsAutoString value;
 
   aStorageEvent->GetKey(key);
   aStorageEvent->GetNewValue(value);
 
   // No key means clearing the full storage.
   if (key.IsVoid()) {
     MOZ_ASSERT(value.IsVoid());
+    MOZ_LOG(gLocalStorage, LogLevel::Verbose,
+            ("LocalStorage::ApplyEvent Clear this=%p", this));
     mCache->Clear(this, LocalStorageCache::E10sPropagated);
     return;
   }
 
   // No new value means removing the key.
   if (value.IsVoid()) {
+    MOZ_LOG(gLocalStorage, LogLevel::Verbose,
+            ("LocalStorage::ApplyEvent RemoveItem this=%p", this));
     mCache->RemoveItem(this, key, old, LocalStorageCache::E10sPropagated);
     return;
   }
 
   // Otherwise, we set the new value.
+  MOZ_LOG(gLocalStorage, LogLevel::Verbose,
+          ("LocalStorage::ApplyEvent SetItem this=%p", this));
   mCache->SetItem(this, key, value, old, LocalStorageCache::E10sPropagated);
 }
 
 static const char kPermissionType[] = "cookie";
 static const char kStorageEnabled[] = "dom.storage.enabled";
 
 bool
 LocalStorage::PrincipalEquals(nsIPrincipal* aPrincipal)
--- a/dom/storage/LocalStorageManager.cpp
+++ b/dom/storage/LocalStorageManager.cpp
@@ -14,27 +14,30 @@
 
 #include "nsNetUtil.h"
 #include "nsNetCID.h"
 #include "nsIURL.h"
 #include "nsPrintfCString.h"
 #include "nsXULAppAPI.h"
 #include "nsThreadUtils.h"
 #include "nsIObserverService.h"
+#include "mozilla/Logging.h"
+#include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
-#include "mozilla/Preferences.h"
 
 // Only allow relatively small amounts of data since performance of
 // the synchronous IO is very bad.
 // We are enforcing simple per-origin quota only.
 #define DEFAULT_QUOTA_LIMIT (5 * 1024)
 
 namespace mozilla {
 namespace dom {
 
+LazyLogModule gLocalStorage("LocalStorage");
+
 using namespace StorageUtils;
 
 namespace {
 
 int32_t gQuotaLimit = DEFAULT_QUOTA_LIMIT;
 
 } // namespace