Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Unified Diff: webkit/dom_storage/session_storage_database.cc

Issue 12224092: SessionStorageDatabase fix: Delete namespace keys if there are no areas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review (michaeln) Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webkit/dom_storage/session_storage_database_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/dom_storage/session_storage_database.cc
diff --git a/webkit/dom_storage/session_storage_database.cc b/webkit/dom_storage/session_storage_database.cc
index 794473836ba4d2425b6956b84282a0331d9989d8..b22ea30296bd01e45593eb5e10f440c027ead4f8 100644
--- a/webkit/dom_storage/session_storage_database.cc
+++ b/webkit/dom_storage/session_storage_database.cc
@@ -240,6 +240,10 @@ bool SessionStorageDatabase::ReadNamespacesAndOrigins(
current_namespace_id =
key.substr(namespace_prefix.length(),
key.length() - namespace_prefix.length() - 1);
+ // Ensure that we keep track of the namespace even if it doesn't contain
+ // any origins.
+ namespaces_and_origins->insert(
+ std::make_pair(current_namespace_id, std::vector<GURL>()));
} else {
// The key is of the form "namespace-<namespaceid>-<origin>".
std::string origin = key.substr(current_namespace_start_key.length());
@@ -411,6 +415,25 @@ bool SessionStorageDatabase::DeleteAreaHelper(
return false;
std::string namespace_key = NamespaceKey(namespace_id, origin);
batch->Delete(namespace_key);
+
+ // If this was the only area in the namespace, delete the namespace start key,
+ // too.
+ std::string namespace_start_key = NamespaceStartKey(namespace_id);
+ scoped_ptr<leveldb::Iterator> it(db_->NewIterator(leveldb::ReadOptions()));
+ it->Seek(namespace_start_key);
+ if (!ConsistencyCheck(it->Valid()))
+ return false;
+ // Advance the iterator 2 times (we still haven't really deleted
+ // namespace_key).
+ it->Next();
+ if (!ConsistencyCheck(it->Valid()))
+ return false;
+ it->Next();
+ if (!it->Valid())
+ return true;
+ std::string key = it->key().ToString();
+ if (key.find(namespace_start_key) != 0)
+ batch->Delete(namespace_start_key);
return true;
}
« no previous file with comments | « no previous file | webkit/dom_storage/session_storage_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698