Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(664)

Side by Side Diff: storage/browser/quota/quota_manager.cc

Issue 1343273003: Integrate SiteEngagementEvictionPolicy with QuotaManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add_eviction_policy
Patch Set: address comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "storage/browser/quota/quota_manager.h" 5 #include "storage/browser/quota/quota_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, 800 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread,
801 const scoped_refptr<base::SequencedTaskRunner>& db_thread, 801 const scoped_refptr<base::SequencedTaskRunner>& db_thread,
802 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy) 802 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy)
803 : is_incognito_(is_incognito), 803 : is_incognito_(is_incognito),
804 profile_path_(profile_path), 804 profile_path_(profile_path),
805 proxy_(new QuotaManagerProxy(this, io_thread)), 805 proxy_(new QuotaManagerProxy(this, io_thread)),
806 db_disabled_(false), 806 db_disabled_(false),
807 eviction_disabled_(false), 807 eviction_disabled_(false),
808 io_thread_(io_thread), 808 io_thread_(io_thread),
809 db_thread_(db_thread), 809 db_thread_(db_thread),
810 is_getting_eviction_origin_(false),
810 temporary_quota_initialized_(false), 811 temporary_quota_initialized_(false),
811 temporary_quota_override_(-1), 812 temporary_quota_override_(-1),
812 desired_available_space_(-1), 813 desired_available_space_(-1),
813 special_storage_policy_(special_storage_policy), 814 special_storage_policy_(special_storage_policy),
814 get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace), 815 get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace),
815 storage_monitor_(new StorageMonitor(this)), 816 storage_monitor_(new StorageMonitor(this)),
816 weak_factory_(this) { 817 weak_factory_(this) {}
817 }
818 818
819 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { 819 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
820 LazyInitialize(); 820 LazyInitialize();
821 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); 821 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback);
822 get_usage_info->Start(); 822 get_usage_info->Start();
823 } 823 }
824 824
825 void QuotaManager::GetUsageAndQuotaForWebApps( 825 void QuotaManager::GetUsageAndQuotaForWebApps(
826 const GURL& origin, 826 const GURL& origin,
827 StorageType type, 827 StorageType type,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 918
919 void QuotaManager::SetUsageCacheEnabled(QuotaClient::ID client_id, 919 void QuotaManager::SetUsageCacheEnabled(QuotaClient::ID client_id,
920 const GURL& origin, 920 const GURL& origin,
921 StorageType type, 921 StorageType type,
922 bool enabled) { 922 bool enabled) {
923 LazyInitialize(); 923 LazyInitialize();
924 DCHECK(GetUsageTracker(type)); 924 DCHECK(GetUsageTracker(type));
925 GetUsageTracker(type)->SetUsageCacheEnabled(client_id, origin, enabled); 925 GetUsageTracker(type)->SetUsageCacheEnabled(client_id, origin, enabled);
926 } 926 }
927 927
928 void QuotaManager::SetTemporaryStorageEvictionPolicy(
929 scoped_ptr<QuotaEvictionPolicy> policy) {
930 temporary_storage_eviction_policy_ = policy.Pass();
931 }
932
928 void QuotaManager::DeleteOriginData( 933 void QuotaManager::DeleteOriginData(
929 const GURL& origin, StorageType type, int quota_client_mask, 934 const GURL& origin, StorageType type, int quota_client_mask,
930 const StatusCallback& callback) { 935 const StatusCallback& callback) {
931 LazyInitialize(); 936 LazyInitialize();
932 937
933 if (origin.is_empty() || clients_.empty()) { 938 if (origin.is_empty() || clients_.empty()) {
934 callback.Run(kQuotaStatusOk); 939 callback.Run(kQuotaStatusOk);
935 return; 940 return;
936 } 941 }
937 942
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 LazyInitialize(); 1285 LazyInitialize();
1281 DCHECK(GetUsageTracker(type)); 1286 DCHECK(GetUsageTracker(type));
1282 GetUsageTracker(type)->GetCachedOrigins(origins); 1287 GetUsageTracker(type)->GetCachedOrigins(origins);
1283 } 1288 }
1284 1289
1285 void QuotaManager::NotifyStorageAccessedInternal( 1290 void QuotaManager::NotifyStorageAccessedInternal(
1286 QuotaClient::ID client_id, 1291 QuotaClient::ID client_id,
1287 const GURL& origin, StorageType type, 1292 const GURL& origin, StorageType type,
1288 base::Time accessed_time) { 1293 base::Time accessed_time) {
1289 LazyInitialize(); 1294 LazyInitialize();
1290 if (type == kStorageTypeTemporary && !lru_origin_callback_.is_null()) { 1295 if (type == kStorageTypeTemporary && is_getting_eviction_origin_) {
1291 // Record the accessed origins while GetLRUOrigin task is runing 1296 // Record the accessed origins while GetLRUOrigin task is runing
1292 // to filter out them from eviction. 1297 // to filter out them from eviction.
1293 access_notified_origins_.insert(origin); 1298 access_notified_origins_.insert(origin);
1294 } 1299 }
1295 1300
1296 if (db_disabled_) 1301 if (db_disabled_)
1297 return; 1302 return;
1298 PostTaskAndReplyWithResultForDBThread( 1303 PostTaskAndReplyWithResultForDBThread(
1299 FROM_HERE, 1304 FROM_HERE,
1300 base::Bind(&UpdateAccessTimeOnDBThread, origin, type, accessed_time), 1305 base::Bind(&UpdateAccessTimeOnDBThread, origin, type, accessed_time),
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 1439
1435 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins", 1440 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins",
1436 num_origins); 1441 num_origins);
1437 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins", 1442 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins",
1438 protected_origins); 1443 protected_origins);
1439 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins", 1444 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins",
1440 unlimited_origins); 1445 unlimited_origins);
1441 } 1446 }
1442 1447
1443 void QuotaManager::GetEvictionOrigin(StorageType type, 1448 void QuotaManager::GetEvictionOrigin(StorageType type,
1449 int64 global_quota,
1444 const GetOriginCallback& callback) { 1450 const GetOriginCallback& callback) {
1445 GetLRUOrigin(type, callback); 1451 LazyInitialize();
1452 // This must not be called while there's an in-flight task.
1453 DCHECK(!is_getting_eviction_origin_);
1454 is_getting_eviction_origin_ = true;
1455
1456 GetOriginCallback did_get_origin_callback =
1457 base::Bind(&QuotaManager::DidGetEvictionOrigin,
1458 weak_factory_.GetWeakPtr(), callback);
1459
1460 if (type == kStorageTypeTemporary && temporary_storage_eviction_policy_) {
1461 std::map<GURL, int64> usage_map;
1462 // The cached origins are populated by the prior call to
1463 // GetUsageAndQuotaForEviction().
1464 GetUsageTracker(kStorageTypeTemporary)->GetCachedOriginsUsage(&usage_map);
1465
1466 temporary_storage_eviction_policy_->GetEvictionOrigin(
1467 special_storage_policy_, usage_map, global_quota,
1468 did_get_origin_callback);
1469 return;
1470 }
1471
1472 // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy.
1473 GetLRUOrigin(type, did_get_origin_callback);
1474 }
1475
1476 void QuotaManager::DidGetEvictionOrigin(const GetOriginCallback& callback,
1477 const GURL& origin) {
1478 callback.Run(origin);
1479
1480 is_getting_eviction_origin_ = false;
1446 } 1481 }
1447 1482
1448 void QuotaManager::EvictOriginData(const GURL& origin, 1483 void QuotaManager::EvictOriginData(const GURL& origin,
1449 StorageType type, 1484 StorageType type,
1450 const EvictOriginDataCallback& callback) { 1485 const EvictOriginDataCallback& callback) {
1451 DCHECK(io_thread_->BelongsToCurrentThread()); 1486 DCHECK(io_thread_->BelongsToCurrentThread());
1452 DCHECK_EQ(type, kStorageTypeTemporary); 1487 DCHECK_EQ(type, kStorageTypeTemporary);
1453 1488
1454 eviction_context_.evicted_origin = origin; 1489 eviction_context_.evicted_origin = origin;
1455 eviction_context_.evicted_type = type; 1490 eviction_context_.evicted_type = type;
(...skipping 23 matching lines...) Expand all
1479 LazyInitialize(); 1514 LazyInitialize();
1480 // This must not be called while there's an in-flight task. 1515 // This must not be called while there's an in-flight task.
1481 DCHECK(lru_origin_callback_.is_null()); 1516 DCHECK(lru_origin_callback_.is_null());
1482 lru_origin_callback_ = callback; 1517 lru_origin_callback_ = callback;
1483 if (db_disabled_) { 1518 if (db_disabled_) {
1484 lru_origin_callback_.Run(GURL()); 1519 lru_origin_callback_.Run(GURL());
1485 lru_origin_callback_.Reset(); 1520 lru_origin_callback_.Reset();
1486 return; 1521 return;
1487 } 1522 }
1488 1523
1524 // TODO(calamity): make all QuotaEvictionPolicies aware of these exceptions.
1489 std::set<GURL>* exceptions = new std::set<GURL>; 1525 std::set<GURL>* exceptions = new std::set<GURL>;
1490 for (std::map<GURL, int>::const_iterator p = origins_in_use_.begin(); 1526 for (std::map<GURL, int>::const_iterator p = origins_in_use_.begin();
1491 p != origins_in_use_.end(); 1527 p != origins_in_use_.end();
1492 ++p) { 1528 ++p) {
1493 if (p->second > 0) 1529 if (p->second > 0)
1494 exceptions->insert(p->first); 1530 exceptions->insert(p->first);
1495 } 1531 }
1496 for (std::map<GURL, int>::const_iterator p = origins_in_error_.begin(); 1532 for (std::map<GURL, int>::const_iterator p = origins_in_error_.begin();
1497 p != origins_in_error_.end(); 1533 p != origins_in_error_.end();
1498 ++p) { 1534 ++p) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 // |database_|, therefore we can be sure that database_ is alive when this 1661 // |database_|, therefore we can be sure that database_ is alive when this
1626 // task runs. 1662 // task runs.
1627 base::PostTaskAndReplyWithResult( 1663 base::PostTaskAndReplyWithResult(
1628 db_thread_.get(), 1664 db_thread_.get(),
1629 from_here, 1665 from_here,
1630 base::Bind(task, base::Unretained(database_.get())), 1666 base::Bind(task, base::Unretained(database_.get())),
1631 reply); 1667 reply);
1632 } 1668 }
1633 1669
1634 } // namespace storage 1670 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/quota/quota_manager.h ('k') | storage/browser/quota/quota_temporary_storage_evictor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698