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

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: 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 is_getting_eviction_origin_(false),
816 weak_factory_(this) { 817 weak_factory_(this) {
817 } 818 }
818 819
819 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { 820 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
820 LazyInitialize(); 821 LazyInitialize();
821 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); 822 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback);
822 get_usage_info->Start(); 823 get_usage_info->Start();
823 } 824 }
824 825
825 void QuotaManager::GetUsageAndQuotaForWebApps( 826 void QuotaManager::GetUsageAndQuotaForWebApps(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 919
919 void QuotaManager::SetUsageCacheEnabled(QuotaClient::ID client_id, 920 void QuotaManager::SetUsageCacheEnabled(QuotaClient::ID client_id,
920 const GURL& origin, 921 const GURL& origin,
921 StorageType type, 922 StorageType type,
922 bool enabled) { 923 bool enabled) {
923 LazyInitialize(); 924 LazyInitialize();
924 DCHECK(GetUsageTracker(type)); 925 DCHECK(GetUsageTracker(type));
925 GetUsageTracker(type)->SetUsageCacheEnabled(client_id, origin, enabled); 926 GetUsageTracker(type)->SetUsageCacheEnabled(client_id, origin, enabled);
926 } 927 }
927 928
929 void QuotaManager::SetQuotaEvictionPolicy(
930 StorageType type,
931 scoped_ptr<QuotaEvictionPolicy> policy) {
932 eviction_policy_map_.set(type, policy.Pass());
933 }
934
928 void QuotaManager::DeleteOriginData( 935 void QuotaManager::DeleteOriginData(
929 const GURL& origin, StorageType type, int quota_client_mask, 936 const GURL& origin, StorageType type, int quota_client_mask,
930 const StatusCallback& callback) { 937 const StatusCallback& callback) {
931 LazyInitialize(); 938 LazyInitialize();
932 939
933 if (origin.is_empty() || clients_.empty()) { 940 if (origin.is_empty() || clients_.empty()) {
934 callback.Run(kQuotaStatusOk); 941 callback.Run(kQuotaStatusOk);
935 return; 942 return;
936 } 943 }
937 944
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 LazyInitialize(); 1287 LazyInitialize();
1281 DCHECK(GetUsageTracker(type)); 1288 DCHECK(GetUsageTracker(type));
1282 GetUsageTracker(type)->GetCachedOrigins(origins); 1289 GetUsageTracker(type)->GetCachedOrigins(origins);
1283 } 1290 }
1284 1291
1285 void QuotaManager::NotifyStorageAccessedInternal( 1292 void QuotaManager::NotifyStorageAccessedInternal(
1286 QuotaClient::ID client_id, 1293 QuotaClient::ID client_id,
1287 const GURL& origin, StorageType type, 1294 const GURL& origin, StorageType type,
1288 base::Time accessed_time) { 1295 base::Time accessed_time) {
1289 LazyInitialize(); 1296 LazyInitialize();
1290 if (type == kStorageTypeTemporary && !lru_origin_callback_.is_null()) { 1297 if (type == kStorageTypeTemporary && is_getting_eviction_origin_) {
1291 // Record the accessed origins while GetLRUOrigin task is runing 1298 // Record the accessed origins while GetLRUOrigin task is runing
1292 // to filter out them from eviction. 1299 // to filter out them from eviction.
1293 access_notified_origins_.insert(origin); 1300 access_notified_origins_.insert(origin);
1294 } 1301 }
1295 1302
1296 if (db_disabled_) 1303 if (db_disabled_)
1297 return; 1304 return;
1298 PostTaskAndReplyWithResultForDBThread( 1305 PostTaskAndReplyWithResultForDBThread(
1299 FROM_HERE, 1306 FROM_HERE,
1300 base::Bind(&UpdateAccessTimeOnDBThread, origin, type, accessed_time), 1307 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", 1442 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins",
1436 num_origins); 1443 num_origins);
1437 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins", 1444 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins",
1438 protected_origins); 1445 protected_origins);
1439 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins", 1446 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins",
1440 unlimited_origins); 1447 unlimited_origins);
1441 } 1448 }
1442 1449
1443 void QuotaManager::GetEvictionOrigin(StorageType type, 1450 void QuotaManager::GetEvictionOrigin(StorageType type,
1444 const GetOriginCallback& callback) { 1451 const GetOriginCallback& callback) {
1445 GetLRUOrigin(type, callback); 1452 LazyInitialize();
1453 is_getting_eviction_origin_ = true;
1454
1455 GetOriginCallback did_get_origin_callback =
1456 base::Bind(&QuotaManager::DidGetEvictionOrigin,
1457 weak_factory_.GetWeakPtr(), callback);
1458
1459 auto eviction_policy = eviction_policy_map_.find(type);
1460 if (eviction_policy != eviction_policy_map_.end()) {
1461 eviction_policy->second->GetEvictionOrigin(
1462 special_storage_policy_,
1463 did_get_origin_callback);
1464 }
1465
1466 // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy.
1467 GetLRUOrigin(type, did_get_origin_callback);
1468 }
1469
1470 void QuotaManager::DidGetEvictionOrigin(const GetOriginCallback& callback,
1471 const GURL& origin) {
1472 callback.Run(origin);
1473
1474 is_getting_eviction_origin_ = false;
1446 } 1475 }
1447 1476
1448 void QuotaManager::EvictOriginData(const GURL& origin, 1477 void QuotaManager::EvictOriginData(const GURL& origin,
1449 StorageType type, 1478 StorageType type,
1450 const EvictOriginDataCallback& callback) { 1479 const EvictOriginDataCallback& callback) {
1451 DCHECK(io_thread_->BelongsToCurrentThread()); 1480 DCHECK(io_thread_->BelongsToCurrentThread());
1452 DCHECK_EQ(type, kStorageTypeTemporary); 1481 DCHECK_EQ(type, kStorageTypeTemporary);
1453 1482
1454 eviction_context_.evicted_origin = origin; 1483 eviction_context_.evicted_origin = origin;
1455 eviction_context_.evicted_type = type; 1484 eviction_context_.evicted_type = type;
(...skipping 23 matching lines...) Expand all
1479 LazyInitialize(); 1508 LazyInitialize();
1480 // This must not be called while there's an in-flight task. 1509 // This must not be called while there's an in-flight task.
1481 DCHECK(lru_origin_callback_.is_null()); 1510 DCHECK(lru_origin_callback_.is_null());
1482 lru_origin_callback_ = callback; 1511 lru_origin_callback_ = callback;
1483 if (db_disabled_) { 1512 if (db_disabled_) {
1484 lru_origin_callback_.Run(GURL()); 1513 lru_origin_callback_.Run(GURL());
1485 lru_origin_callback_.Reset(); 1514 lru_origin_callback_.Reset();
1486 return; 1515 return;
1487 } 1516 }
1488 1517
1518 // TODO(calamity): make all QuotaEvictionPolicies aware of these exceptions.
1489 std::set<GURL>* exceptions = new std::set<GURL>; 1519 std::set<GURL>* exceptions = new std::set<GURL>;
1490 for (std::map<GURL, int>::const_iterator p = origins_in_use_.begin(); 1520 for (std::map<GURL, int>::const_iterator p = origins_in_use_.begin();
1491 p != origins_in_use_.end(); 1521 p != origins_in_use_.end();
1492 ++p) { 1522 ++p) {
1493 if (p->second > 0) 1523 if (p->second > 0)
1494 exceptions->insert(p->first); 1524 exceptions->insert(p->first);
1495 } 1525 }
1496 for (std::map<GURL, int>::const_iterator p = origins_in_error_.begin(); 1526 for (std::map<GURL, int>::const_iterator p = origins_in_error_.begin();
1497 p != origins_in_error_.end(); 1527 p != origins_in_error_.end();
1498 ++p) { 1528 ++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 1655 // |database_|, therefore we can be sure that database_ is alive when this
1626 // task runs. 1656 // task runs.
1627 base::PostTaskAndReplyWithResult( 1657 base::PostTaskAndReplyWithResult(
1628 db_thread_.get(), 1658 db_thread_.get(),
1629 from_here, 1659 from_here,
1630 base::Bind(task, base::Unretained(database_.get())), 1660 base::Bind(task, base::Unretained(database_.get())),
1631 reply); 1661 reply);
1632 } 1662 }
1633 1663
1634 } // namespace storage 1664 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698