OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/dom_storage/session_storage_database.h" | 5 #include "webkit/dom_storage/session_storage_database.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 // "<namespaceid>" parts from the keys. | 233 // "<namespaceid>" parts from the keys. |
234 if (current_namespace_start_key.empty() || | 234 if (current_namespace_start_key.empty() || |
235 key.substr(0, current_namespace_start_key.length()) != | 235 key.substr(0, current_namespace_start_key.length()) != |
236 current_namespace_start_key) { | 236 current_namespace_start_key) { |
237 // The key is of the form "namespace-<namespaceid>-" for a new | 237 // The key is of the form "namespace-<namespaceid>-" for a new |
238 // <namespaceid>. | 238 // <namespaceid>. |
239 current_namespace_start_key = key; | 239 current_namespace_start_key = key; |
240 current_namespace_id = | 240 current_namespace_id = |
241 key.substr(namespace_prefix.length(), | 241 key.substr(namespace_prefix.length(), |
242 key.length() - namespace_prefix.length() - 1); | 242 key.length() - namespace_prefix.length() - 1); |
243 // Ensure that we keep track of the namespace even if it doesn't contain | |
244 // any origins. | |
245 (*namespaces_and_origins)[current_namespace_id]; | |
michaeln
2013/02/12 01:42:46
maybe map->insert(id, std::vector<GURL>()) would b
marja
2013/02/12 09:10:41
Done.
| |
243 } else { | 246 } else { |
244 // The key is of the form "namespace-<namespaceid>-<origin>". | 247 // The key is of the form "namespace-<namespaceid>-<origin>". |
245 std::string origin = key.substr(current_namespace_start_key.length()); | 248 std::string origin = key.substr(current_namespace_start_key.length()); |
246 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin)); | 249 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin)); |
247 } | 250 } |
248 } | 251 } |
249 db_->ReleaseSnapshot(options.snapshot); | 252 db_->ReleaseSnapshot(options.snapshot); |
250 return true; | 253 return true; |
251 } | 254 } |
252 | 255 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 bool exists; | 407 bool exists; |
405 if (!GetMapForArea(namespace_id, origin, leveldb::ReadOptions(), &exists, | 408 if (!GetMapForArea(namespace_id, origin, leveldb::ReadOptions(), &exists, |
406 &map_id)) | 409 &map_id)) |
407 return false; | 410 return false; |
408 if (!exists) | 411 if (!exists) |
409 return true; // Nothing to delete. | 412 return true; // Nothing to delete. |
410 if (!DecreaseMapRefCount(map_id, 1, batch)) | 413 if (!DecreaseMapRefCount(map_id, 1, batch)) |
411 return false; | 414 return false; |
412 std::string namespace_key = NamespaceKey(namespace_id, origin); | 415 std::string namespace_key = NamespaceKey(namespace_id, origin); |
413 batch->Delete(namespace_key); | 416 batch->Delete(namespace_key); |
417 | |
418 // If this was the only area in the namespace, delete the namespace start key, | |
419 // too. | |
michaeln
2013/02/12 01:42:46
I doubt this explains the massive size of the file
marja
2013/02/12 09:10:41
Yeah, this is not the reason behind the bug report
| |
420 std::string namespace_start_key = NamespaceStartKey(namespace_id); | |
421 scoped_ptr<leveldb::Iterator> it(db_->NewIterator(leveldb::ReadOptions())); | |
422 it->Seek(namespace_start_key); | |
423 if (!ConsistencyCheck(it->Valid())) | |
424 return false; | |
425 // Advance the iterator 2 times (we still haven't really deleted | |
426 // namespace_key). | |
427 it->Next(); | |
428 if (!ConsistencyCheck(it->Valid())) | |
429 return false; | |
430 it->Next(); | |
431 if (!it->Valid()) | |
432 return true; | |
433 std::string key = it->key().ToString(); | |
434 if (key.find(namespace_start_key) != 0) { | |
michaeln
2013/02/12 01:42:46
nit: {} not needed on the one-liner
marja
2013/02/12 09:10:41
Done.
| |
435 batch->Delete(namespace_start_key); | |
436 } | |
414 return true; | 437 return true; |
415 } | 438 } |
416 | 439 |
417 bool SessionStorageDatabase::GetMapForArea(const std::string& namespace_id, | 440 bool SessionStorageDatabase::GetMapForArea(const std::string& namespace_id, |
418 const std::string& origin, | 441 const std::string& origin, |
419 const leveldb::ReadOptions& options, | 442 const leveldb::ReadOptions& options, |
420 bool* exists, std::string* map_id) { | 443 bool* exists, std::string* map_id) { |
421 std::string namespace_key = NamespaceKey(namespace_id, origin); | 444 std::string namespace_key = NamespaceKey(namespace_id, origin); |
422 leveldb::Status s = db_->Get(options, namespace_key, map_id); | 445 leveldb::Status s = db_->Get(options, namespace_key, map_id); |
423 if (s.IsNotFound()) { | 446 if (s.IsNotFound()) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 std::string SessionStorageDatabase::MapKey(const std::string& map_id, | 641 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
619 const std::string& key) { | 642 const std::string& key) { |
620 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); | 643 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); |
621 } | 644 } |
622 | 645 |
623 const char* SessionStorageDatabase::NextMapIdKey() { | 646 const char* SessionStorageDatabase::NextMapIdKey() { |
624 return "next-map-id"; | 647 return "next-map-id"; |
625 } | 648 } |
626 | 649 |
627 } // namespace dom_storage | 650 } // namespace dom_storage |
OLD | NEW |