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

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: rebase Created 5 years, 3 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 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 temporary_quota_initialized_(false), 810 temporary_quota_initialized_(false),
811 temporary_quota_override_(-1), 811 temporary_quota_override_(-1),
812 desired_available_space_(-1), 812 desired_available_space_(-1),
813 special_storage_policy_(special_storage_policy), 813 special_storage_policy_(special_storage_policy),
814 get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace), 814 get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace),
815 storage_monitor_(new StorageMonitor(this)), 815 storage_monitor_(new StorageMonitor(this)),
816 weak_factory_(this) { 816 is_getting_eviction_origin_(false),
817 } 817 weak_factory_(this) {}
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::SetQuotaEvictionPolicy(
929 StorageType type,
930 scoped_ptr<QuotaEvictionPolicy> policy) {
931 eviction_policy_map_.set(type, policy.Pass());
932 }
933
928 void QuotaManager::DeleteOriginData( 934 void QuotaManager::DeleteOriginData(
929 const GURL& origin, StorageType type, int quota_client_mask, 935 const GURL& origin, StorageType type, int quota_client_mask,
930 const StatusCallback& callback) { 936 const StatusCallback& callback) {
931 LazyInitialize(); 937 LazyInitialize();
932 938
933 if (origin.is_empty() || clients_.empty()) { 939 if (origin.is_empty() || clients_.empty()) {
934 callback.Run(kQuotaStatusOk); 940 callback.Run(kQuotaStatusOk);
935 return; 941 return;
936 } 942 }
937 943
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 LazyInitialize(); 1286 LazyInitialize();
1281 DCHECK(GetUsageTracker(type)); 1287 DCHECK(GetUsageTracker(type));
1282 GetUsageTracker(type)->GetCachedOrigins(origins); 1288 GetUsageTracker(type)->GetCachedOrigins(origins);
1283 } 1289 }
1284 1290
1285 void QuotaManager::NotifyStorageAccessedInternal( 1291 void QuotaManager::NotifyStorageAccessedInternal(
1286 QuotaClient::ID client_id, 1292 QuotaClient::ID client_id,
1287 const GURL& origin, StorageType type, 1293 const GURL& origin, StorageType type,
1288 base::Time accessed_time) { 1294 base::Time accessed_time) {
1289 LazyInitialize(); 1295 LazyInitialize();
1290 if (type == kStorageTypeTemporary && !lru_origin_callback_.is_null()) { 1296 if (type == kStorageTypeTemporary && is_getting_eviction_origin_) {
1291 // Record the accessed origins while GetLRUOrigin task is runing 1297 // Record the accessed origins while GetLRUOrigin task is runing
1292 // to filter out them from eviction. 1298 // to filter out them from eviction.
1293 access_notified_origins_.insert(origin); 1299 access_notified_origins_.insert(origin);
1294 } 1300 }
1295 1301
1296 if (db_disabled_) 1302 if (db_disabled_)
1297 return; 1303 return;
1298 PostTaskAndReplyWithResultForDBThread( 1304 PostTaskAndReplyWithResultForDBThread(
1299 FROM_HERE, 1305 FROM_HERE,
1300 base::Bind(&UpdateAccessTimeOnDBThread, origin, type, accessed_time), 1306 base::Bind(&UpdateAccessTimeOnDBThread, origin, type, accessed_time),
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins", 1441 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins",
1436 num_origins); 1442 num_origins);
1437 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins", 1443 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins",
1438 protected_origins); 1444 protected_origins);
1439 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins", 1445 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins",
1440 unlimited_origins); 1446 unlimited_origins);
1441 } 1447 }
1442 1448
1443 void QuotaManager::GetEvictionOrigin(StorageType type, 1449 void QuotaManager::GetEvictionOrigin(StorageType type,
1444 const GetOriginCallback& callback) { 1450 const GetOriginCallback& callback) {
1445 GetLRUOrigin(type, callback); 1451 LazyInitialize();
1452 is_getting_eviction_origin_ = true;
raymes 2015/09/22 06:08:49 Should we dcheck this is false (as with lru_origin
calamity 2015/09/23 01:46:24 Done.
1453
1454 GetOriginCallback did_get_origin_callback =
1455 base::Bind(&QuotaManager::DidGetEvictionOrigin,
1456 weak_factory_.GetWeakPtr(), callback);
1457
1458 auto eviction_policy = eviction_policy_map_.find(type);
1459 if (eviction_policy != eviction_policy_map_.end()) {
1460 eviction_policy->second->GetEvictionOrigin(special_storage_policy_,
1461 did_get_origin_callback);
raymes 2015/09/22 06:08:49 Should this return here?
calamity 2015/09/23 01:46:24 Done. Good catch >_>
1462 }
1463
1464 // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy.
1465 GetLRUOrigin(type, did_get_origin_callback);
1466 }
1467
1468 void QuotaManager::DidGetEvictionOrigin(const GetOriginCallback& callback,
1469 const GURL& origin) {
1470 callback.Run(origin);
1471
1472 is_getting_eviction_origin_ = false;
1446 } 1473 }
1447 1474
1448 void QuotaManager::EvictOriginData(const GURL& origin, 1475 void QuotaManager::EvictOriginData(const GURL& origin,
1449 StorageType type, 1476 StorageType type,
1450 const EvictOriginDataCallback& callback) { 1477 const EvictOriginDataCallback& callback) {
1451 DCHECK(io_thread_->BelongsToCurrentThread()); 1478 DCHECK(io_thread_->BelongsToCurrentThread());
1452 DCHECK_EQ(type, kStorageTypeTemporary); 1479 DCHECK_EQ(type, kStorageTypeTemporary);
1453 1480
1454 eviction_context_.evicted_origin = origin; 1481 eviction_context_.evicted_origin = origin;
1455 eviction_context_.evicted_type = type; 1482 eviction_context_.evicted_type = type;
(...skipping 23 matching lines...) Expand all
1479 LazyInitialize(); 1506 LazyInitialize();
1480 // This must not be called while there's an in-flight task. 1507 // This must not be called while there's an in-flight task.
1481 DCHECK(lru_origin_callback_.is_null()); 1508 DCHECK(lru_origin_callback_.is_null());
1482 lru_origin_callback_ = callback; 1509 lru_origin_callback_ = callback;
1483 if (db_disabled_) { 1510 if (db_disabled_) {
1484 lru_origin_callback_.Run(GURL()); 1511 lru_origin_callback_.Run(GURL());
1485 lru_origin_callback_.Reset(); 1512 lru_origin_callback_.Reset();
1486 return; 1513 return;
1487 } 1514 }
1488 1515
1516 // TODO(calamity): make all QuotaEvictionPolicies aware of these exceptions.
1489 std::set<GURL>* exceptions = new std::set<GURL>; 1517 std::set<GURL>* exceptions = new std::set<GURL>;
1490 for (std::map<GURL, int>::const_iterator p = origins_in_use_.begin(); 1518 for (std::map<GURL, int>::const_iterator p = origins_in_use_.begin();
1491 p != origins_in_use_.end(); 1519 p != origins_in_use_.end();
1492 ++p) { 1520 ++p) {
1493 if (p->second > 0) 1521 if (p->second > 0)
1494 exceptions->insert(p->first); 1522 exceptions->insert(p->first);
1495 } 1523 }
1496 for (std::map<GURL, int>::const_iterator p = origins_in_error_.begin(); 1524 for (std::map<GURL, int>::const_iterator p = origins_in_error_.begin();
1497 p != origins_in_error_.end(); 1525 p != origins_in_error_.end();
1498 ++p) { 1526 ++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 1653 // |database_|, therefore we can be sure that database_ is alive when this
1626 // task runs. 1654 // task runs.
1627 base::PostTaskAndReplyWithResult( 1655 base::PostTaskAndReplyWithResult(
1628 db_thread_.get(), 1656 db_thread_.get(),
1629 from_here, 1657 from_here,
1630 base::Bind(task, base::Unretained(database_.get())), 1658 base::Bind(task, base::Unretained(database_.get())),
1631 reply); 1659 reply);
1632 } 1660 }
1633 1661
1634 } // namespace storage 1662 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698