Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: content/browser/dom_storage/dom_storage_namespace.cc

Issue 1906243002: [tracing] Add a memory dump provider for DOM storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/dom_storage_namespace.h" 5 #include "content/browser/dom_storage/dom_storage_namespace.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/trace_event/memory_dump_manager.h"
10 #include "content/browser/dom_storage/dom_storage_area.h" 11 #include "content/browser/dom_storage/dom_storage_area.h"
11 #include "content/browser/dom_storage/dom_storage_task_runner.h" 12 #include "content/browser/dom_storage/dom_storage_task_runner.h"
12 #include "content/browser/dom_storage/session_storage_database.h" 13 #include "content/browser/dom_storage/session_storage_database.h"
13 #include "content/common/dom_storage/dom_storage_types.h" 14 #include "content/common/dom_storage/dom_storage_types.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 DOMStorageNamespace::DOMStorageNamespace( 18 DOMStorageNamespace::DOMStorageNamespace(
18 const base::FilePath& directory, 19 const base::FilePath& directory,
19 DOMStorageTaskRunner* task_runner) 20 DOMStorageTaskRunner* task_runner)
20 : namespace_id_(kLocalStorageNamespaceId), 21 : namespace_id_(kLocalStorageNamespaceId),
21 directory_(directory), 22 directory_(directory),
22 task_runner_(task_runner) { 23 task_runner_(task_runner) {
23 } 24 }
24 25
25 DOMStorageNamespace::DOMStorageNamespace( 26 DOMStorageNamespace::DOMStorageNamespace(
26 int64_t namespace_id, 27 int64_t namespace_id,
27 const std::string& persistent_namespace_id, 28 const std::string& persistent_namespace_id,
28 SessionStorageDatabase* session_storage_database, 29 SessionStorageDatabase* session_storage_database,
29 DOMStorageTaskRunner* task_runner) 30 DOMStorageTaskRunner* task_runner)
30 : namespace_id_(namespace_id), 31 : namespace_id_(namespace_id),
31 persistent_namespace_id_(persistent_namespace_id), 32 persistent_namespace_id_(persistent_namespace_id),
32 task_runner_(task_runner), 33 task_runner_(task_runner),
33 session_storage_database_(session_storage_database) { 34 session_storage_database_(session_storage_database) {
34 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); 35 DCHECK_NE(kLocalStorageNamespaceId, namespace_id);
36 base::trace_event::MemoryDumpManager::GetInstance()
37 ->RegisterDumpProviderWithSequencedTaskRunner(
38 this, "DOMStorage", task_runner_->GetSequencedTaskRunner(
39 DOMStorageTaskRunner::PRIMARY_SEQUENCE),
40 base::trace_event::MemoryDumpProvider::Options());
35 } 41 }
36 42
37 DOMStorageNamespace::~DOMStorageNamespace() { 43 DOMStorageNamespace::~DOMStorageNamespace() {
44 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
45 this);
38 } 46 }
39 47
40 DOMStorageArea* DOMStorageNamespace::OpenStorageArea(const GURL& origin) { 48 DOMStorageArea* DOMStorageNamespace::OpenStorageArea(const GURL& origin) {
41 if (AreaHolder* holder = GetAreaHolder(origin)) { 49 if (AreaHolder* holder = GetAreaHolder(origin)) {
42 ++(holder->open_count_); 50 ++(holder->open_count_);
43 return holder->area_.get(); 51 return holder->area_.get();
44 } 52 }
45 DOMStorageArea* area; 53 DOMStorageArea* area;
46 if (namespace_id_ == kLocalStorageNamespaceId) { 54 if (namespace_id_ == kLocalStorageNamespaceId) {
47 area = new DOMStorageArea(origin, directory_, task_runner_.get()); 55 area = new DOMStorageArea(origin, directory_, task_runner_.get());
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 177
170 unsigned int DOMStorageNamespace::CountInMemoryAreas() const { 178 unsigned int DOMStorageNamespace::CountInMemoryAreas() const {
171 unsigned int area_count = 0; 179 unsigned int area_count = 0;
172 for (AreaMap::const_iterator it = areas_.begin(); it != areas_.end(); ++it) { 180 for (AreaMap::const_iterator it = areas_.begin(); it != areas_.end(); ++it) {
173 if (it->second.area_->IsLoadedInMemory()) 181 if (it->second.area_->IsLoadedInMemory())
174 ++area_count; 182 ++area_count;
175 } 183 }
176 return area_count; 184 return area_count;
177 } 185 }
178 186
187 bool DOMStorageNamespace::OnMemoryDump(
188 const base::trace_event::MemoryDumpArgs& args,
189 base::trace_event::ProcessMemoryDump* pmd) {
190 DCHECK(task_runner_->IsRunningOnPrimarySequence());
191 for (AreaMap::const_iterator it = areas_.begin(); it != areas_.end(); ++it) {
Primiano Tucci (use gerrit) 2016/04/22 09:56:39 or if you prefer just for (const auto& area : area
ssid 2016/04/22 23:28:16 Done.
192 it->second.area_->OnMemoryDump(pmd);
193 }
194 return true;
195 }
196
179 DOMStorageNamespace::AreaHolder* 197 DOMStorageNamespace::AreaHolder*
180 DOMStorageNamespace::GetAreaHolder(const GURL& origin) { 198 DOMStorageNamespace::GetAreaHolder(const GURL& origin) {
181 AreaMap::iterator found = areas_.find(origin); 199 AreaMap::iterator found = areas_.find(origin);
182 if (found == areas_.end()) 200 if (found == areas_.end())
183 return NULL; 201 return NULL;
184 return &(found->second); 202 return &(found->second);
185 } 203 }
186 204
187 // AreaHolder 205 // AreaHolder
188 206
189 DOMStorageNamespace::AreaHolder::AreaHolder() 207 DOMStorageNamespace::AreaHolder::AreaHolder()
190 : open_count_(0) { 208 : open_count_(0) {
191 } 209 }
192 210
193 DOMStorageNamespace::AreaHolder::AreaHolder( 211 DOMStorageNamespace::AreaHolder::AreaHolder(
194 DOMStorageArea* area, int count) 212 DOMStorageArea* area, int count)
195 : area_(area), open_count_(count) { 213 : area_(area), open_count_(count) {
196 } 214 }
197 215
198 DOMStorageNamespace::AreaHolder::AreaHolder(const AreaHolder& other) = default; 216 DOMStorageNamespace::AreaHolder::AreaHolder(const AreaHolder& other) = default;
199 217
200 DOMStorageNamespace::AreaHolder::~AreaHolder() { 218 DOMStorageNamespace::AreaHolder::~AreaHolder() {
201 } 219 }
202 220
203 } // namespace content 221 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698