Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/dom_storage/session_storage_database.h" | 5 #include "content/browser/dom_storage/session_storage_database.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/trace_event/memory_dump_manager.h" | |
| 16 #include "base/trace_event/process_memory_dump.h" | |
| 15 #include "third_party/leveldatabase/env_chromium.h" | 17 #include "third_party/leveldatabase/env_chromium.h" |
| 16 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 18 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 17 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" | 19 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" |
| 18 #include "third_party/leveldatabase/src/include/leveldb/options.h" | 20 #include "third_party/leveldatabase/src/include/leveldb/options.h" |
| 19 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 21 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
| 20 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 22 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
| 21 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 22 | 24 |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 SessionStorageDatabase* session_storage_database_; | 90 SessionStorageDatabase* session_storage_database_; |
| 89 }; | 91 }; |
| 90 | 92 |
| 91 | 93 |
| 92 SessionStorageDatabase::SessionStorageDatabase(const base::FilePath& file_path) | 94 SessionStorageDatabase::SessionStorageDatabase(const base::FilePath& file_path) |
| 93 : file_path_(file_path), | 95 : file_path_(file_path), |
| 94 db_error_(false), | 96 db_error_(false), |
| 95 is_inconsistent_(false), | 97 is_inconsistent_(false), |
| 96 invalid_db_deleted_(false), | 98 invalid_db_deleted_(false), |
| 97 operation_count_(0) { | 99 operation_count_(0) { |
| 100 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
| 101 this); | |
| 98 } | 102 } |
| 99 | 103 |
| 100 SessionStorageDatabase::~SessionStorageDatabase() { | 104 SessionStorageDatabase::~SessionStorageDatabase() { |
| 105 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
| 106 this); | |
|
Primiano Tucci (use gerrit)
2015/10/15 08:59:52
if you unregister the RegisterDumpProvider call ab
ssid
2015/10/15 15:22:04
Thanks, I guess both were done in the same thread
| |
| 101 } | 107 } |
| 102 | 108 |
| 103 void SessionStorageDatabase::ReadAreaValues(const std::string& namespace_id, | 109 void SessionStorageDatabase::ReadAreaValues(const std::string& namespace_id, |
| 104 const GURL& origin, | 110 const GURL& origin, |
| 105 DOMStorageValuesMap* result) { | 111 DOMStorageValuesMap* result) { |
| 106 // We don't create a database if it doesn't exist. In that case, there is | 112 // We don't create a database if it doesn't exist. In that case, there is |
| 107 // nothing to be added to the result. | 113 // nothing to be added to the result. |
| 108 if (!LazyOpen(false)) | 114 if (!LazyOpen(false)) |
| 109 return; | 115 return; |
| 110 DBOperation operation(this); | 116 DBOperation operation(this); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 } else { | 322 } else { |
| 317 // The key is of the form "namespace-<namespaceid>-<origin>". | 323 // The key is of the form "namespace-<namespaceid>-<origin>". |
| 318 std::string origin = key.substr(current_namespace_start_key.length()); | 324 std::string origin = key.substr(current_namespace_start_key.length()); |
| 319 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin)); | 325 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin)); |
| 320 } | 326 } |
| 321 } | 327 } |
| 322 db_->ReleaseSnapshot(options.snapshot); | 328 db_->ReleaseSnapshot(options.snapshot); |
| 323 return true; | 329 return true; |
| 324 } | 330 } |
| 325 | 331 |
| 332 bool SessionStorageDatabase::OnMemoryDump( | |
| 333 const base::trace_event::MemoryDumpArgs& args, | |
| 334 base::trace_event::ProcessMemoryDump* pmd) { | |
| 335 if (!db_) | |
| 336 return true; | |
| 337 | |
| 338 base::trace_event::MemoryAllocatorDump* dump = | |
| 339 pmd->CreateAllocatorDump("leveldb/session_storage_db"); | |
| 340 | |
| 341 base::AutoLock auto_lock(db_lock_); | |
| 342 std::string value; | |
| 343 uint64 size; | |
| 344 db_->GetProperty("leveldb.approximate-memory-usage", &value); | |
|
Primiano Tucci (use gerrit)
2015/10/15 08:59:52
shouldn't you check the return value of GetPropert
ssid
2015/10/15 15:22:04
Actually it cannot fail. added dcheck.
| |
| 345 base::StringToUint64(value, &size); | |
| 346 | |
| 347 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
| 348 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); | |
| 349 | |
| 350 // Memory is allocated from system allocator (malloc). | |
| 351 pmd->AddSuballocation(dump->guid(), | |
| 352 base::trace_event::MemoryDumpManager::GetInstance() | |
| 353 ->system_allocator_pool_name()); | |
| 354 return true; | |
| 355 } | |
| 356 | |
| 326 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { | 357 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { |
| 327 base::AutoLock auto_lock(db_lock_); | 358 base::AutoLock auto_lock(db_lock_); |
| 328 if (db_error_ || is_inconsistent_) { | 359 if (db_error_ || is_inconsistent_) { |
| 329 // Don't try to open a database that we know has failed already. | 360 // Don't try to open a database that we know has failed already. |
| 330 return false; | 361 return false; |
| 331 } | 362 } |
| 332 if (IsOpen()) | 363 if (IsOpen()) |
| 333 return true; | 364 return true; |
| 334 | 365 |
| 335 if (!create_if_needed && | 366 if (!create_if_needed && |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 std::string SessionStorageDatabase::MapKey(const std::string& map_id, | 752 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
| 722 const std::string& key) { | 753 const std::string& key) { |
| 723 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); | 754 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); |
| 724 } | 755 } |
| 725 | 756 |
| 726 const char* SessionStorageDatabase::NextMapIdKey() { | 757 const char* SessionStorageDatabase::NextMapIdKey() { |
| 727 return "next-map-id"; | 758 return "next-map-id"; |
| 728 } | 759 } |
| 729 | 760 |
| 730 } // namespace content | 761 } // namespace content |
| OLD | NEW |