Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 // Tests may run without task runners. | |
| 57 if (task_runner_) { | |
| 58 // Registering dump provider is safe even outside the task runner. | |
| 59 base::trace_event::MemoryDumpManager::GetInstance() | |
| 60 ->RegisterDumpProviderWithSequencedTaskRunner( | |
| 61 this, "DOMStorage", task_runner_->GetSequencedTaskRunner( | |
| 62 DOMStorageTaskRunner::PRIMARY_SEQUENCE), | |
| 63 base::trace_event::MemoryDumpProvider::Options()); | |
| 64 } | |
| 53 } | 65 } |
| 54 | 66 |
| 55 DOMStorageContextImpl::~DOMStorageContextImpl() { | 67 DOMStorageContextImpl::~DOMStorageContextImpl() { |
| 68 DCHECK(is_shutdown_); | |
| 56 if (session_storage_database_.get()) { | 69 if (session_storage_database_.get()) { |
| 57 // SessionStorageDatabase shouldn't be deleted right away: deleting it will | 70 // SessionStorageDatabase shouldn't be deleted right away: deleting it will |
| 58 // potentially involve waiting in leveldb::DBImpl::~DBImpl, and waiting | 71 // potentially involve waiting in leveldb::DBImpl::~DBImpl, and waiting |
| 59 // shouldn't happen on this thread. | 72 // shouldn't happen on this thread. |
| 60 SessionStorageDatabase* to_release = session_storage_database_.get(); | 73 SessionStorageDatabase* to_release = session_storage_database_.get(); |
| 61 to_release->AddRef(); | 74 to_release->AddRef(); |
| 62 session_storage_database_ = NULL; | 75 session_storage_database_ = NULL; |
| 63 task_runner_->PostShutdownBlockingTask( | 76 task_runner_->PostShutdownBlockingTask( |
| 64 FROM_HERE, | 77 FROM_HERE, |
| 65 DOMStorageTaskRunner::COMMIT_SEQUENCE, | 78 DOMStorageTaskRunner::COMMIT_SEQUENCE, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 dom_storage_namespace->GetOpenStorageArea(usage_info.origin); | 179 dom_storage_namespace->GetOpenStorageArea(usage_info.origin); |
| 167 if (area) | 180 if (area) |
| 168 NotifyAreaCleared(area, usage_info.origin); | 181 NotifyAreaCleared(area, usage_info.origin); |
| 169 } | 182 } |
| 170 | 183 |
| 171 void DOMStorageContextImpl::Flush() { | 184 void DOMStorageContextImpl::Flush() { |
| 172 for (auto& entry : namespaces_) | 185 for (auto& entry : namespaces_) |
| 173 entry.second->Flush(); | 186 entry.second->Flush(); |
| 174 } | 187 } |
| 175 | 188 |
| 176 void DOMStorageContextImpl::Shutdown() { | 189 void DOMStorageContextImpl::Shutdown() { |
|
michaeln
2016/05/02 22:47:12
DCHECK(!task_runner_ || task_runner_->IsRunningOnP
ssid
2016/05/04 06:06:14
Done.
| |
| 177 is_shutdown_ = true; | 190 is_shutdown_ = true; |
| 178 StorageNamespaceMap::const_iterator it = namespaces_.begin(); | 191 StorageNamespaceMap::const_iterator it = namespaces_.begin(); |
| 179 for (; it != namespaces_.end(); ++it) | 192 for (; it != namespaces_.end(); ++it) |
| 180 it->second->Shutdown(); | 193 it->second->Shutdown(); |
| 181 | 194 |
| 195 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
| 196 this); | |
| 197 | |
| 182 if (localstorage_directory_.empty() && !session_storage_database_.get()) | 198 if (localstorage_directory_.empty() && !session_storage_database_.get()) |
| 183 return; | 199 return; |
| 184 | 200 |
| 185 // Respect the content policy settings about what to | 201 // Respect the content policy settings about what to |
| 186 // keep and what to discard. | 202 // keep and what to discard. |
| 187 if (force_keep_session_state_) | 203 if (force_keep_session_state_) |
| 188 return; // Keep everything. | 204 return; // Keep everything. |
| 189 | 205 |
| 190 bool has_session_only_origins = | 206 bool has_session_only_origins = |
| 191 special_storage_policy_.get() && | 207 special_storage_policy_.get() && |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 | 366 |
| 351 void DOMStorageContextImpl::StartScavengingUnusedSessionStorage() { | 367 void DOMStorageContextImpl::StartScavengingUnusedSessionStorage() { |
| 352 if (session_storage_database_.get()) { | 368 if (session_storage_database_.get()) { |
| 353 task_runner_->PostDelayedTask( | 369 task_runner_->PostDelayedTask( |
| 354 FROM_HERE, base::Bind(&DOMStorageContextImpl::FindUnusedNamespaces, | 370 FROM_HERE, base::Bind(&DOMStorageContextImpl::FindUnusedNamespaces, |
| 355 this), | 371 this), |
| 356 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 372 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
| 357 } | 373 } |
| 358 } | 374 } |
| 359 | 375 |
| 376 bool DOMStorageContextImpl::OnMemoryDump( | |
| 377 const base::trace_event::MemoryDumpArgs& args, | |
| 378 base::trace_event::ProcessMemoryDump* pmd) { | |
| 379 for (const auto& it : namespaces_) { | |
| 380 it.second->OnMemoryDump(pmd); | |
| 381 } | |
| 382 if (session_storage_database_) | |
| 383 session_storage_database_->OnMemoryDump(pmd); | |
| 384 return true; | |
| 385 } | |
| 386 | |
| 360 void DOMStorageContextImpl::FindUnusedNamespaces() { | 387 void DOMStorageContextImpl::FindUnusedNamespaces() { |
| 361 DCHECK(session_storage_database_.get()); | 388 DCHECK(session_storage_database_.get()); |
| 362 if (scavenging_started_) | 389 if (scavenging_started_) |
| 363 return; | 390 return; |
| 364 scavenging_started_ = true; | 391 scavenging_started_ = true; |
| 365 std::set<std::string> namespace_ids_in_use; | 392 std::set<std::string> namespace_ids_in_use; |
| 366 for (StorageNamespaceMap::const_iterator it = namespaces_.begin(); | 393 for (StorageNamespaceMap::const_iterator it = namespaces_.begin(); |
| 367 it != namespaces_.end(); ++it) | 394 it != namespaces_.end(); ++it) |
| 368 namespace_ids_in_use.insert(it->second->persistent_namespace_id()); | 395 namespace_ids_in_use.insert(it->second->persistent_namespace_id()); |
| 369 std::set<std::string> protected_persistent_session_ids; | 396 std::set<std::string> protected_persistent_session_ids; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 if (!deletable_persistent_namespace_ids_.empty()) { | 447 if (!deletable_persistent_namespace_ids_.empty()) { |
| 421 task_runner_->PostDelayedTask( | 448 task_runner_->PostDelayedTask( |
| 422 FROM_HERE, base::Bind( | 449 FROM_HERE, base::Bind( |
| 423 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 450 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
| 424 this), | 451 this), |
| 425 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 452 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
| 426 } | 453 } |
| 427 } | 454 } |
| 428 | 455 |
| 429 } // namespace content | 456 } // namespace content |
| OLD | NEW |