Bug 786301 - 1/3 - Add RemoveAllForApp on nsDOMStorageDBWrapper and nsDOMStoragePersistentDB. r=honza
authorMounir Lamouri <mounir.lamouri@gmail.com>
Thu, 27 Sep 2012 16:28:01 +0100
changeset 114542 2310fb3518ee869d6be3940b7419a69dc965f4d1
parent 114541 aacf4867f83067e33f31f81ecaa14a7152a82d1c
child 114543 205fdb51a6e3266494f4389b32f8ddb19e44ba7c
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonza
bugs786301
milestone18.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 786301 - 1/3 - Add RemoveAllForApp on nsDOMStorageDBWrapper and nsDOMStoragePersistentDB. r=honza
dom/src/storage/nsDOMStorageDBWrapper.cpp
dom/src/storage/nsDOMStorageDBWrapper.h
dom/src/storage/nsDOMStoragePersistentDB.cpp
dom/src/storage/nsDOMStoragePersistentDB.h
--- a/dom/src/storage/nsDOMStorageDBWrapper.cpp
+++ b/dom/src/storage/nsDOMStorageDBWrapper.cpp
@@ -198,16 +198,25 @@ nsDOMStorageDBWrapper::RemoveAll()
 
   rv = mPersistentDB.RemoveAll();
   NS_ENSURE_SUCCESS(rv, rv);
 
   return rv;
 }
 
 nsresult
+nsDOMStorageDBWrapper::RemoveAllForApp(uint32_t aAppId, bool aOnlyBrowserElement)
+{
+  // We only care about removing the permament storage. Temporary storage such
+  // as session storage or private browsing storage will not be re-used anyway
+  // and will be automatically deleted at some point.
+  return mPersistentDB.RemoveAllForApp(aAppId, aOnlyBrowserElement);
+}
+
+nsresult
 nsDOMStorageDBWrapper::GetUsage(DOMStorageImpl* aStorage, int32_t *aUsage)
 {
   IMPL_FORWARDER(GetUsage(aStorage, aUsage));
 }
 
 nsresult
 nsDOMStorageDBWrapper::GetUsage(const nsACString& aDomain,
                                 int32_t *aUsage, bool aPrivate)
--- a/dom/src/storage/nsDOMStorageDBWrapper.h
+++ b/dom/src/storage/nsDOMStorageDBWrapper.h
@@ -133,16 +133,25 @@ public:
 
   /**
    * Removes all keys from storage. Used when clearing storage.
    */
   nsresult
   RemoveAll();
 
   /**
+   * Removes all keys from storage for a specific app.
+   * If aOnlyBrowserElement is true, it will remove only keys with the
+   * browserElement flag set.
+   * aAppId has to be a valid app id. It can't be NO_APP_ID or UNKNOWN_APP_ID.
+   */
+  nsresult
+  RemoveAllForApp(uint32_t aAppId, bool aOnlyBrowserElement);
+
+  /**
     * Returns usage for a storage using its GetQuotaDBKey() as a key.
     */
   nsresult
   GetUsage(DOMStorageImpl* aStorage, int32_t *aUsage);
 
   /**
     * Returns usage of the domain and optionaly by any subdomain.
     */
--- a/dom/src/storage/nsDOMStoragePersistentDB.cpp
+++ b/dom/src/storage/nsDOMStoragePersistentDB.cpp
@@ -660,16 +660,49 @@ nsDOMStoragePersistentDB::RemoveAll()
   NS_ENSURE_SUCCESS(rv, rv);
 
   MarkAllScopesDirty();
 
   return NS_OK;
 }
 
 nsresult
+nsDOMStoragePersistentDB::RemoveAllForApp(uint32_t aAppId, bool aOnlyBrowserElement)
+{
+  nsresult rv;
+
+  rv = MaybeCommitInsertTransaction();
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<mozIStorageStatement> stmt = mStatements.GetCachedStatement(
+    "DELETE FROM webappsstore2_view "
+    "WHERE scope LIKE :scope"
+  );
+  NS_ENSURE_STATE(stmt);
+  mozStorageStatementScoper scopeStmt(stmt);
+
+  nsAutoCString scope;
+  scope.AppendInt(aAppId);
+  if (aOnlyBrowserElement) {
+    scope.Append(NS_LITERAL_CSTRING(":t:%"));
+  } else {
+    scope.Append(NS_LITERAL_CSTRING(":_:%"));
+  }
+  rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("scope"), scope);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  rv = stmt->Execute();
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  MarkAllScopesDirty();
+
+  return NS_OK;
+}
+
+nsresult
 nsDOMStoragePersistentDB::GetUsage(DOMStorageImpl* aStorage,
                                    int32_t *aUsage)
 {
   return GetUsageInternal(aStorage->GetQuotaDBKey(), aUsage);
 }
 
 nsresult
 nsDOMStoragePersistentDB::GetUsage(const nsACString& aDomain,
--- a/dom/src/storage/nsDOMStoragePersistentDB.h
+++ b/dom/src/storage/nsDOMStoragePersistentDB.h
@@ -94,16 +94,25 @@ public:
 
   /**
    * Removes all keys from storage. Used when clearing storage.
    */
   nsresult
   RemoveAll();
 
   /**
+   * Removes all keys from storage for a specific app.
+   * If aOnlyBrowserElement is true, it will remove only keys with the
+   * browserElement flag set.
+   * aAppId has to be a valid app id. It can't be NO_APP_ID or UNKNOWN_APP_ID.
+   */
+  nsresult
+  RemoveAllForApp(uint32_t aAppId, bool aOnlyBrowserElement);
+
+  /**
     * Returns usage for a storage using its GetQuotaDBKey() as a key.
     */
   nsresult
   GetUsage(DOMStorageImpl* aStorage, int32_t *aUsage);
 
   /**
     * Returns usage of the domain and optionaly by any subdomain.
     */