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 11db6e5fbdd152c081c52751c334e26d0c6604e5..a1ea5260f43ee69cf7c8f6fcd0bb86adcc42016c 100644 |
--- a/webkit/dom_storage/session_storage_database.cc |
+++ b/webkit/dom_storage/session_storage_database.cc |
@@ -108,7 +108,7 @@ bool SessionStorageDatabase::CommitAreaChanges(int64 namespace_id, |
return DatabaseErrorCheck(s.ok()); |
} |
-bool SessionStorageDatabase::CloneNamespace(int64 namespace_id, |
+void SessionStorageDatabase::CloneNamespace(int64 namespace_id, |
int64 new_namespace_id) { |
// Go through all origins in the namespace |namespace_id|, create placeholders |
// for them in |new_namespace_id|, and associate them with the existing maps. |
@@ -128,40 +128,40 @@ bool SessionStorageDatabase::CloneNamespace(int64 namespace_id, |
// | namespace-2-origin1 | 1 (mapid) << references the same map |
if (!LazyOpen(true)) |
- return false; |
+ return; |
leveldb::WriteBatch batch; |
const bool kOkIfExists = false; |
if (!CreateNamespace(new_namespace_id, kOkIfExists, &batch)) |
- return false; |
+ return; |
std::map<std::string, std::string> areas; |
if (!GetAreasInNamespace(namespace_id, &areas)) |
- return false; |
+ return; |
for (std::map<std::string, std::string>::const_iterator it = areas.begin(); |
it != areas.end(); ++it) { |
const std::string& origin = it->first; |
const std::string& map_id = it->second; |
if (!IncreaseMapRefCount(map_id, &batch)) |
- return false; |
+ return; |
AddAreaToNamespace(new_namespace_id, origin, map_id, &batch); |
} |
leveldb::Status s = db_->Write(leveldb::WriteOptions(), &batch); |
- return DatabaseErrorCheck(s.ok()); |
+ DatabaseErrorCheck(s.ok()); |
} |
-bool SessionStorageDatabase::DeleteArea(int64 namespace_id, |
+void SessionStorageDatabase::DeleteArea(int64 namespace_id, |
const GURL& origin) { |
if (!LazyOpen(false)) { |
// No need to create the database if it doesn't exist. |
- return true; |
+ return; |
} |
leveldb::WriteBatch batch; |
- if (!DeleteArea(namespace_id, origin.spec(), &batch)) |
- return false; |
+ if (!DeleteAreaHelper(namespace_id, origin.spec(), &batch)) |
+ return; |
leveldb::Status s = db_->Write(leveldb::WriteOptions(), &batch); |
- return DatabaseErrorCheck(s.ok()); |
+ DatabaseErrorCheck(s.ok()); |
} |
bool SessionStorageDatabase::DeleteNamespace(int64 namespace_id) { |
@@ -177,7 +177,7 @@ bool SessionStorageDatabase::DeleteNamespace(int64 namespace_id) { |
for (std::map<std::string, std::string>::const_iterator it = areas.begin(); |
it != areas.end(); ++it) { |
const std::string& origin = it->first; |
- if (!DeleteArea(namespace_id, origin, &batch)) |
+ if (!DeleteAreaHelper(namespace_id, origin, &batch)) |
return false; |
} |
batch.Delete(NamespaceStartKey(namespace_id, namespace_offset_)); |
@@ -185,6 +185,43 @@ bool SessionStorageDatabase::DeleteNamespace(int64 namespace_id) { |
return DatabaseErrorCheck(s.ok()); |
} |
+bool SessionStorageDatabase::ReadNamespaceIds( |
+ std::vector<int64>* namespace_ids) { |
+ if (!LazyOpen(true)) |
+ return false; |
+ |
+ std::string namespace_prefix = NamespacePrefix(); |
+ scoped_ptr<leveldb::Iterator> it(db_->NewIterator(leveldb::ReadOptions())); |
+ it->Seek(namespace_prefix); |
+ if (it->status().IsNotFound()) |
+ return true; |
+ |
+ if (!DatabaseErrorCheck(it->status().ok())) |
+ return false; |
+ |
+ // Skip the dummy entry "namespace-" and iterate the namespaces. |
+ for (it->Next(); it->Valid(); it->Next()) { |
+ std::string key = it->key().ToString(); |
+ if (key.find(namespace_prefix) != 0) { |
+ // Iterated past the "namespace-" keys. |
+ break; |
+ } |
+ size_t second_dash = key.find('-', namespace_prefix.length()); |
+ if (second_dash != std::string::npos) |
+ continue; |
+ |
+ // The key is of the form "namespace-<namespaceid>". |
+ std::string namespace_id_str = key.substr(namespace_prefix.length()); |
+ int64 namespace_id; |
+ bool conversion_ok = |
+ base::StringToInt64(namespace_id_str, &namespace_id); |
+ if (!ConsistencyCheck(conversion_ok)) |
+ return false; |
+ namespace_ids->push_back(namespace_id - namespace_offset_); |
+ } |
+ return true; |
+} |
+ |
bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { |
base::AutoLock auto_lock(db_lock_); |
if (db_error_ || is_inconsistent_) { |
@@ -370,16 +407,17 @@ void SessionStorageDatabase::AddAreaToNamespace(int64 namespace_id, |
batch->Put(namespace_key, map_id); |
} |
-bool SessionStorageDatabase::DeleteArea(int64 namespace_id, |
- const std::string& origin, |
- leveldb::WriteBatch* batch) { |
- return DeleteArea(NamespaceIdStr(namespace_id, namespace_offset_), |
- origin, batch); |
+bool SessionStorageDatabase::DeleteAreaHelper(int64 namespace_id, |
+ const std::string& origin, |
+ leveldb::WriteBatch* batch) { |
+ return DeleteAreaHelper(NamespaceIdStr(namespace_id, namespace_offset_), |
+ origin, batch); |
} |
-bool SessionStorageDatabase::DeleteArea(const std::string& namespace_id_str, |
- const std::string& origin, |
- leveldb::WriteBatch* batch) { |
+bool SessionStorageDatabase::DeleteAreaHelper( |
+ const std::string& namespace_id_str, |
+ const std::string& origin, |
+ leveldb::WriteBatch* batch) { |
std::string map_id; |
bool exists; |
if (!GetMapForArea(namespace_id_str, origin, &exists, &map_id)) |