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

Side by Side Diff: content/browser/dom_storage/dom_storage_context_impl.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, 7 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 (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 "content/browser/dom_storage/dom_storage_context_impl.h" 5 #include "content/browser/dom_storage/dom_storage_context_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/files/file_enumerator.h" 12 #include "base/files/file_enumerator.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/guid.h" 14 #include "base/guid.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/trace_event/memory_dump_manager.h"
18 #include "base/trace_event/process_memory_dump.h"
17 #include "content/browser/dom_storage/dom_storage_area.h" 19 #include "content/browser/dom_storage/dom_storage_area.h"
18 #include "content/browser/dom_storage/dom_storage_database.h" 20 #include "content/browser/dom_storage/dom_storage_database.h"
19 #include "content/browser/dom_storage/dom_storage_namespace.h" 21 #include "content/browser/dom_storage/dom_storage_namespace.h"
20 #include "content/browser/dom_storage/dom_storage_task_runner.h" 22 #include "content/browser/dom_storage/dom_storage_task_runner.h"
21 #include "content/browser/dom_storage/session_storage_database.h" 23 #include "content/browser/dom_storage/session_storage_database.h"
22 #include "content/common/dom_storage/dom_storage_types.h" 24 #include "content/common/dom_storage/dom_storage_types.h"
23 #include "content/public/browser/dom_storage_context.h" 25 #include "content/public/browser/dom_storage_context.h"
24 #include "content/public/browser/local_storage_usage_info.h" 26 #include "content/public/browser/local_storage_usage_info.h"
25 #include "content/public/browser/session_storage_usage_info.h" 27 #include "content/public/browser/session_storage_usage_info.h"
26 #include "storage/browser/quota/special_storage_policy.h" 28 #include "storage/browser/quota/special_storage_policy.h"
(...skipping 16 matching lines...) Expand all
43 task_runner_(task_runner), 45 task_runner_(task_runner),
44 session_id_offset_(abs((g_session_id_offset_sequence++ % 10)) * 1000), 46 session_id_offset_(abs((g_session_id_offset_sequence++ % 10)) * 1000),
45 is_shutdown_(false), 47 is_shutdown_(false),
46 force_keep_session_state_(false), 48 force_keep_session_state_(false),
47 special_storage_policy_(special_storage_policy), 49 special_storage_policy_(special_storage_policy),
48 scavenging_started_(false) { 50 scavenging_started_(false) {
49 // AtomicSequenceNum starts at 0 but we want to start session 51 // AtomicSequenceNum starts at 0 but we want to start session
50 // namespace ids at one since zero is reserved for the 52 // namespace ids at one since zero is reserved for the
51 // kLocalStorageNamespaceId. 53 // kLocalStorageNamespaceId.
52 session_id_sequence_.GetNext(); 54 session_id_sequence_.GetNext();
55
56 // Registering dump provider is safe even outside the task runner.
57 base::trace_event::MemoryDumpManager::GetInstance()
58 ->RegisterDumpProviderWithSequencedTaskRunner(
59 this, "DOMStorage", task_runner_->GetSequencedTaskRunner(
60 DOMStorageTaskRunner::PRIMARY_SEQUENCE),
61 base::trace_event::MemoryDumpProvider::Options());
53 } 62 }
54 63
55 DOMStorageContextImpl::~DOMStorageContextImpl() { 64 DOMStorageContextImpl::~DOMStorageContextImpl() {
michaeln 2016/04/26 22:56:25 can you add a DCHECK(is_shutdown_) here to test ou
56 if (session_storage_database_.get()) { 65 if (session_storage_database_.get()) {
57 // SessionStorageDatabase shouldn't be deleted right away: deleting it will 66 // SessionStorageDatabase shouldn't be deleted right away: deleting it will
58 // potentially involve waiting in leveldb::DBImpl::~DBImpl, and waiting 67 // potentially involve waiting in leveldb::DBImpl::~DBImpl, and waiting
59 // shouldn't happen on this thread. 68 // shouldn't happen on this thread.
60 SessionStorageDatabase* to_release = session_storage_database_.get(); 69 SessionStorageDatabase* to_release = session_storage_database_.get();
61 to_release->AddRef(); 70 to_release->AddRef();
62 session_storage_database_ = NULL; 71 session_storage_database_ = NULL;
63 task_runner_->PostShutdownBlockingTask( 72 task_runner_->PostShutdownBlockingTask(
64 FROM_HERE, 73 FROM_HERE,
65 DOMStorageTaskRunner::COMMIT_SEQUENCE, 74 DOMStorageTaskRunner::COMMIT_SEQUENCE,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 for (auto& entry : namespaces_) 181 for (auto& entry : namespaces_)
173 entry.second->Flush(); 182 entry.second->Flush();
174 } 183 }
175 184
176 void DOMStorageContextImpl::Shutdown() { 185 void DOMStorageContextImpl::Shutdown() {
177 is_shutdown_ = true; 186 is_shutdown_ = true;
178 StorageNamespaceMap::const_iterator it = namespaces_.begin(); 187 StorageNamespaceMap::const_iterator it = namespaces_.begin();
179 for (; it != namespaces_.end(); ++it) 188 for (; it != namespaces_.end(); ++it)
180 it->second->Shutdown(); 189 it->second->Shutdown();
181 190
191 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
192 this);
193
182 if (localstorage_directory_.empty() && !session_storage_database_.get()) 194 if (localstorage_directory_.empty() && !session_storage_database_.get())
183 return; 195 return;
184 196
185 // Respect the content policy settings about what to 197 // Respect the content policy settings about what to
186 // keep and what to discard. 198 // keep and what to discard.
187 if (force_keep_session_state_) 199 if (force_keep_session_state_)
188 return; // Keep everything. 200 return; // Keep everything.
189 201
190 bool has_session_only_origins = 202 bool has_session_only_origins =
191 special_storage_policy_.get() && 203 special_storage_policy_.get() &&
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 362
351 void DOMStorageContextImpl::StartScavengingUnusedSessionStorage() { 363 void DOMStorageContextImpl::StartScavengingUnusedSessionStorage() {
352 if (session_storage_database_.get()) { 364 if (session_storage_database_.get()) {
353 task_runner_->PostDelayedTask( 365 task_runner_->PostDelayedTask(
354 FROM_HERE, base::Bind(&DOMStorageContextImpl::FindUnusedNamespaces, 366 FROM_HERE, base::Bind(&DOMStorageContextImpl::FindUnusedNamespaces,
355 this), 367 this),
356 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); 368 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds));
357 } 369 }
358 } 370 }
359 371
372 bool DOMStorageContextImpl::OnMemoryDump(
373 const base::trace_event::MemoryDumpArgs& args,
374 base::trace_event::ProcessMemoryDump* pmd) {
375 for (const auto& it : namespaces_) {
376 it.second->OnMemoryDump(pmd);
377 }
378 if (session_storage_database_)
379 session_storage_database_->OnMemoryDump(pmd);
380 return true;
381 }
382
360 void DOMStorageContextImpl::FindUnusedNamespaces() { 383 void DOMStorageContextImpl::FindUnusedNamespaces() {
361 DCHECK(session_storage_database_.get()); 384 DCHECK(session_storage_database_.get());
362 if (scavenging_started_) 385 if (scavenging_started_)
363 return; 386 return;
364 scavenging_started_ = true; 387 scavenging_started_ = true;
365 std::set<std::string> namespace_ids_in_use; 388 std::set<std::string> namespace_ids_in_use;
366 for (StorageNamespaceMap::const_iterator it = namespaces_.begin(); 389 for (StorageNamespaceMap::const_iterator it = namespaces_.begin();
367 it != namespaces_.end(); ++it) 390 it != namespaces_.end(); ++it)
368 namespace_ids_in_use.insert(it->second->persistent_namespace_id()); 391 namespace_ids_in_use.insert(it->second->persistent_namespace_id());
369 std::set<std::string> protected_persistent_session_ids; 392 std::set<std::string> protected_persistent_session_ids;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 if (!deletable_persistent_namespace_ids_.empty()) { 443 if (!deletable_persistent_namespace_ids_.empty()) {
421 task_runner_->PostDelayedTask( 444 task_runner_->PostDelayedTask(
422 FROM_HERE, base::Bind( 445 FROM_HERE, base::Bind(
423 &DOMStorageContextImpl::DeleteNextUnusedNamespace, 446 &DOMStorageContextImpl::DeleteNextUnusedNamespace,
424 this), 447 this),
425 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); 448 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds));
426 } 449 }
427 } 450 }
428 451
429 } // namespace content 452 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698