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/thread_task_runner_handle.h" | |
16 #include "base/trace_event/memory_dump_manager.h" | |
17 #include "base/trace_event/process_memory_dump.h" | |
15 #include "third_party/leveldatabase/env_chromium.h" | 18 #include "third_party/leveldatabase/env_chromium.h" |
16 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 19 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
17 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" | 20 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" |
18 #include "third_party/leveldatabase/src/include/leveldb/options.h" | 21 #include "third_party/leveldatabase/src/include/leveldb/options.h" |
19 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 22 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
20 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 23 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
21 #include "url/gurl.h" | 24 #include "url/gurl.h" |
22 | 25 |
23 | 26 |
24 namespace { | 27 namespace { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 SessionStorageDatabase* session_storage_database_; | 91 SessionStorageDatabase* session_storage_database_; |
89 }; | 92 }; |
90 | 93 |
91 | 94 |
92 SessionStorageDatabase::SessionStorageDatabase(const base::FilePath& file_path) | 95 SessionStorageDatabase::SessionStorageDatabase(const base::FilePath& file_path) |
93 : file_path_(file_path), | 96 : file_path_(file_path), |
94 db_error_(false), | 97 db_error_(false), |
95 is_inconsistent_(false), | 98 is_inconsistent_(false), |
96 invalid_db_deleted_(false), | 99 invalid_db_deleted_(false), |
97 operation_count_(0) { | 100 operation_count_(0) { |
101 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
102 this, base::ThreadTaskRunnerHandle::Get()); | |
98 } | 103 } |
99 | 104 |
100 SessionStorageDatabase::~SessionStorageDatabase() { | 105 SessionStorageDatabase::~SessionStorageDatabase() { |
106 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
107 this); | |
101 } | 108 } |
102 | 109 |
103 void SessionStorageDatabase::ReadAreaValues(const std::string& namespace_id, | 110 void SessionStorageDatabase::ReadAreaValues(const std::string& namespace_id, |
104 const GURL& origin, | 111 const GURL& origin, |
105 DOMStorageValuesMap* result) { | 112 DOMStorageValuesMap* result) { |
106 // We don't create a database if it doesn't exist. In that case, there is | 113 // We don't create a database if it doesn't exist. In that case, there is |
107 // nothing to be added to the result. | 114 // nothing to be added to the result. |
108 if (!LazyOpen(false)) | 115 if (!LazyOpen(false)) |
109 return; | 116 return; |
110 DBOperation operation(this); | 117 DBOperation operation(this); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 } else { | 323 } else { |
317 // The key is of the form "namespace-<namespaceid>-<origin>". | 324 // The key is of the form "namespace-<namespaceid>-<origin>". |
318 std::string origin = key.substr(current_namespace_start_key.length()); | 325 std::string origin = key.substr(current_namespace_start_key.length()); |
319 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin)); | 326 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin)); |
320 } | 327 } |
321 } | 328 } |
322 db_->ReleaseSnapshot(options.snapshot); | 329 db_->ReleaseSnapshot(options.snapshot); |
323 return true; | 330 return true; |
324 } | 331 } |
325 | 332 |
333 bool SessionStorageDatabase::OnMemoryDump( | |
334 const base::trace_event::MemoryDumpArgs& args, | |
335 base::trace_event::ProcessMemoryDump* pmd) { | |
336 base::AutoLock auto_lock(db_lock_); | |
337 if (!db_) | |
338 return true; | |
339 | |
340 base::trace_event::MemoryAllocatorDump* dump = | |
341 pmd->CreateAllocatorDump("leveldb/session_storage_db"); | |
342 | |
Primiano Tucci (use gerrit)
2015/10/15 15:27:56
why are you locking db_lock_ twice? doesn't this d
ssid
2015/10/15 15:36:27
yes removed.
| |
343 base::AutoLock auto_lock(db_lock_); | |
344 std::string value; | |
345 uint64 size; | |
346 bool res = db_->GetProperty("leveldb.approximate-memory-usage", &value); | |
347 DCHECK(res); | |
348 base::StringToUint64(value, &size); | |
349 | |
350 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
351 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); | |
352 | |
353 // Memory is allocated from system allocator (malloc). | |
354 pmd->AddSuballocation(dump->guid(), | |
355 base::trace_event::MemoryDumpManager::GetInstance() | |
356 ->system_allocator_pool_name()); | |
357 return true; | |
358 } | |
359 | |
326 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { | 360 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { |
327 base::AutoLock auto_lock(db_lock_); | 361 base::AutoLock auto_lock(db_lock_); |
328 if (db_error_ || is_inconsistent_) { | 362 if (db_error_ || is_inconsistent_) { |
329 // Don't try to open a database that we know has failed already. | 363 // Don't try to open a database that we know has failed already. |
330 return false; | 364 return false; |
331 } | 365 } |
332 if (IsOpen()) | 366 if (IsOpen()) |
333 return true; | 367 return true; |
334 | 368 |
335 if (!create_if_needed && | 369 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, | 755 std::string SessionStorageDatabase::MapKey(const std::string& map_id, |
722 const std::string& key) { | 756 const std::string& key) { |
723 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); | 757 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); |
724 } | 758 } |
725 | 759 |
726 const char* SessionStorageDatabase::NextMapIdKey() { | 760 const char* SessionStorageDatabase::NextMapIdKey() { |
727 return "next-map-id"; | 761 return "next-map-id"; |
728 } | 762 } |
729 | 763 |
730 } // namespace content | 764 } // namespace content |
OLD | NEW |