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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 437 |
438 // Track the total localStorage cache size. | 438 // Track the total localStorage cache size. |
439 UMA_HISTOGRAM_CUSTOM_COUNTS("LocalStorage.BrowserLocalStorageCacheSizeInKB", | 439 UMA_HISTOGRAM_CUSTOM_COUNTS("LocalStorage.BrowserLocalStorageCacheSizeInKB", |
440 initial_stats.total_cache_size / 1024, 1, 100000, | 440 initial_stats.total_cache_size / 1024, 1, 100000, |
441 50); | 441 50); |
michaeln
2016/06/27 21:51:15
if (!stats.total_area_count)
return;
I think th
ssid
2016/06/27 22:00:37
Thanks for pointing out, i have moved this conditi
| |
442 | 442 |
443 const char* purge_reason = nullptr; | 443 const char* purge_reason = nullptr; |
444 if (purge_option == PURGE_IF_NEEDED) { | 444 if (purge_option == PURGE_IF_NEEDED) { |
445 // Purging is done based on the cache sizes without including the database | 445 // 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 | 446 // size since it can be expensive trying to estimate the sqlite usage for |
447 // all databases. For low end devices purge all inactive areas. | 447 // 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) | 448 if (initial_stats.total_cache_size > kMaxCacheSize) |
452 purge_reason = "SizeLimitExceeded"; | 449 purge_reason = "SizeLimitExceeded"; |
453 else if (initial_stats.total_area_count > kMaxStorageAreaCount) | 450 else if (initial_stats.total_area_count > kMaxStorageAreaCount) |
454 purge_reason = "AreaCountLimitExceeded"; | 451 purge_reason = "AreaCountLimitExceeded"; |
455 else if (is_low_end_device_) | 452 else if (is_low_end_device_) |
456 purge_reason = "InactiveOnLowEndDevice"; | 453 purge_reason = "InactiveOnLowEndDevice"; |
457 if (!purge_reason) | 454 if (!purge_reason) |
458 return; | 455 return; |
459 | 456 |
460 purge_option = PURGE_UNOPENED; | 457 purge_option = PURGE_UNOPENED; |
461 } | 458 } |
462 | 459 |
460 // Return if no areas can be purged with the given option. | |
463 bool aggressively = purge_option == PURGE_AGGRESSIVE; | 461 bool aggressively = purge_option == PURGE_AGGRESSIVE; |
462 if ((aggressively && !initial_stats.total_area_count) || | |
463 (!aggressively && !initial_stats.inactive_area_count)) { | |
464 return; | |
465 } | |
464 for (const auto& it : namespaces_) | 466 for (const auto& it : namespaces_) |
465 it.second->PurgeMemory(aggressively); | 467 it.second->PurgeMemory(aggressively); |
466 | 468 |
467 // Track the size of cache purged. | 469 // Track the size of cache purged. |
468 if (!purge_reason) { | 470 if (!purge_reason) { |
michaeln
2016/06/27 21:51:15
nit: it might be nice to set purge_reason in all c
ssid
2016/06/27 22:00:37
Done.
| |
469 if (purge_option == PURGE_AGGRESSIVE) | 471 if (aggressively) |
470 purge_reason = "AggressivePurgeTriggered"; | 472 purge_reason = "AggressivePurgeTriggered"; |
471 else | 473 else |
472 purge_reason = "ModeratePurgeTriggered"; | 474 purge_reason = "ModeratePurgeTriggered"; |
473 } | 475 } |
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.") + |
(...skipping 99 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 |