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" |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 return; | 432 return; |
| 433 | 433 |
| 434 DOMStorageNamespace::UsageStatistics initial_stats = | 434 DOMStorageNamespace::UsageStatistics initial_stats = |
| 435 GetTotalNamespaceStatistics(namespaces_); | 435 GetTotalNamespaceStatistics(namespaces_); |
| 436 | 436 |
| 437 // Track the total localStorage cache size. | 437 // Track the total localStorage cache size. |
| 438 UMA_HISTOGRAM_CUSTOM_COUNTS("LocalStorage.BrowserLocalStorageCacheSizeInKB", | 438 UMA_HISTOGRAM_CUSTOM_COUNTS("LocalStorage.BrowserLocalStorageCacheSizeInKB", |
| 439 initial_stats.total_cache_size / 1024, 1, 100000, | 439 initial_stats.total_cache_size / 1024, 1, 100000, |
| 440 50); | 440 50); |
| 441 | 441 |
| 442 const char* purge_reason = nullptr; | |
| 442 if (purge_option == PURGE_IF_NEEDED) { | 443 if (purge_option == PURGE_IF_NEEDED) { |
| 443 // Purging is done based on the cache sizes without including the database | 444 // Purging is done based on the cache sizes without including the database |
| 444 // size since it can be expensive trying to estimate the sqlite usage for | 445 // size since it can be expensive trying to estimate the sqlite usage for |
| 445 // all databases. For low end devices purge all inactive areas. | 446 // all databases. For low end devices purge all inactive areas. |
| 446 bool should_purge = | 447 if (!initial_stats.inactive_area_count) |
| 447 initial_stats.inactive_area_count && | 448 return; |
| 448 (is_low_end_device_ || initial_stats.total_cache_size > kMaxCacheSize || | 449 if (is_low_end_device_) |
| 449 initial_stats.total_area_count > kMaxStorageAreaCount); | 450 purge_reason = "InactiveOnLowEndDevice"; |
| 450 if (!should_purge) | 451 else if (initial_stats.total_cache_size > kMaxCacheSize) |
| 452 purge_reason = "SizeLimitExceeded"; | |
| 453 else if (initial_stats.total_area_count > kMaxStorageAreaCount) | |
| 454 purge_reason = "AreaCountLimitExceeded"; | |
| 455 if (!purge_reason) | |
| 451 return; | 456 return; |
| 452 | 457 |
| 453 purge_option = PURGE_UNOPENED; | 458 purge_option = PURGE_UNOPENED; |
| 454 } | 459 } |
| 455 | 460 |
| 456 bool aggressively = purge_option == PURGE_AGGRESSIVE; | 461 bool aggressively = purge_option == PURGE_AGGRESSIVE; |
| 457 for (const auto& it : namespaces_) | 462 for (const auto& it : namespaces_) |
| 458 it.second->PurgeMemory(aggressively); | 463 it.second->PurgeMemory(aggressively); |
| 459 | 464 |
| 460 // Track the size of cache purged. | 465 // Track the size of cache purged. |
| 461 UMA_HISTOGRAM_CUSTOM_COUNTS( | 466 size_t purged_size_kib = |
| 462 "LocalStorage.BrowserLocalStorageCachePurgedInKB", | |
| 463 (initial_stats.total_cache_size - | 467 (initial_stats.total_cache_size - |
| 464 GetTotalNamespaceStatistics(namespaces_).total_cache_size) / | 468 GetTotalNamespaceStatistics(namespaces_).total_cache_size) / |
| 465 1024, | 469 1024; |
| 466 1, 100000, 50); | 470 std::string full_histogram_name = |
| 471 std::string("LocalStorage.BrowserLocalStorageCachePurgedInKB.") + | |
|
Maria
2016/06/16 00:08:15
you also need to update histograms.xml file with t
ssid
2016/06/16 01:01:24
I copied the pattern from "Sqlite.SizeKB" it also
| |
| 472 purge_reason; | |
| 473 base::HistogramBase* histogram = base::Histogram::FactoryGet( | |
| 474 full_histogram_name, 1, 100000, 50, | |
| 475 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 476 if (histogram) | |
| 477 histogram->Add(purged_size_kib); | |
| 478 UMA_HISTOGRAM_CUSTOM_COUNTS("LocalStorage.BrowserLocalStorageCachePurgedInKB", | |
| 479 purged_size_kib, 1, 100000, 50); | |
| 467 } | 480 } |
| 468 | 481 |
| 469 bool DOMStorageContextImpl::OnMemoryDump( | 482 bool DOMStorageContextImpl::OnMemoryDump( |
| 470 const base::trace_event::MemoryDumpArgs& args, | 483 const base::trace_event::MemoryDumpArgs& args, |
| 471 base::trace_event::ProcessMemoryDump* pmd) { | 484 base::trace_event::ProcessMemoryDump* pmd) { |
| 472 if (session_storage_database_) | 485 if (session_storage_database_) |
| 473 session_storage_database_->OnMemoryDump(pmd); | 486 session_storage_database_->OnMemoryDump(pmd); |
| 474 if (args.level_of_detail == | 487 if (args.level_of_detail == |
| 475 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { | 488 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { |
| 476 DOMStorageNamespace::UsageStatistics total_stats = | 489 DOMStorageNamespace::UsageStatistics total_stats = |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 if (!deletable_persistent_namespace_ids_.empty()) { | 570 if (!deletable_persistent_namespace_ids_.empty()) { |
| 558 task_runner_->PostDelayedTask( | 571 task_runner_->PostDelayedTask( |
| 559 FROM_HERE, base::Bind( | 572 FROM_HERE, base::Bind( |
| 560 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 573 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
| 561 this), | 574 this), |
| 562 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 575 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
| 563 } | 576 } |
| 564 } | 577 } |
| 565 | 578 |
| 566 } // namespace content | 579 } // namespace content |
| OLD | NEW |