diff options
-rw-r--r-- | chrome/browser/engagement/site_engagement_eviction_policy.cc | 16 | ||||
-rw-r--r-- | chrome/browser/engagement/site_engagement_eviction_policy.h | 6 | ||||
-rw-r--r-- | chrome/browser/engagement/site_engagement_eviction_policy_unittest.cc | 11 | ||||
-rw-r--r-- | content/browser/quota/quota_manager_unittest.cc | 111 | ||||
-rw-r--r-- | content/browser/quota/quota_temporary_storage_evictor_unittest.cc | 1 | ||||
-rw-r--r-- | storage/browser/quota/client_usage_tracker.cc | 9 | ||||
-rw-r--r-- | storage/browser/quota/client_usage_tracker.h | 3 | ||||
-rw-r--r-- | storage/browser/quota/quota_manager.cc | 44 | ||||
-rw-r--r-- | storage/browser/quota/quota_manager.h | 20 | ||||
-rw-r--r-- | storage/browser/quota/quota_temporary_storage_evictor.cc | 2 | ||||
-rw-r--r-- | storage/browser/quota/usage_tracker.cc | 8 | ||||
-rw-r--r-- | storage/browser/quota/usage_tracker.h | 1 |
12 files changed, 171 insertions, 61 deletions
diff --git a/chrome/browser/engagement/site_engagement_eviction_policy.cc b/chrome/browser/engagement/site_engagement_eviction_policy.cc index ba7a885..79ebe1f 100644 --- a/chrome/browser/engagement/site_engagement_eviction_policy.cc +++ b/chrome/browser/engagement/site_engagement_eviction_policy.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/barrier_closure.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/engagement/site_engagement_eviction_policy.h" #include "chrome/browser/engagement/site_engagement_service.h" @@ -64,6 +63,7 @@ GURL DoCalculateEvictionOrigin( origin_to_evict = origin; } } + return origin_to_evict; } @@ -73,16 +73,18 @@ GURL GetSiteEngagementEvictionOriginOnUIThread( const std::map<GURL, int64>& usage_map, int64 global_quota) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + Profile* profile = Profile::FromBrowserContext(browser_context); - SiteEngagementService* service = + SiteEngagementScoreProvider* score_provider = g_browser_process->profile_manager()->IsValidProfile(profile) ? SiteEngagementService::Get(profile) : nullptr; - if (!service) + + if (!score_provider) return GURL(); - return DoCalculateEvictionOrigin(special_storage_policy, service, usage_map, - global_quota); + return DoCalculateEvictionOrigin(special_storage_policy, score_provider, + usage_map, global_quota); } } // namespace @@ -98,6 +100,8 @@ void SiteEngagementEvictionPolicy::GetEvictionOrigin( const std::map<GURL, int64>& usage_map, int64 global_quota, const storage::GetOriginCallback& callback) { + DCHECK_CURRENTLY_ON(content::BrowserThread::IO); + content::BrowserThread::PostTaskAndReplyWithResult( content::BrowserThread::UI, FROM_HERE, base::Bind(&GetSiteEngagementEvictionOriginOnUIThread, @@ -107,7 +111,7 @@ void SiteEngagementEvictionPolicy::GetEvictionOrigin( } // static -GURL SiteEngagementEvictionPolicy::CalculateEvictionOrigin( +GURL SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, SiteEngagementScoreProvider* score_provider, const std::map<GURL, int64>& usage_map, diff --git a/chrome/browser/engagement/site_engagement_eviction_policy.h b/chrome/browser/engagement/site_engagement_eviction_policy.h index 470b0ec..60c8768 100644 --- a/chrome/browser/engagement/site_engagement_eviction_policy.h +++ b/chrome/browser/engagement/site_engagement_eviction_policy.h @@ -23,7 +23,7 @@ class SiteEngagementEvictionPolicy : public storage::QuotaEvictionPolicy { public: explicit SiteEngagementEvictionPolicy( content::BrowserContext* browser_context); - virtual ~SiteEngagementEvictionPolicy(); + ~SiteEngagementEvictionPolicy() override; // Overridden from storage::QuotaEvictionPolicy: void GetEvictionOrigin(const scoped_refptr<storage::SpecialStoragePolicy>& @@ -35,14 +35,14 @@ class SiteEngagementEvictionPolicy : public storage::QuotaEvictionPolicy { private: friend class SiteEngagementEvictionPolicyTest; - static GURL CalculateEvictionOrigin( + static GURL CalculateEvictionOriginForTests( const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy, SiteEngagementScoreProvider* score_provider, const std::map<GURL, int64>& usage_map, int64 global_quota); - content::BrowserContext* browser_context_; + content::BrowserContext* const browser_context_; DISALLOW_COPY_AND_ASSIGN(SiteEngagementEvictionPolicy); }; diff --git a/chrome/browser/engagement/site_engagement_eviction_policy_unittest.cc b/chrome/browser/engagement/site_engagement_eviction_policy_unittest.cc index 733c5aa..19c948e 100644 --- a/chrome/browser/engagement/site_engagement_eviction_policy_unittest.cc +++ b/chrome/browser/engagement/site_engagement_eviction_policy_unittest.cc @@ -2,9 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/files/scoped_temp_dir.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "base/run_loop.h" +#include "base/thread_task_runner_handle.h" #include "chrome/browser/engagement/site_engagement_eviction_policy.h" #include "chrome/browser/engagement/site_engagement_service.h" #include "content/public/test/mock_special_storage_policy.h" +#include "content/public/test/mock_storage_client.h" +#include "content/public/test/test_browser_thread_bundle.h" +#include "storage/browser/quota/quota_manager.h" +#include "storage/browser/quota/quota_manager_proxy.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -49,7 +58,7 @@ class SiteEngagementEvictionPolicyTest : public testing::Test { ~SiteEngagementEvictionPolicyTest() override {} GURL CalculateEvictionOrigin(const std::map<GURL, int64>& usage) { - return SiteEngagementEvictionPolicy::CalculateEvictionOrigin( + return SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( storage_policy_, score_provider_.get(), usage, kGlobalQuota); } diff --git a/content/browser/quota/quota_manager_unittest.cc b/content/browser/quota/quota_manager_unittest.cc index 39c2315..56cfba4 100644 --- a/content/browser/quota/quota_manager_unittest.cc +++ b/content/browser/quota/quota_manager_unittest.cc @@ -58,11 +58,28 @@ const int64 kAvailableSpaceForApp = 13377331U; const int64 kMinimumPreserveForSystem = QuotaManager::kMinimumPreserveForSystem; const int kPerHostTemporaryPortion = QuotaManager::kPerHostTemporaryPortion; +const GURL kTestEvictionOrigin = GURL("http://test.eviction.policy/result"); + // Returns a deterministic value for the amount of available disk space. int64 GetAvailableDiskSpaceForTest(const base::FilePath&) { return kAvailableSpaceForApp + kMinimumPreserveForSystem; } +class TestEvictionPolicy : public storage::QuotaEvictionPolicy { + public: + TestEvictionPolicy() {} + ~TestEvictionPolicy() override {} + + // Overridden from storage::QuotaEvictionPolicy: + void GetEvictionOrigin(const scoped_refptr<storage::SpecialStoragePolicy>& + special_storage_policy, + const std::map<GURL, int64>& usage_map, + int64 global_quota, + const storage::GetOriginCallback& callback) override { + callback.Run(kTestEvictionOrigin); + } +}; + } // namespace class QuotaManagerTest : public testing::Test { @@ -277,12 +294,13 @@ class QuotaManagerTest : public testing::Test { quota_manager_->DeleteOriginFromDatabase(origin, type); } - void GetLRUOrigin(StorageType type) { - lru_origin_ = GURL(); - quota_manager_->GetLRUOrigin( - type, - base::Bind(&QuotaManagerTest::DidGetLRUOrigin, - weak_factory_.GetWeakPtr())); + void GetEvictionOrigin(StorageType type) { + eviction_origin_ = GURL(); + // The quota manager's default eviction policy is to use an LRU eviction + // policy. + quota_manager_->GetEvictionOrigin( + type, 0, base::Bind(&QuotaManagerTest::DidGetEvictionOrigin, + weak_factory_.GetWeakPtr())); } void NotifyOriginInUse(const GURL& origin) { @@ -366,8 +384,8 @@ class QuotaManagerTest : public testing::Test { available_space_ = usage_and_quota.available_disk_space; } - void DidGetLRUOrigin(const GURL& origin) { - lru_origin_ = origin; + void DidGetEvictionOrigin(const GURL& origin) { + eviction_origin_ = origin; } void DidGetModifiedOrigins(const std::set<GURL>& origins, StorageType type) { @@ -408,7 +426,7 @@ class QuotaManagerTest : public testing::Test { int64 unlimited_usage() const { return unlimited_usage_; } int64 quota() const { return quota_; } int64 available_space() const { return available_space_; } - const GURL& lru_origin() const { return lru_origin_; } + const GURL& eviction_origin() const { return eviction_origin_; } const std::set<GURL>& modified_origins() const { return modified_origins_; } StorageType modified_origins_type() const { return modified_origins_type_; } const QuotaTableEntries& quota_entries() const { return quota_entries_; } @@ -438,7 +456,7 @@ class QuotaManagerTest : public testing::Test { int64 unlimited_usage_; int64 quota_; int64 available_space_; - GURL lru_origin_; + GURL eviction_origin_; std::set<GURL> modified_origins_; StorageType modified_origins_type_; QuotaTableEntries quota_entries_; @@ -1263,6 +1281,15 @@ TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { EXPECT_LE(0, available_space()); } +TEST_F(QuotaManagerTest, SetTemporaryStorageEvictionPolicy) { + quota_manager()->SetTemporaryStorageEvictionPolicy( + make_scoped_ptr(new TestEvictionPolicy)); + + GetEvictionOrigin(kTemp); + base::RunLoop().RunUntilIdle(); + EXPECT_EQ(kTestEvictionOrigin, eviction_origin()); +} + TEST_F(QuotaManagerTest, EvictOriginData) { static const MockOriginData kData1[] = { { "http://foo.com/", kTemp, 1 }, @@ -1387,19 +1414,19 @@ TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) { EXPECT_TRUE(found_origin_in_database); for (size_t i = 0; i < kNumberOfTemporaryOrigins - 1; ++i) { - GetLRUOrigin(kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_FALSE(lru_origin().is_empty()); + EXPECT_FALSE(eviction_origin().is_empty()); // The origin "http://foo.com/" should not be in the LRU list. - EXPECT_NE(std::string("http://foo.com/"), lru_origin().spec()); - DeleteOriginFromDatabase(lru_origin(), kTemp); + EXPECT_NE(std::string("http://foo.com/"), eviction_origin().spec()); + DeleteOriginFromDatabase(eviction_origin(), kTemp); base::RunLoop().RunUntilIdle(); } // Now the LRU list must be empty. - GetLRUOrigin(kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_TRUE(lru_origin().is_empty()); + EXPECT_TRUE(eviction_origin().is_empty()); // Deleting origins from the database should not affect the results of the // following checks. @@ -1728,31 +1755,31 @@ TEST_F(QuotaManagerTest, NotifyAndLRUOrigin) { RegisterClient(client); GURL origin; - GetLRUOrigin(kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_TRUE(lru_origin().is_empty()); + EXPECT_TRUE(eviction_origin().is_empty()); NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp); - GetLRUOrigin(kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_EQ("http://a.com/", lru_origin().spec()); + EXPECT_EQ("http://a.com/", eviction_origin().spec()); NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm); NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp); NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); - GetLRUOrigin(kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_EQ("http://a.com/", lru_origin().spec()); + EXPECT_EQ("http://a.com/", eviction_origin().spec()); - DeleteOriginFromDatabase(lru_origin(), kTemp); - GetLRUOrigin(kTemp); + DeleteOriginFromDatabase(eviction_origin(), kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_EQ("https://a.com/", lru_origin().spec()); + EXPECT_EQ("https://a.com/", eviction_origin().spec()); - DeleteOriginFromDatabase(lru_origin(), kTemp); - GetLRUOrigin(kTemp); + DeleteOriginFromDatabase(eviction_origin(), kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_EQ("http://c.com/", lru_origin().spec()); + EXPECT_EQ("http://c.com/", eviction_origin().spec()); } TEST_F(QuotaManagerTest, GetLRUOriginWithOriginInUse) { @@ -1768,46 +1795,46 @@ TEST_F(QuotaManagerTest, GetLRUOriginWithOriginInUse) { RegisterClient(client); GURL origin; - GetLRUOrigin(kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_TRUE(lru_origin().is_empty()); + EXPECT_TRUE(eviction_origin().is_empty()); NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp); NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm); NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp); NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); - GetLRUOrigin(kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_EQ("http://a.com/", lru_origin().spec()); + EXPECT_EQ("http://a.com/", eviction_origin().spec()); // Notify origin http://a.com is in use. NotifyOriginInUse(GURL("http://a.com/")); - GetLRUOrigin(kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_EQ("https://a.com/", lru_origin().spec()); + EXPECT_EQ("https://a.com/", eviction_origin().spec()); - // Notify origin https://a.com is in use while GetLRUOrigin is running. - GetLRUOrigin(kTemp); + // Notify origin https://a.com is in use while GetEvictionOrigin is running. + GetEvictionOrigin(kTemp); NotifyOriginInUse(GURL("https://a.com/")); base::RunLoop().RunUntilIdle(); // Post-filtering must have excluded the returned origin, so we will // see empty result here. - EXPECT_TRUE(lru_origin().is_empty()); + EXPECT_TRUE(eviction_origin().is_empty()); - // Notify access for http://c.com while GetLRUOrigin is running. - GetLRUOrigin(kTemp); + // Notify access for http://c.com while GetEvictionOrigin is running. + GetEvictionOrigin(kTemp); NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); base::RunLoop().RunUntilIdle(); // Post-filtering must have excluded the returned origin, so we will // see empty result here. - EXPECT_TRUE(lru_origin().is_empty()); + EXPECT_TRUE(eviction_origin().is_empty()); NotifyOriginNoLongerInUse(GURL("http://a.com/")); NotifyOriginNoLongerInUse(GURL("https://a.com/")); - GetLRUOrigin(kTemp); + GetEvictionOrigin(kTemp); base::RunLoop().RunUntilIdle(); - EXPECT_EQ("http://a.com/", lru_origin().spec()); + EXPECT_EQ("http://a.com/", eviction_origin().spec()); } TEST_F(QuotaManagerTest, GetOriginsModifiedSince) { diff --git a/content/browser/quota/quota_temporary_storage_evictor_unittest.cc b/content/browser/quota/quota_temporary_storage_evictor_unittest.cc index 2d63362..d386a53 100644 --- a/content/browser/quota/quota_temporary_storage_evictor_unittest.cc +++ b/content/browser/quota/quota_temporary_storage_evictor_unittest.cc @@ -60,6 +60,7 @@ class MockQuotaEvictionHandler : public storage::QuotaEvictionHandler { } void GetEvictionOrigin(StorageType type, + int64 global_quota, const storage::GetOriginCallback& callback) override { if (origin_order_.empty()) callback.Run(GURL()); diff --git a/storage/browser/quota/client_usage_tracker.cc b/storage/browser/quota/client_usage_tracker.cc index 968b351..0b11bd1 100644 --- a/storage/browser/quota/client_usage_tracker.cc +++ b/storage/browser/quota/client_usage_tracker.cc @@ -173,6 +173,15 @@ void ClientUsageTracker::GetCachedHostsUsage( } } +void ClientUsageTracker::GetCachedOriginsUsage( + std::map<GURL, int64>* origin_usage) const { + DCHECK(origin_usage); + for (const auto& host_and_usage_map : cached_usage_by_host_) { + for (const auto& origin_and_usage : host_and_usage_map.second) + (*origin_usage)[origin_and_usage.first] += origin_and_usage.second; + } +} + void ClientUsageTracker::GetCachedOrigins(std::set<GURL>* origins) const { DCHECK(origins); for (const auto& host_and_usage_map : cached_usage_by_host_) { diff --git a/storage/browser/quota/client_usage_tracker.h b/storage/browser/quota/client_usage_tracker.h index 1c07dc8..0505fae 100644 --- a/storage/browser/quota/client_usage_tracker.h +++ b/storage/browser/quota/client_usage_tracker.h @@ -51,9 +51,8 @@ class ClientUsageTracker : public SpecialStoragePolicy::Observer, void GetHostUsage(const std::string& host, const UsageCallback& callback); void UpdateUsageCache(const GURL& origin, int64 delta); void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; + void GetCachedOriginsUsage(std::map<GURL, int64>* origin_usage) const; void GetCachedOrigins(std::set<GURL>* origins) const; - int64 GetCachedOriginsUsage(const std::set<GURL>& origins, - std::vector<GURL>* origins_not_in_cache); bool IsUsageCacheEnabledForOrigin(const GURL& origin) const; void SetUsageCacheEnabled(const GURL& origin, bool enabled); diff --git a/storage/browser/quota/quota_manager.cc b/storage/browser/quota/quota_manager.cc index 674b1ec..c2ccb26 100644 --- a/storage/browser/quota/quota_manager.cc +++ b/storage/browser/quota/quota_manager.cc @@ -836,14 +836,14 @@ QuotaManager::QuotaManager( eviction_disabled_(false), io_thread_(io_thread), db_thread_(db_thread), + is_getting_eviction_origin_(false), temporary_quota_initialized_(false), temporary_quota_override_(-1), desired_available_space_(-1), special_storage_policy_(special_storage_policy), get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace), storage_monitor_(new StorageMonitor(this)), - weak_factory_(this) { -} + weak_factory_(this) {} void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { LazyInitialize(); @@ -954,6 +954,11 @@ void QuotaManager::SetUsageCacheEnabled(QuotaClient::ID client_id, GetUsageTracker(type)->SetUsageCacheEnabled(client_id, origin, enabled); } +void QuotaManager::SetTemporaryStorageEvictionPolicy( + scoped_ptr<QuotaEvictionPolicy> policy) { + temporary_storage_eviction_policy_ = policy.Pass(); +} + void QuotaManager::DeleteOriginData( const GURL& origin, StorageType type, int quota_client_mask, const StatusCallback& callback) { @@ -1318,7 +1323,7 @@ void QuotaManager::NotifyStorageAccessedInternal( const GURL& origin, StorageType type, base::Time accessed_time) { LazyInitialize(); - if (type == kStorageTypeTemporary && !lru_origin_callback_.is_null()) { + if (type == kStorageTypeTemporary && is_getting_eviction_origin_) { // Record the accessed origins while GetLRUOrigin task is runing // to filter out them from eviction. access_notified_origins_.insert(origin); @@ -1472,8 +1477,38 @@ void QuotaManager::DidGetPersistentGlobalUsageForHistogram( } void QuotaManager::GetEvictionOrigin(StorageType type, + int64 global_quota, const GetOriginCallback& callback) { - GetLRUOrigin(type, callback); + LazyInitialize(); + // This must not be called while there's an in-flight task. + DCHECK(!is_getting_eviction_origin_); + is_getting_eviction_origin_ = true; + + GetOriginCallback did_get_origin_callback = + base::Bind(&QuotaManager::DidGetEvictionOrigin, + weak_factory_.GetWeakPtr(), callback); + + if (type == kStorageTypeTemporary && temporary_storage_eviction_policy_) { + std::map<GURL, int64> usage_map; + // The cached origins are populated by the prior call to + // GetUsageAndQuotaForEviction(). + GetUsageTracker(kStorageTypeTemporary)->GetCachedOriginsUsage(&usage_map); + + temporary_storage_eviction_policy_->GetEvictionOrigin( + special_storage_policy_, usage_map, global_quota, + did_get_origin_callback); + return; + } + + // TODO(calamity): convert LRU origin retrieval into a QuotaEvictionPolicy. + GetLRUOrigin(type, did_get_origin_callback); +} + +void QuotaManager::DidGetEvictionOrigin(const GetOriginCallback& callback, + const GURL& origin) { + callback.Run(origin); + + is_getting_eviction_origin_ = false; } void QuotaManager::EvictOriginData(const GURL& origin, @@ -1520,6 +1555,7 @@ void QuotaManager::GetLRUOrigin(StorageType type, return; } + // TODO(calamity): make all QuotaEvictionPolicies aware of these exceptions. std::set<GURL>* exceptions = new std::set<GURL>; for (std::map<GURL, int>::const_iterator p = origins_in_use_.begin(); p != origins_in_use_.end(); diff --git a/storage/browser/quota/quota_manager.h b/storage/browser/quota/quota_manager.h index 3e05388..0e4884b 100644 --- a/storage/browser/quota/quota_manager.h +++ b/storage/browser/quota/quota_manager.h @@ -28,6 +28,8 @@ #include "storage/browser/quota/storage_observer.h" #include "storage/browser/storage_browser_export.h" +class SiteEngagementEvictionPolicyWithQuotaManagerTest; + namespace base { class FilePath; class SequencedTaskRunner; @@ -70,10 +72,12 @@ struct STORAGE_EXPORT UsageAndQuota { }; // TODO(calamity): Use this in the temporary storage eviction path. -// An interface for deciding which origin's temporary storage should be evicted -// when the quota is exceeded. +// An interface for deciding which origin's storage should be evicted when the +// quota is exceeded. class STORAGE_EXPORT QuotaEvictionPolicy { public: + virtual ~QuotaEvictionPolicy() {} + // Returns the next origin to evict. It might return an empty GURL when there // are no evictable origins. virtual void GetEvictionOrigin( @@ -94,6 +98,7 @@ class STORAGE_EXPORT QuotaEvictionHandler { // Returns next origin to evict. It might return an empty GURL when there are // no evictable origins. virtual void GetEvictionOrigin(StorageType type, + int64 global_quota, const GetOriginCallback& callback) = 0; virtual void EvictOriginData( @@ -194,6 +199,10 @@ class STORAGE_EXPORT QuotaManager StorageType type, bool enabled); + // Set the eviction policy to use when choosing an origin to evict. + void SetTemporaryStorageEvictionPolicy( + scoped_ptr<QuotaEvictionPolicy> policy); + // DeleteOriginData and DeleteHostData (surprisingly enough) delete data of a // particular StorageType associated with either a specific origin or set of // origins. Each method additionally requires a |quota_client_mask| which @@ -286,6 +295,7 @@ class STORAGE_EXPORT QuotaManager friend class QuotaManagerProxy; friend class QuotaTemporaryStorageEvictor; friend struct QuotaManagerDeleter; + friend class ::SiteEngagementEvictionPolicyWithQuotaManagerTest; class GetUsageInfoTask; @@ -373,8 +383,12 @@ class STORAGE_EXPORT QuotaManager void DidGetPersistentGlobalUsageForHistogram(int64 usage, int64 unlimited_usage); + void DidGetEvictionOrigin(const GetOriginCallback& callback, + const GURL& origin); + // QuotaEvictionHandler. void GetEvictionOrigin(StorageType type, + int64 global_quota, const GetOriginCallback& callback) override; void EvictOriginData(const GURL& origin, StorageType type, @@ -435,6 +449,8 @@ class STORAGE_EXPORT QuotaManager scoped_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; EvictionContext eviction_context_; + scoped_ptr<QuotaEvictionPolicy> temporary_storage_eviction_policy_; + bool is_getting_eviction_origin_; ClosureQueue db_initialization_callbacks_; AvailableSpaceCallbackQueue available_space_callbacks_; diff --git a/storage/browser/quota/quota_temporary_storage_evictor.cc b/storage/browser/quota/quota_temporary_storage_evictor.cc index adcff0d..30f17b8 100644 --- a/storage/browser/quota/quota_temporary_storage_evictor.cc +++ b/storage/browser/quota/quota_temporary_storage_evictor.cc @@ -196,7 +196,7 @@ void QuotaTemporaryStorageEvictor::OnGotUsageAndQuotaForEviction( // TODO(michaeln): if the reason for eviction is low physical disk space, // make 'unlimited' origins subject to eviction too. quota_eviction_handler_->GetEvictionOrigin( - kStorageTypeTemporary, + kStorageTypeTemporary, qau.quota, base::Bind(&QuotaTemporaryStorageEvictor::OnGotEvictionOrigin, weak_factory_.GetWeakPtr())); } else { diff --git a/storage/browser/quota/usage_tracker.cc b/storage/browser/quota/usage_tracker.cc index 528725d..de9fbeb 100644 --- a/storage/browser/quota/usage_tracker.cc +++ b/storage/browser/quota/usage_tracker.cc @@ -144,6 +144,14 @@ void UsageTracker::GetCachedHostsUsage( client_id_and_tracker.second->GetCachedHostsUsage(host_usage); } +void UsageTracker::GetCachedOriginsUsage( + std::map<GURL, int64>* origin_usage) const { + DCHECK(origin_usage); + origin_usage->clear(); + for (const auto& client_id_and_tracker : client_tracker_map_) + client_id_and_tracker.second->GetCachedOriginsUsage(origin_usage); +} + void UsageTracker::GetCachedOrigins(std::set<GURL>* origins) const { DCHECK(origins); origins->clear(); diff --git a/storage/browser/quota/usage_tracker.h b/storage/browser/quota/usage_tracker.h index 224faf8..ed54fcc 100644 --- a/storage/browser/quota/usage_tracker.h +++ b/storage/browser/quota/usage_tracker.h @@ -45,6 +45,7 @@ class STORAGE_EXPORT UsageTracker : public QuotaTaskObserver { void UpdateUsageCache(QuotaClient::ID client_id, const GURL& origin, int64 delta); + void GetCachedOriginsUsage(std::map<GURL, int64>* origin_usage) const; void GetCachedHostsUsage(std::map<std::string, int64>* host_usage) const; void GetCachedOrigins(std::set<GURL>* origins) const; bool IsWorking() const { |