Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 QuotaDatabase* database) { | 134 QuotaDatabase* database) { |
| 135 DCHECK(database); | 135 DCHECK(database); |
| 136 database->GetQuotaConfigValue(QuotaDatabase::kTemporaryQuotaOverrideKey, | 136 database->GetQuotaConfigValue(QuotaDatabase::kTemporaryQuotaOverrideKey, |
| 137 temporary_quota_override); | 137 temporary_quota_override); |
| 138 database->GetQuotaConfigValue(QuotaDatabase::kDesiredAvailableSpaceKey, | 138 database->GetQuotaConfigValue(QuotaDatabase::kDesiredAvailableSpaceKey, |
| 139 desired_available_space); | 139 desired_available_space); |
| 140 return true; | 140 return true; |
| 141 } | 141 } |
| 142 | 142 |
| 143 bool GetLRUOriginOnDBThread(StorageType type, | 143 bool GetLRUOriginOnDBThread(StorageType type, |
| 144 std::set<GURL>* exceptions, | 144 const std::set<GURL>& exceptions, |
| 145 SpecialStoragePolicy* policy, | 145 SpecialStoragePolicy* policy, |
| 146 GURL* url, | 146 GURL* url, |
| 147 QuotaDatabase* database) { | 147 QuotaDatabase* database) { |
| 148 DCHECK(database); | 148 DCHECK(database); |
| 149 database->GetLRUOrigin(type, *exceptions, policy, url); | 149 database->GetLRUOrigin(type, exceptions, policy, url); |
| 150 return true; | 150 return true; |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool DeleteOriginInfoOnDBThread(const GURL& origin, | 153 bool DeleteOriginInfoOnDBThread(const GURL& origin, |
| 154 StorageType type, | 154 StorageType type, |
| 155 QuotaDatabase* database) { | 155 QuotaDatabase* database) { |
| 156 DCHECK(database); | 156 DCHECK(database); |
| 157 return database->DeleteOriginInfo(origin, type); | 157 return database->DeleteOriginInfo(origin, type); |
| 158 } | 158 } |
| 159 | 159 |
| (...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1451 LazyInitialize(); | 1451 LazyInitialize(); |
| 1452 is_getting_eviction_origin_ = true; | 1452 is_getting_eviction_origin_ = true; |
| 1453 | 1453 |
| 1454 GetOriginCallback did_get_origin_callback = | 1454 GetOriginCallback did_get_origin_callback = |
| 1455 base::Bind(&QuotaManager::DidGetEvictionOrigin, | 1455 base::Bind(&QuotaManager::DidGetEvictionOrigin, |
| 1456 weak_factory_.GetWeakPtr(), callback); | 1456 weak_factory_.GetWeakPtr(), callback); |
| 1457 | 1457 |
| 1458 auto eviction_policy = eviction_policy_map_.find(type); | 1458 auto eviction_policy = eviction_policy_map_.find(type); |
| 1459 if (eviction_policy != eviction_policy_map_.end()) { | 1459 if (eviction_policy != eviction_policy_map_.end()) { |
| 1460 eviction_policy->second->GetEvictionOrigin(special_storage_policy_, | 1460 eviction_policy->second->GetEvictionOrigin(special_storage_policy_, |
| 1461 GetEvictionOriginExceptions(), | |
| 1461 did_get_origin_callback); | 1462 did_get_origin_callback); |
| 1462 } | 1463 } |
| 1463 | 1464 |
| 1464 // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy. | 1465 // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy. |
| 1465 GetLRUOrigin(type, did_get_origin_callback); | 1466 GetLRUOrigin(type, did_get_origin_callback); |
| 1466 } | 1467 } |
| 1467 | 1468 |
| 1469 std::set<GURL> QuotaManager::GetEvictionOriginExceptions() { | |
| 1470 std::set<GURL> exceptions; | |
| 1471 for (const auto& p : origins_in_use_) { | |
| 1472 if (p.second > 0) | |
| 1473 exceptions.insert(p.first); | |
| 1474 } | |
| 1475 | |
| 1476 for (const auto& p : origins_in_error_) { | |
| 1477 if (p.second > QuotaManager::kThresholdOfErrorsToBeBlacklisted) | |
| 1478 exceptions.insert(p.first); | |
| 1479 } | |
|
raymes
2015/09/22 07:16:10
I'm confused a bit by this stuff - but I see you'v
calamity
2015/09/23 01:55:21
Good question. Okay, so, access_notified_origins_
| |
| 1480 | |
| 1481 return exceptions; | |
| 1482 } | |
| 1483 | |
| 1468 void QuotaManager::DidGetEvictionOrigin(const GetOriginCallback& callback, | 1484 void QuotaManager::DidGetEvictionOrigin(const GetOriginCallback& callback, |
| 1469 const GURL& origin) { | 1485 const GURL& origin) { |
| 1470 callback.Run(origin); | 1486 // Make sure the returned origin is (still) not in the origin_in_use_ set |
| 1487 // and has not been accessed since we posted the task. | |
| 1488 if (origins_in_use_.find(origin) != origins_in_use_.end() || | |
| 1489 access_notified_origins_.find(origin) != access_notified_origins_.end()) { | |
| 1490 callback.Run(GURL()); | |
| 1491 } else { | |
| 1492 callback.Run(origin); | |
| 1493 } | |
| 1494 access_notified_origins_.clear(); | |
| 1471 | 1495 |
| 1472 is_getting_eviction_origin_ = false; | 1496 is_getting_eviction_origin_ = false; |
| 1473 } | 1497 } |
| 1474 | 1498 |
| 1475 void QuotaManager::EvictOriginData(const GURL& origin, | 1499 void QuotaManager::EvictOriginData(const GURL& origin, |
| 1476 StorageType type, | 1500 StorageType type, |
| 1477 const EvictOriginDataCallback& callback) { | 1501 const EvictOriginDataCallback& callback) { |
| 1478 DCHECK(io_thread_->BelongsToCurrentThread()); | 1502 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1479 DCHECK_EQ(type, kStorageTypeTemporary); | 1503 DCHECK_EQ(type, kStorageTypeTemporary); |
| 1480 | 1504 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1506 LazyInitialize(); | 1530 LazyInitialize(); |
| 1507 // This must not be called while there's an in-flight task. | 1531 // This must not be called while there's an in-flight task. |
| 1508 DCHECK(lru_origin_callback_.is_null()); | 1532 DCHECK(lru_origin_callback_.is_null()); |
| 1509 lru_origin_callback_ = callback; | 1533 lru_origin_callback_ = callback; |
| 1510 if (db_disabled_) { | 1534 if (db_disabled_) { |
| 1511 lru_origin_callback_.Run(GURL()); | 1535 lru_origin_callback_.Run(GURL()); |
| 1512 lru_origin_callback_.Reset(); | 1536 lru_origin_callback_.Reset(); |
| 1513 return; | 1537 return; |
| 1514 } | 1538 } |
| 1515 | 1539 |
| 1516 // TODO(calamity): make all QuotaEvictionPolicies aware of these exceptions. | |
| 1517 std::set<GURL>* exceptions = new std::set<GURL>; | |
| 1518 for (std::map<GURL, int>::const_iterator p = origins_in_use_.begin(); | |
| 1519 p != origins_in_use_.end(); | |
| 1520 ++p) { | |
| 1521 if (p->second > 0) | |
| 1522 exceptions->insert(p->first); | |
| 1523 } | |
| 1524 for (std::map<GURL, int>::const_iterator p = origins_in_error_.begin(); | |
| 1525 p != origins_in_error_.end(); | |
| 1526 ++p) { | |
| 1527 if (p->second > QuotaManager::kThresholdOfErrorsToBeBlacklisted) | |
| 1528 exceptions->insert(p->first); | |
| 1529 } | |
| 1530 | |
| 1531 GURL* url = new GURL; | 1540 GURL* url = new GURL; |
| 1532 PostTaskAndReplyWithResultForDBThread( | 1541 PostTaskAndReplyWithResultForDBThread( |
| 1533 FROM_HERE, | 1542 FROM_HERE, |
| 1534 base::Bind(&GetLRUOriginOnDBThread, | 1543 base::Bind(&GetLRUOriginOnDBThread, type, GetEvictionOriginExceptions(), |
| 1535 type, | 1544 special_storage_policy_, base::Unretained(url)), |
| 1536 base::Owned(exceptions), | 1545 base::Bind(&QuotaManager::DidGetLRUOrigin, weak_factory_.GetWeakPtr(), |
| 1537 special_storage_policy_, | |
| 1538 base::Unretained(url)), | |
| 1539 base::Bind(&QuotaManager::DidGetLRUOrigin, | |
| 1540 weak_factory_.GetWeakPtr(), | |
| 1541 base::Owned(url))); | 1546 base::Owned(url))); |
| 1542 } | 1547 } |
| 1543 | 1548 |
| 1544 void QuotaManager::DidSetTemporaryGlobalOverrideQuota( | 1549 void QuotaManager::DidSetTemporaryGlobalOverrideQuota( |
| 1545 const QuotaCallback& callback, | 1550 const QuotaCallback& callback, |
| 1546 const int64* new_quota, | 1551 const int64* new_quota, |
| 1547 bool success) { | 1552 bool success) { |
| 1548 QuotaStatusCode status = kQuotaErrorInvalidAccess; | 1553 QuotaStatusCode status = kQuotaErrorInvalidAccess; |
| 1549 DidDatabaseWork(success); | 1554 DidDatabaseWork(success); |
| 1550 if (success) { | 1555 if (success) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1588 | 1593 |
| 1589 db_initialization_callbacks_.Run(); | 1594 db_initialization_callbacks_.Run(); |
| 1590 GetTemporaryGlobalQuota( | 1595 GetTemporaryGlobalQuota( |
| 1591 base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota, | 1596 base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota, |
| 1592 weak_factory_.GetWeakPtr())); | 1597 weak_factory_.GetWeakPtr())); |
| 1593 } | 1598 } |
| 1594 | 1599 |
| 1595 void QuotaManager::DidGetLRUOrigin(const GURL* origin, | 1600 void QuotaManager::DidGetLRUOrigin(const GURL* origin, |
| 1596 bool success) { | 1601 bool success) { |
| 1597 DidDatabaseWork(success); | 1602 DidDatabaseWork(success); |
| 1598 // Make sure the returned origin is (still) not in the origin_in_use_ set | 1603 |
| 1599 // and has not been accessed since we posted the task. | 1604 lru_origin_callback_.Run(*origin); |
| 1600 if (origins_in_use_.find(*origin) != origins_in_use_.end() || | |
| 1601 access_notified_origins_.find(*origin) != access_notified_origins_.end()) | |
| 1602 lru_origin_callback_.Run(GURL()); | |
| 1603 else | |
| 1604 lru_origin_callback_.Run(*origin); | |
| 1605 access_notified_origins_.clear(); | |
| 1606 lru_origin_callback_.Reset(); | 1605 lru_origin_callback_.Reset(); |
| 1607 } | 1606 } |
| 1608 | 1607 |
| 1609 void QuotaManager::DidGetInitialTemporaryGlobalQuota( | 1608 void QuotaManager::DidGetInitialTemporaryGlobalQuota( |
| 1610 QuotaStatusCode status, int64 quota_unused) { | 1609 QuotaStatusCode status, int64 quota_unused) { |
| 1611 if (eviction_disabled_) | 1610 if (eviction_disabled_) |
| 1612 return; | 1611 return; |
| 1613 | 1612 |
| 1614 std::set<GURL>* origins = new std::set<GURL>; | 1613 std::set<GURL>* origins = new std::set<GURL>; |
| 1615 temporary_usage_tracker_->GetCachedOrigins(origins); | 1614 temporary_usage_tracker_->GetCachedOrigins(origins); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1653 // |database_|, therefore we can be sure that database_ is alive when this | 1652 // |database_|, therefore we can be sure that database_ is alive when this |
| 1654 // task runs. | 1653 // task runs. |
| 1655 base::PostTaskAndReplyWithResult( | 1654 base::PostTaskAndReplyWithResult( |
| 1656 db_thread_.get(), | 1655 db_thread_.get(), |
| 1657 from_here, | 1656 from_here, |
| 1658 base::Bind(task, base::Unretained(database_.get())), | 1657 base::Bind(task, base::Unretained(database_.get())), |
| 1659 reply); | 1658 reply); |
| 1660 } | 1659 } |
| 1661 | 1660 |
| 1662 } // namespace storage | 1661 } // namespace storage |
| OLD | NEW |