diff options
-rw-r--r-- | chrome/browser/browsing_data_quota_helper.h | 3 | ||||
-rw-r--r-- | chrome/browser/browsing_data_quota_helper_impl.cc | 53 | ||||
-rw-r--r-- | chrome/browser/browsing_data_quota_helper_impl.h | 22 | ||||
-rw-r--r-- | chrome/browser/browsing_data_quota_helper_unittest.cc | 53 | ||||
-rw-r--r-- | chrome/browser/cookies_tree_model.cc | 4 | ||||
-rw-r--r-- | chrome/browser/mock_browsing_data_quota_helper.cc | 3 | ||||
-rw-r--r-- | chrome/browser/mock_browsing_data_quota_helper.h | 1 |
7 files changed, 113 insertions, 26 deletions
diff --git a/chrome/browser/browsing_data_quota_helper.h b/chrome/browser/browsing_data_quota_helper.h index d3aac1b..2e41e00 100644 --- a/chrome/browser/browsing_data_quota_helper.h +++ b/chrome/browser/browsing_data_quota_helper.h @@ -65,8 +65,7 @@ class BrowsingDataQuotaHelper virtual void StartFetching(FetchResultCallback* callback) = 0; virtual void CancelNotification() = 0; - // We don't support deletion now. - virtual void DeleteQuotaHost(const std::string& host) {} + virtual void RevokeHostQuota(const std::string& host) = 0; protected: explicit BrowsingDataQuotaHelper(base::MessageLoopProxy* io_thread_); diff --git a/chrome/browser/browsing_data_quota_helper_impl.cc b/chrome/browser/browsing_data_quota_helper_impl.cc index bb4e9da..4ca148e 100644 --- a/chrome/browser/browsing_data_quota_helper_impl.cc +++ b/chrome/browser/browsing_data_quota_helper_impl.cc @@ -19,21 +19,6 @@ BrowsingDataQuotaHelper* BrowsingDataQuotaHelper::Create(Profile* profile) { profile->GetQuotaManager()); } -BrowsingDataQuotaHelperImpl::BrowsingDataQuotaHelperImpl( - base::MessageLoopProxy* ui_thread, - base::MessageLoopProxy* io_thread, - quota::QuotaManager* quota_manager) - : BrowsingDataQuotaHelper(io_thread), - quota_manager_(quota_manager), - is_fetching_(false), - ui_thread_(ui_thread), - io_thread_(io_thread), - callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { - DCHECK(quota_manager); -} - -BrowsingDataQuotaHelperImpl::~BrowsingDataQuotaHelperImpl() {} - void BrowsingDataQuotaHelperImpl::StartFetching(FetchResultCallback* callback) { DCHECK(callback); DCHECK(!callback_.get()); @@ -49,6 +34,37 @@ void BrowsingDataQuotaHelperImpl::CancelNotification() { callback_.reset(); } +void BrowsingDataQuotaHelperImpl::RevokeHostQuota(const std::string& host) { + if (!io_thread_->BelongsToCurrentThread()) { + io_thread_->PostTask( + FROM_HERE, + NewRunnableMethod( + this, + &BrowsingDataQuotaHelperImpl::RevokeHostQuota, + host)); + return; + } + + quota_manager_->SetPersistentHostQuota( + host, 0, callback_factory_.NewCallback( + &BrowsingDataQuotaHelperImpl::DidRevokeHostQuota)); +} + +BrowsingDataQuotaHelperImpl::BrowsingDataQuotaHelperImpl( + base::MessageLoopProxy* ui_thread, + base::MessageLoopProxy* io_thread, + quota::QuotaManager* quota_manager) + : BrowsingDataQuotaHelper(io_thread), + quota_manager_(quota_manager), + is_fetching_(false), + ui_thread_(ui_thread), + io_thread_(io_thread), + callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { + DCHECK(quota_manager); +} + +BrowsingDataQuotaHelperImpl::~BrowsingDataQuotaHelperImpl() {} + void BrowsingDataQuotaHelperImpl::FetchQuotaInfo() { if (!io_thread_->BelongsToCurrentThread()) { io_thread_->PostTask( @@ -160,3 +176,10 @@ void BrowsingDataQuotaHelperImpl::OnComplete() { callback_->Run(result); callback_.reset(); } + +void BrowsingDataQuotaHelperImpl::DidRevokeHostQuota( + quota::QuotaStatusCode status_unused, + const std::string& host_unused, + quota::StorageType type_unused, + int64 quota_unused) { +} diff --git a/chrome/browser/browsing_data_quota_helper_impl.h b/chrome/browser/browsing_data_quota_helper_impl.h index 09fa36b..b526b99 100644 --- a/chrome/browser/browsing_data_quota_helper_impl.h +++ b/chrome/browser/browsing_data_quota_helper_impl.h @@ -31,26 +31,32 @@ class BrowsingDataQuotaHelperImpl : public BrowsingDataQuotaHelper { public: virtual void StartFetching(FetchResultCallback* callback) OVERRIDE; virtual void CancelNotification() OVERRIDE; + virtual void RevokeHostQuota(const std::string& host) OVERRIDE; private: - void FetchQuotaInfo(); - void OnComplete(); + BrowsingDataQuotaHelperImpl(base::MessageLoopProxy* ui_thread, + base::MessageLoopProxy* io_thread, + quota::QuotaManager* quota_manager); + virtual ~BrowsingDataQuotaHelperImpl(); - void GetHostUsage(const std::string& host, quota::StorageType type); - void ProcessPendingHosts(); + void FetchQuotaInfo(); // Callback function for GetOriginModifiedSince. void GotOrigins(const std::set<GURL>& origins, quota::StorageType type); + void ProcessPendingHosts(); + void GetHostUsage(const std::string& host, quota::StorageType type); + // Callback function for GetHostUsage. void GotHostUsage(const std::string& host, quota::StorageType type, int64 usage); - explicit BrowsingDataQuotaHelperImpl(base::MessageLoopProxy* ui_thread, - base::MessageLoopProxy* io_thread, - quota::QuotaManager* quota_manager); - virtual ~BrowsingDataQuotaHelperImpl(); + void OnComplete(); + void DidRevokeHostQuota(quota::QuotaStatusCode status, + const std::string& host, + quota::StorageType type, + int64 quota); scoped_refptr<quota::QuotaManager> quota_manager_; scoped_ptr<FetchResultCallback> callback_; diff --git a/chrome/browser/browsing_data_quota_helper_unittest.cc b/chrome/browser/browsing_data_quota_helper_unittest.cc index 5cf5ede..bb0d677 100644 --- a/chrome/browser/browsing_data_quota_helper_unittest.cc +++ b/chrome/browser/browsing_data_quota_helper_unittest.cc @@ -21,6 +21,7 @@ class BrowsingDataQuotaHelperTest : public testing::Test { db_thread_(BrowserThread::DB, &message_loop_), io_thread_(BrowserThread::IO, &message_loop_), fetching_completed_(true), + quota_(-1), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} virtual ~BrowsingDataQuotaHelperTest() {} @@ -69,6 +70,37 @@ class BrowsingDataQuotaHelperTest : public testing::Test { client->TouchAllOriginsAndNotify(); } + void SetPersistentHostQuota(const std::string& host, int64 quota) { + quota_ = -1; + quota_manager_->SetPersistentHostQuota( + host, quota, callback_factory_.NewCallback( + &BrowsingDataQuotaHelperTest::GotPersistentHostQuota)); + } + + void GetPersistentHostQuota(const std::string& host) { + quota_ = -1; + quota_manager_->GetPersistentHostQuota( + host, callback_factory_.NewCallback( + &BrowsingDataQuotaHelperTest::GotPersistentHostQuota)); + } + + void GotPersistentHostQuota(quota::QuotaStatusCode status, + const std::string& host, + quota::StorageType type, + int64 quota) { + EXPECT_EQ(quota::kQuotaStatusOk, status); + EXPECT_EQ(quota::kStorageTypePersistent, type); + quota_ = quota; + } + + void RevokeHostQuota(const std::string& host) { + helper_->RevokeHostQuota(host); + } + + int64 quota() { + return quota_; + } + private: void FetchCompleted(const QuotaInfoArray& quota_info) { quota_info_ = quota_info; @@ -86,6 +118,7 @@ class BrowsingDataQuotaHelperTest : public testing::Test { bool fetching_completed_; QuotaInfoArray quota_info_; + int64 quota_; base::ScopedCallbackFactory<BrowsingDataQuotaHelperTest> callback_factory_; DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest); @@ -117,3 +150,23 @@ TEST_F(BrowsingDataQuotaHelperTest, FetchData) { expected.insert(QuotaInfo("example2.com", 1000, 0)); EXPECT_TRUE(expected == actual); } + +TEST_F(BrowsingDataQuotaHelperTest, RevokeHostQuota) { + const std::string kHost1("example1.com"); + const std::string kHost2("example2.com"); + + SetPersistentHostQuota(kHost1, 1); + SetPersistentHostQuota(kHost2, 10); + MessageLoop::current()->RunAllPending(); + + RevokeHostQuota(kHost1); + MessageLoop::current()->RunAllPending(); + + GetPersistentHostQuota(kHost1); + MessageLoop::current()->RunAllPending(); + EXPECT_EQ(0, quota()); + + GetPersistentHostQuota(kHost2); + MessageLoop::current()->RunAllPending(); + EXPECT_EQ(10, quota()); +} diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc index f0ed602..4fb778a 100644 --- a/chrome/browser/cookies_tree_model.cc +++ b/chrome/browser/cookies_tree_model.cc @@ -301,7 +301,9 @@ CookieTreeQuotaNode::CookieTreeQuotaNode( CookieTreeQuotaNode::~CookieTreeQuotaNode() {} void CookieTreeQuotaNode::DeleteStoredObjects() { - GetModel()->quota_helper_->DeleteQuotaHost(quota_info_->host); + // Calling this function may cause unexpected over-quota state of origin. + // However, it'll caused no problem, just prevent usage growth of the origin. + GetModel()->quota_helper_->RevokeHostQuota(quota_info_->host); GetModel()->quota_info_list_.erase(quota_info_); } diff --git a/chrome/browser/mock_browsing_data_quota_helper.cc b/chrome/browser/mock_browsing_data_quota_helper.cc index 45d2c41..d1daf51 100644 --- a/chrome/browser/mock_browsing_data_quota_helper.cc +++ b/chrome/browser/mock_browsing_data_quota_helper.cc @@ -19,6 +19,9 @@ void MockBrowsingDataQuotaHelper::CancelNotification() { callback_.reset(NULL); } +void MockBrowsingDataQuotaHelper::RevokeHostQuota(const std::string& host) { +} + void MockBrowsingDataQuotaHelper::AddHost( const std::string& host, int64 temporary_usage, diff --git a/chrome/browser/mock_browsing_data_quota_helper.h b/chrome/browser/mock_browsing_data_quota_helper.h index 0c4c3c4..4c8f778 100644 --- a/chrome/browser/mock_browsing_data_quota_helper.h +++ b/chrome/browser/mock_browsing_data_quota_helper.h @@ -19,6 +19,7 @@ class MockBrowsingDataQuotaHelper : public BrowsingDataQuotaHelper { virtual void StartFetching(FetchResultCallback* callback) OVERRIDE; virtual void CancelNotification() OVERRIDE; + virtual void RevokeHostQuota(const std::string& host) OVERRIDE; void AddHost(const std::string& host, int64 temporary_usage, |