| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/trace_event/memory_dump_manager.h" |
| 18 #include "base/trace_event/process_memory_dump.h" |
| 17 #include "third_party/leveldatabase/env_chromium.h" | 19 #include "third_party/leveldatabase/env_chromium.h" |
| 18 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 20 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 19 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" | 21 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" |
| 20 #include "third_party/leveldatabase/src/include/leveldb/options.h" | 22 #include "third_party/leveldatabase/src/include/leveldb/options.h" |
| 21 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 23 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
| 22 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 24 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
| 23 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 24 | 26 |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } else { | 320 } else { |
| 319 // The key is of the form "namespace-<namespaceid>-<origin>". | 321 // The key is of the form "namespace-<namespaceid>-<origin>". |
| 320 std::string origin = key.substr(current_namespace_start_key.length()); | 322 std::string origin = key.substr(current_namespace_start_key.length()); |
| 321 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin)); | 323 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin)); |
| 322 } | 324 } |
| 323 } | 325 } |
| 324 db_->ReleaseSnapshot(options.snapshot); | 326 db_->ReleaseSnapshot(options.snapshot); |
| 325 return true; | 327 return true; |
| 326 } | 328 } |
| 327 | 329 |
| 330 bool SessionStorageDatabase::OnMemoryDump( |
| 331 base::trace_event::ProcessMemoryDump* pmd) { |
| 332 std::string db_memory_usage; |
| 333 { |
| 334 base::AutoLock lock(db_lock_); |
| 335 // Return true if |db_| is null to prevent the dump provider from being |
| 336 // disabled, since it can be created lazily. |
| 337 if (!db_) |
| 338 return true; |
| 339 |
| 340 bool res = |
| 341 db_->GetProperty("leveldb.approximate-memory-usage", &db_memory_usage); |
| 342 DCHECK(res); |
| 343 } |
| 344 |
| 345 uint64_t size; |
| 346 bool res = base::StringToUint64(db_memory_usage, &size); |
| 347 DCHECK(res); |
| 348 |
| 349 auto mad = pmd->CreateAllocatorDump( |
| 350 base::StringPrintf("dom_storage/session_storage_%p", this)); |
| 351 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 352 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); |
| 353 |
| 354 // Memory is allocated from system allocator (malloc). |
| 355 const char* system_allocator_name = |
| 356 base::trace_event::MemoryDumpManager::GetInstance() |
| 357 ->system_allocator_pool_name(); |
| 358 if (system_allocator_name) |
| 359 pmd->AddSuballocation(mad->guid(), system_allocator_name); |
| 360 return true; |
| 361 } |
| 328 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { | 362 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { |
| 329 base::AutoLock auto_lock(db_lock_); | 363 base::AutoLock auto_lock(db_lock_); |
| 330 if (db_error_ || is_inconsistent_) { | 364 if (db_error_ || is_inconsistent_) { |
| 331 // Don't try to open a database that we know has failed already. | 365 // Don't try to open a database that we know has failed already. |
| 332 return false; | 366 return false; |
| 333 } | 367 } |
| 334 if (IsOpen()) | 368 if (IsOpen()) |
| 335 return true; | 369 return true; |
| 336 | 370 |
| 337 if (!create_if_needed && | 371 if (!create_if_needed && |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 std::string SessionStorageDatabase::MapKey(const std::string& map_id, | 762 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
| 729 const std::string& key) { | 763 const std::string& key) { |
| 730 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); | 764 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); |
| 731 } | 765 } |
| 732 | 766 |
| 733 const char* SessionStorageDatabase::NextMapIdKey() { | 767 const char* SessionStorageDatabase::NextMapIdKey() { |
| 734 return "next-map-id"; | 768 return "next-map-id"; |
| 735 } | 769 } |
| 736 | 770 |
| 737 } // namespace content | 771 } // namespace content |
| OLD | NEW |