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

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

Issue 1354543002: Exclude in-use origins from storage evictions for all QuotaEvictionPolicies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hook_it_up_gooood
Patch Set: rebase summore 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 QuotaDatabase* database) { 135 QuotaDatabase* database) {
136 DCHECK(database); 136 DCHECK(database);
137 database->GetQuotaConfigValue(QuotaDatabase::kTemporaryQuotaOverrideKey, 137 database->GetQuotaConfigValue(QuotaDatabase::kTemporaryQuotaOverrideKey,
138 temporary_quota_override); 138 temporary_quota_override);
139 database->GetQuotaConfigValue(QuotaDatabase::kDesiredAvailableSpaceKey, 139 database->GetQuotaConfigValue(QuotaDatabase::kDesiredAvailableSpaceKey,
140 desired_available_space); 140 desired_available_space);
141 return true; 141 return true;
142 } 142 }
143 143
144 bool GetLRUOriginOnDBThread(StorageType type, 144 bool GetLRUOriginOnDBThread(StorageType type,
145 std::set<GURL>* exceptions, 145 const std::set<GURL>& exceptions,
146 SpecialStoragePolicy* policy, 146 SpecialStoragePolicy* policy,
147 GURL* url, 147 GURL* url,
148 QuotaDatabase* database) { 148 QuotaDatabase* database) {
149 DCHECK(database); 149 DCHECK(database);
150 database->GetLRUOrigin(type, *exceptions, policy, url); 150 database->GetLRUOrigin(type, exceptions, policy, url);
151 return true; 151 return true;
152 } 152 }
153 153
154 bool DeleteOriginInfoOnDBThread(const GURL& origin, 154 bool DeleteOriginInfoOnDBThread(const GURL& origin,
155 StorageType type, 155 StorageType type,
156 QuotaDatabase* database) { 156 QuotaDatabase* database) {
157 DCHECK(database); 157 DCHECK(database);
158 return database->DeleteOriginInfo(origin, type); 158 return database->DeleteOriginInfo(origin, type);
159 } 159 }
160 160
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 &unlimited_origins); 1469 &unlimited_origins);
1470 1470
1471 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins", 1471 UMA_HISTOGRAM_COUNTS("Quota.NumberOfPersistentStorageOrigins",
1472 num_origins); 1472 num_origins);
1473 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins", 1473 UMA_HISTOGRAM_COUNTS("Quota.NumberOfProtectedPersistentStorageOrigins",
1474 protected_origins); 1474 protected_origins);
1475 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins", 1475 UMA_HISTOGRAM_COUNTS("Quota.NumberOfUnlimitedPersistentStorageOrigins",
1476 unlimited_origins); 1476 unlimited_origins);
1477 } 1477 }
1478 1478
1479 std::set<GURL> QuotaManager::GetEvictionOriginExceptions() {
1480 std::set<GURL> exceptions;
1481 for (const auto& p : origins_in_use_) {
1482 if (p.second > 0)
1483 exceptions.insert(p.first);
1484 }
1485
1486 for (const auto& p : origins_in_error_) {
1487 if (p.second > QuotaManager::kThresholdOfErrorsToBeBlacklisted)
1488 exceptions.insert(p.first);
1489 }
1490
1491 return exceptions;
1492 }
1493
1494 void QuotaManager::DidGetEvictionOrigin(const GetOriginCallback& callback,
1495 const GURL& origin) {
1496 // Make sure the returned origin is (still) not in the origin_in_use_ set
1497 // and has not been accessed since we posted the task.
1498 if (origins_in_use_.find(origin) != origins_in_use_.end() ||
1499 access_notified_origins_.find(origin) != access_notified_origins_.end()) {
michaeln 2015/10/21 00:56:13 could also use ContainsKey() for these tests
calamity 2015/10/21 04:27:09 Done.
1500 callback.Run(GURL());
1501 } else {
1502 callback.Run(origin);
1503 }
1504 access_notified_origins_.clear();
1505
1506 is_getting_eviction_origin_ = false;
1507 }
1508
1479 void QuotaManager::GetEvictionOrigin(StorageType type, 1509 void QuotaManager::GetEvictionOrigin(StorageType type,
1480 int64 global_quota, 1510 int64 global_quota,
1481 const GetOriginCallback& callback) { 1511 const GetOriginCallback& callback) {
1482 LazyInitialize(); 1512 LazyInitialize();
1483 // This must not be called while there's an in-flight task. 1513 // This must not be called while there's an in-flight task.
1484 DCHECK(!is_getting_eviction_origin_); 1514 DCHECK(!is_getting_eviction_origin_);
1485 is_getting_eviction_origin_ = true; 1515 is_getting_eviction_origin_ = true;
1486 1516
1487 GetOriginCallback did_get_origin_callback = 1517 GetOriginCallback did_get_origin_callback =
1488 base::Bind(&QuotaManager::DidGetEvictionOrigin, 1518 base::Bind(&QuotaManager::DidGetEvictionOrigin,
1489 weak_factory_.GetWeakPtr(), callback); 1519 weak_factory_.GetWeakPtr(), callback);
1490 1520
1491 if (type == kStorageTypeTemporary && temporary_storage_eviction_policy_) { 1521 if (type == kStorageTypeTemporary && temporary_storage_eviction_policy_) {
1492 std::map<GURL, int64> usage_map; 1522 std::map<GURL, int64> usage_map;
1493 // The cached origins are populated by the prior call to 1523 // The cached origins are populated by the prior call to
1494 // GetUsageAndQuotaForEviction(). 1524 // GetUsageAndQuotaForEviction().
1495 GetUsageTracker(kStorageTypeTemporary)->GetCachedOriginsUsage(&usage_map); 1525 GetUsageTracker(kStorageTypeTemporary)->GetCachedOriginsUsage(&usage_map);
1496 1526
1497 temporary_storage_eviction_policy_->GetEvictionOrigin( 1527 temporary_storage_eviction_policy_->GetEvictionOrigin(
1498 special_storage_policy_, usage_map, global_quota, 1528 special_storage_policy_, GetEvictionOriginExceptions(), usage_map,
1499 did_get_origin_callback); 1529 global_quota, did_get_origin_callback);
1530
1500 return; 1531 return;
1501 } 1532 }
1502 1533
1503 // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy. 1534 // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy.
1504 GetLRUOrigin(type, did_get_origin_callback); 1535 GetLRUOrigin(type, did_get_origin_callback);
1505 } 1536 }
1506 1537
1507 void QuotaManager::DidGetEvictionOrigin(const GetOriginCallback& callback,
1508 const GURL& origin) {
1509 callback.Run(origin);
1510
1511 is_getting_eviction_origin_ = false;
1512 }
1513
1514 void QuotaManager::EvictOriginData(const GURL& origin, 1538 void QuotaManager::EvictOriginData(const GURL& origin,
1515 StorageType type, 1539 StorageType type,
1516 const EvictOriginDataCallback& callback) { 1540 const EvictOriginDataCallback& callback) {
1517 DCHECK(io_thread_->BelongsToCurrentThread()); 1541 DCHECK(io_thread_->BelongsToCurrentThread());
1518 DCHECK_EQ(type, kStorageTypeTemporary); 1542 DCHECK_EQ(type, kStorageTypeTemporary);
1519 1543
1520 eviction_context_.evicted_origin = origin; 1544 eviction_context_.evicted_origin = origin;
1521 eviction_context_.evicted_type = type; 1545 eviction_context_.evicted_type = type;
1522 eviction_context_.evict_origin_data_callback = callback; 1546 eviction_context_.evict_origin_data_callback = callback;
1523 1547
(...skipping 24 matching lines...) Expand all
1548 LazyInitialize(); 1572 LazyInitialize();
1549 // This must not be called while there's an in-flight task. 1573 // This must not be called while there's an in-flight task.
1550 DCHECK(lru_origin_callback_.is_null()); 1574 DCHECK(lru_origin_callback_.is_null());
1551 lru_origin_callback_ = callback; 1575 lru_origin_callback_ = callback;
1552 if (db_disabled_) { 1576 if (db_disabled_) {
1553 lru_origin_callback_.Run(GURL()); 1577 lru_origin_callback_.Run(GURL());
1554 lru_origin_callback_.Reset(); 1578 lru_origin_callback_.Reset();
1555 return; 1579 return;
1556 } 1580 }
1557 1581
1558 // TODO(calamity): make all QuotaEvictionPolicies aware of these exceptions.
1559 std::set<GURL>* exceptions = new std::set<GURL>;
1560 for (std::map<GURL, int>::const_iterator p = origins_in_use_.begin();
1561 p != origins_in_use_.end();
1562 ++p) {
1563 if (p->second > 0)
1564 exceptions->insert(p->first);
1565 }
1566 for (std::map<GURL, int>::const_iterator p = origins_in_error_.begin();
1567 p != origins_in_error_.end();
1568 ++p) {
1569 if (p->second > QuotaManager::kThresholdOfErrorsToBeBlacklisted)
1570 exceptions->insert(p->first);
1571 }
1572
1573 GURL* url = new GURL; 1582 GURL* url = new GURL;
1574 PostTaskAndReplyWithResultForDBThread( 1583 PostTaskAndReplyWithResultForDBThread(
1575 FROM_HERE, 1584 FROM_HERE,
1576 base::Bind(&GetLRUOriginOnDBThread, 1585 base::Bind(&GetLRUOriginOnDBThread, type, GetEvictionOriginExceptions(),
1577 type, 1586 special_storage_policy_, base::Unretained(url)),
1578 base::Owned(exceptions), 1587 base::Bind(&QuotaManager::DidGetLRUOrigin, weak_factory_.GetWeakPtr(),
1579 special_storage_policy_,
1580 base::Unretained(url)),
1581 base::Bind(&QuotaManager::DidGetLRUOrigin,
1582 weak_factory_.GetWeakPtr(),
1583 base::Owned(url))); 1588 base::Owned(url)));
1584 } 1589 }
1585 1590
1586 void QuotaManager::DidSetTemporaryGlobalOverrideQuota( 1591 void QuotaManager::DidSetTemporaryGlobalOverrideQuota(
1587 const QuotaCallback& callback, 1592 const QuotaCallback& callback,
1588 const int64* new_quota, 1593 const int64* new_quota,
1589 bool success) { 1594 bool success) {
1590 QuotaStatusCode status = kQuotaErrorInvalidAccess; 1595 QuotaStatusCode status = kQuotaErrorInvalidAccess;
1591 DidDatabaseWork(success); 1596 DidDatabaseWork(success);
1592 if (success) { 1597 if (success) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 1635
1631 db_initialization_callbacks_.Run(); 1636 db_initialization_callbacks_.Run();
1632 GetTemporaryGlobalQuota( 1637 GetTemporaryGlobalQuota(
1633 base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota, 1638 base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota,
1634 weak_factory_.GetWeakPtr())); 1639 weak_factory_.GetWeakPtr()));
1635 } 1640 }
1636 1641
1637 void QuotaManager::DidGetLRUOrigin(const GURL* origin, 1642 void QuotaManager::DidGetLRUOrigin(const GURL* origin,
1638 bool success) { 1643 bool success) {
1639 DidDatabaseWork(success); 1644 DidDatabaseWork(success);
1640 // Make sure the returned origin is (still) not in the origin_in_use_ set 1645
1641 // and has not been accessed since we posted the task. 1646 lru_origin_callback_.Run(*origin);
1642 if (origins_in_use_.find(*origin) != origins_in_use_.end() ||
1643 access_notified_origins_.find(*origin) != access_notified_origins_.end())
1644 lru_origin_callback_.Run(GURL());
1645 else
1646 lru_origin_callback_.Run(*origin);
1647 access_notified_origins_.clear();
1648 lru_origin_callback_.Reset(); 1647 lru_origin_callback_.Reset();
1649 } 1648 }
1650 1649
1651 void QuotaManager::DidGetInitialTemporaryGlobalQuota( 1650 void QuotaManager::DidGetInitialTemporaryGlobalQuota(
1652 QuotaStatusCode status, int64 quota_unused) { 1651 QuotaStatusCode status, int64 quota_unused) {
1653 if (eviction_disabled_) 1652 if (eviction_disabled_)
1654 return; 1653 return;
1655 1654
1656 std::set<GURL>* origins = new std::set<GURL>; 1655 std::set<GURL>* origins = new std::set<GURL>;
1657 temporary_usage_tracker_->GetCachedOrigins(origins); 1656 temporary_usage_tracker_->GetCachedOrigins(origins);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 // |database_|, therefore we can be sure that database_ is alive when this 1698 // |database_|, therefore we can be sure that database_ is alive when this
1700 // task runs. 1699 // task runs.
1701 base::PostTaskAndReplyWithResult( 1700 base::PostTaskAndReplyWithResult(
1702 db_thread_.get(), 1701 db_thread_.get(),
1703 from_here, 1702 from_here,
1704 base::Bind(task, base::Unretained(database_.get())), 1703 base::Bind(task, base::Unretained(database_.get())),
1705 reply); 1704 reply);
1706 } 1705 }
1707 1706
1708 } // namespace storage 1707 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698