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 <inttypes.h> | 7 #include <inttypes.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 | 10 |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 427 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 | 430 |
| 431 void DOMStorageContextImpl::PurgeMemory(PurgeOption purge_option) { | 431 void DOMStorageContextImpl::PurgeMemory(PurgeOption purge_option) { |
| 432 if (is_shutdown_) | 432 if (is_shutdown_) |
| 433 return; | 433 return; |
| 434 | 434 |
| 435 DOMStorageNamespace::UsageStatistics initial_stats = | 435 DOMStorageNamespace::UsageStatistics initial_stats = |
| 436 GetTotalNamespaceStatistics(namespaces_); | 436 GetTotalNamespaceStatistics(namespaces_); |
| 437 if (!initial_stats.total_area_count) | |
| 438 return; | |
| 437 | 439 |
| 438 // Track the total localStorage cache size. | 440 // Track the total localStorage cache size. |
| 439 UMA_HISTOGRAM_CUSTOM_COUNTS("LocalStorage.BrowserLocalStorageCacheSizeInKB", | 441 UMA_HISTOGRAM_CUSTOM_COUNTS("LocalStorage.BrowserLocalStorageCacheSizeInKB", |
| 440 initial_stats.total_cache_size / 1024, 1, 100000, | 442 initial_stats.total_cache_size / 1024, 1, 100000, |
| 441 50); | 443 50); |
| 442 | 444 |
| 443 const char* purge_reason = nullptr; | 445 const char* purge_reason = nullptr; |
| 444 if (purge_option == PURGE_IF_NEEDED) { | 446 if (purge_option == PURGE_IF_NEEDED) { |
| 445 // Purging is done based on the cache sizes without including the database | 447 // Purging is done based on the cache sizes without including the database |
| 446 // size since it can be expensive trying to estimate the sqlite usage for | 448 // size since it can be expensive trying to estimate the sqlite usage for |
| 447 // all databases. For low end devices purge all inactive areas. | 449 // all databases. For low end devices purge all inactive areas. |
| 448 if (!initial_stats.inactive_area_count) | |
| 449 return; | |
| 450 | |
| 451 if (initial_stats.total_cache_size > kMaxCacheSize) | 450 if (initial_stats.total_cache_size > kMaxCacheSize) |
| 452 purge_reason = "SizeLimitExceeded"; | 451 purge_reason = "SizeLimitExceeded"; |
| 453 else if (initial_stats.total_area_count > kMaxStorageAreaCount) | 452 else if (initial_stats.total_area_count > kMaxStorageAreaCount) |
| 454 purge_reason = "AreaCountLimitExceeded"; | 453 purge_reason = "AreaCountLimitExceeded"; |
| 455 else if (is_low_end_device_) | 454 else if (is_low_end_device_) |
| 456 purge_reason = "InactiveOnLowEndDevice"; | 455 purge_reason = "InactiveOnLowEndDevice"; |
| 457 if (!purge_reason) | 456 if (!purge_reason) |
| 458 return; | 457 return; |
| 459 | 458 |
| 460 purge_option = PURGE_UNOPENED; | 459 purge_option = PURGE_UNOPENED; |
| 461 } | 460 } else { |
| 462 | |
| 463 bool aggressively = purge_option == PURGE_AGGRESSIVE; | |
| 464 for (const auto& it : namespaces_) | |
| 465 it.second->PurgeMemory(aggressively); | |
| 466 | |
| 467 // Track the size of cache purged. | |
| 468 if (!purge_reason) { | |
| 469 if (purge_option == PURGE_AGGRESSIVE) | 461 if (purge_option == PURGE_AGGRESSIVE) |
| 470 purge_reason = "AggressivePurgeTriggered"; | 462 purge_reason = "AggressivePurgeTriggered"; |
| 471 else | 463 else |
| 472 purge_reason = "ModeratePurgeTriggered"; | 464 purge_reason = "ModeratePurgeTriggered"; |
| 473 } | 465 } |
| 466 | |
| 467 // Return if no areas can be purged with the given option. | |
| 468 bool aggressively = purge_option == PURGE_AGGRESSIVE; | |
| 469 if (!aggressively && !initial_stats.inactive_area_count) { | |
| 470 return; | |
|
michaeln
2016/06/27 22:59:02
nit: you might be able to work this early return i
ssid
2016/06/27 23:09:29
Hm there are 2 cases where this helps.
1. When we
michaeln
2016/06/28 18:33:45
still lgtm, good point about only having one early
| |
| 471 } | |
| 472 for (const auto& it : namespaces_) | |
| 473 it.second->PurgeMemory(aggressively); | |
| 474 | |
| 475 // Track the size of cache purged. | |
| 474 size_t purged_size_kib = | 476 size_t purged_size_kib = |
| 475 (initial_stats.total_cache_size - | 477 (initial_stats.total_cache_size - |
| 476 GetTotalNamespaceStatistics(namespaces_).total_cache_size) / | 478 GetTotalNamespaceStatistics(namespaces_).total_cache_size) / |
| 477 1024; | 479 1024; |
| 478 std::string full_histogram_name = | 480 std::string full_histogram_name = |
| 479 std::string("LocalStorage.BrowserLocalStorageCachePurgedInKB.") + | 481 std::string("LocalStorage.BrowserLocalStorageCachePurgedInKB.") + |
| 480 purge_reason; | 482 purge_reason; |
| 481 base::HistogramBase* histogram = base::Histogram::FactoryGet( | 483 base::HistogramBase* histogram = base::Histogram::FactoryGet( |
| 482 full_histogram_name, 1, 100000, 50, | 484 full_histogram_name, 1, 100000, 50, |
| 483 base::HistogramBase::kUmaTargetedHistogramFlag); | 485 base::HistogramBase::kUmaTargetedHistogramFlag); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 if (!deletable_persistent_namespace_ids_.empty()) { | 581 if (!deletable_persistent_namespace_ids_.empty()) { |
| 580 task_runner_->PostDelayedTask( | 582 task_runner_->PostDelayedTask( |
| 581 FROM_HERE, base::Bind( | 583 FROM_HERE, base::Bind( |
| 582 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 584 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
| 583 this), | 585 this), |
| 584 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 586 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
| 585 } | 587 } |
| 586 } | 588 } |
| 587 | 589 |
| 588 } // namespace content | 590 } // namespace content |
| OLD | NEW |