| 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/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/strings/stringprintf.h" |
| 17 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "base/trace_event/memory_dump_manager.h" | 20 #include "base/trace_event/memory_dump_manager.h" |
| 20 #include "base/trace_event/process_memory_dump.h" | 21 #include "base/trace_event/process_memory_dump.h" |
| 21 #include "content/browser/dom_storage/dom_storage_area.h" | 22 #include "content/browser/dom_storage/dom_storage_area.h" |
| 22 #include "content/browser/dom_storage/dom_storage_database.h" | 23 #include "content/browser/dom_storage/dom_storage_database.h" |
| 23 #include "content/browser/dom_storage/dom_storage_namespace.h" | 24 #include "content/browser/dom_storage/dom_storage_namespace.h" |
| 24 #include "content/browser/dom_storage/dom_storage_task_runner.h" | 25 #include "content/browser/dom_storage/dom_storage_task_runner.h" |
| 25 #include "content/browser/dom_storage/session_storage_database.h" | 26 #include "content/browser/dom_storage/session_storage_database.h" |
| 26 #include "content/common/dom_storage/dom_storage_types.h" | 27 #include "content/common/dom_storage/dom_storage_types.h" |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 "LocalStorage.BrowserLocalStorageCachePurgedInKB", | 462 "LocalStorage.BrowserLocalStorageCachePurgedInKB", |
| 462 (initial_stats.total_cache_size - | 463 (initial_stats.total_cache_size - |
| 463 GetTotalNamespaceStatistics(namespaces_).total_cache_size) / | 464 GetTotalNamespaceStatistics(namespaces_).total_cache_size) / |
| 464 1024, | 465 1024, |
| 465 1, 100000, 50); | 466 1, 100000, 50); |
| 466 } | 467 } |
| 467 | 468 |
| 468 bool DOMStorageContextImpl::OnMemoryDump( | 469 bool DOMStorageContextImpl::OnMemoryDump( |
| 469 const base::trace_event::MemoryDumpArgs& args, | 470 const base::trace_event::MemoryDumpArgs& args, |
| 470 base::trace_event::ProcessMemoryDump* pmd) { | 471 base::trace_event::ProcessMemoryDump* pmd) { |
| 472 if (session_storage_database_) |
| 473 session_storage_database_->OnMemoryDump(pmd); |
| 474 if (args.level_of_detail == |
| 475 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { |
| 476 DOMStorageNamespace::UsageStatistics total_stats = |
| 477 GetTotalNamespaceStatistics(namespaces_); |
| 478 auto mad = pmd->CreateAllocatorDump( |
| 479 StringPrintf("dom_storage/%p/cache_size", this)); |
| 480 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 481 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 482 total_stats.total_cache_size); |
| 483 mad->AddScalar("inactive_areas", |
| 484 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 485 total_stats.inactive_area_count); |
| 486 mad->AddScalar("total_areas", |
| 487 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 488 total_stats.total_area_count); |
| 489 return true; |
| 490 } |
| 471 for (const auto& it : namespaces_) { | 491 for (const auto& it : namespaces_) { |
| 472 it.second->OnMemoryDump(pmd); | 492 it.second->OnMemoryDump(pmd); |
| 473 } | 493 } |
| 474 if (session_storage_database_) | |
| 475 session_storage_database_->OnMemoryDump(pmd); | |
| 476 return true; | 494 return true; |
| 477 } | 495 } |
| 478 | 496 |
| 479 void DOMStorageContextImpl::FindUnusedNamespaces() { | 497 void DOMStorageContextImpl::FindUnusedNamespaces() { |
| 480 DCHECK(session_storage_database_.get()); | 498 DCHECK(session_storage_database_.get()); |
| 481 if (scavenging_started_) | 499 if (scavenging_started_) |
| 482 return; | 500 return; |
| 483 scavenging_started_ = true; | 501 scavenging_started_ = true; |
| 484 std::set<std::string> namespace_ids_in_use; | 502 std::set<std::string> namespace_ids_in_use; |
| 485 for (StorageNamespaceMap::const_iterator it = namespaces_.begin(); | 503 for (StorageNamespaceMap::const_iterator it = namespaces_.begin(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 if (!deletable_persistent_namespace_ids_.empty()) { | 557 if (!deletable_persistent_namespace_ids_.empty()) { |
| 540 task_runner_->PostDelayedTask( | 558 task_runner_->PostDelayedTask( |
| 541 FROM_HERE, base::Bind( | 559 FROM_HERE, base::Bind( |
| 542 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 560 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
| 543 this), | 561 this), |
| 544 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 562 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
| 545 } | 563 } |
| 546 } | 564 } |
| 547 | 565 |
| 548 } // namespace content | 566 } // namespace content |
| OLD | NEW |