diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-16 18:39:39 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-16 18:39:39 +0000 |
commit | 9830d77aa9cc9efd03d64226b15cfd94c39e66f8 (patch) | |
tree | 939166dbdc360b3c7d596cc2cef95803df82ac59 /webkit/appcache | |
parent | 59e414ef3fbd4551cc17a7cece753946357b8f63 (diff) | |
download | chromium_src-9830d77aa9cc9efd03d64226b15cfd94c39e66f8.zip chromium_src-9830d77aa9cc9efd03d64226b15cfd94c39e66f8.tar.gz chromium_src-9830d77aa9cc9efd03d64226b15cfd94c39e66f8.tar.bz2 |
Enough appcache + quota integration to call NotifyOriginInUse/NotifyOriginNoLongerInUse when frames are loaded/unloaded.
BUG=61676
TEST=appcache_host_unittest.cc
Review URL: http://codereview.chromium.org/6999008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85507 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r-- | webkit/appcache/appcache_host.cc | 7 | ||||
-rw-r--r-- | webkit/appcache/appcache_host.h | 3 | ||||
-rw-r--r-- | webkit/appcache/appcache_host_unittest.cc | 75 | ||||
-rw-r--r-- | webkit/appcache/appcache_service.cc | 9 | ||||
-rw-r--r-- | webkit/appcache/appcache_service.h | 9 | ||||
-rw-r--r-- | webkit/appcache/appcache_storage_impl_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/appcache/mock_appcache_service.h | 7 |
7 files changed, 91 insertions, 21 deletions
diff --git a/webkit/appcache/appcache_host.cc b/webkit/appcache/appcache_host.cc index 18809790..6965c1d 100644 --- a/webkit/appcache/appcache_host.cc +++ b/webkit/appcache/appcache_host.cc @@ -10,6 +10,7 @@ #include "webkit/appcache/appcache.h" #include "webkit/appcache/appcache_backend_impl.h" #include "webkit/appcache/appcache_request_handler.h" +#include "webkit/quota/quota_manager.h" namespace appcache { @@ -52,6 +53,8 @@ AppCacheHost::~AppCacheHost() { if (group_being_updated_.get()) group_being_updated_->RemoveUpdateObserver(this); service_->storage()->CancelDelegateCallbacks(this); + if (service()->quota_manager_proxy() && !origin_in_use_.is_empty()) + service()->quota_manager_proxy()->NotifyOriginNoLongerInUse(origin_in_use_); } void AppCacheHost::AddObserver(Observer* observer) { @@ -70,6 +73,10 @@ void AppCacheHost::SelectCache(const GURL& document_url, !pending_get_status_callback_ && !is_selection_pending()); + origin_in_use_ = document_url.GetOrigin(); + if (service()->quota_manager_proxy() && !origin_in_use_.is_empty()) + service()->quota_manager_proxy()->NotifyOriginInUse(origin_in_use_); + if (main_resource_blocked_) frontend_->OnContentBlocked(host_id_, blocked_manifest_url_); diff --git a/webkit/appcache/appcache_host.h b/webkit/appcache/appcache_host.h index 6f25a57..a06cdd3 100644 --- a/webkit/appcache/appcache_host.h +++ b/webkit/appcache/appcache_host.h @@ -242,6 +242,9 @@ class AppCacheHost : public AppCacheStorage::Delegate, // List of objects observing us. ObserverList<Observer> observers_; + // Used to inform the QuotaManager of what origins are currently in use. + GURL origin_in_use_; + friend class AppCacheRequestHandlerTest; friend class AppCacheUpdateJobTest; FRIEND_TEST_ALL_PREFIXES(AppCacheTest, CleanupUnusedCache); diff --git a/webkit/appcache/appcache_host_unittest.cc b/webkit/appcache/appcache_host_unittest.cc index d648e07..762ed9c 100644 --- a/webkit/appcache/appcache_host_unittest.cc +++ b/webkit/appcache/appcache_host_unittest.cc @@ -11,6 +11,7 @@ #include "webkit/appcache/appcache_group.h" #include "webkit/appcache/appcache_host.h" #include "webkit/appcache/mock_appcache_service.h" +#include "webkit/quota/quota_manager.h" namespace appcache { @@ -76,6 +77,40 @@ class AppCacheHostTest : public testing::Test { appcache::EventID last_event_id_; }; + class MockQuotaManagerProxy : public quota::QuotaManagerProxy { + public: + MockQuotaManagerProxy() : QuotaManagerProxy(NULL, NULL) {} + + // Not needed for our tests. + virtual void RegisterClient(quota::QuotaClient* client) {} + virtual void NotifyStorageAccessed(quota::QuotaClient::ID client_id, + const GURL& origin, + quota::StorageType type) {} + virtual void NotifyStorageModified(quota::QuotaClient::ID client_id, + const GURL& origin, + quota::StorageType type, + int64 delta) {} + + virtual void NotifyOriginInUse(const GURL& origin) { + inuse_[origin] += 1; + } + + virtual void NotifyOriginNoLongerInUse(const GURL& origin) { + inuse_[origin] -= 1; + } + + int GetInUseCount(const GURL& origin) { + return inuse_[origin]; + } + + void reset() { + inuse_.clear(); + } + + // Map from origin to count of inuse notifications. + std::map<GURL, int> inuse_; + }; + void GetStatusCallback(Status status, void* param) { last_status_result_ = status; last_callback_param_ = param; @@ -137,26 +172,36 @@ TEST_F(AppCacheHostTest, Basic) { } TEST_F(AppCacheHostTest, SelectNoCache) { + scoped_refptr<MockQuotaManagerProxy> mock_quota_proxy( + new MockQuotaManagerProxy); + service_.set_quota_manager_proxy(mock_quota_proxy); + // Reset our mock frontend mock_frontend_.last_cache_id_ = -333; mock_frontend_.last_host_id_ = -333; mock_frontend_.last_status_ = OBSOLETE; - AppCacheHost host(1, &mock_frontend_, &service_); - host.SelectCache(GURL("http://whatever/"), kNoCacheId, GURL()); - - // We should have received an OnCacheSelected msg - EXPECT_EQ(1, mock_frontend_.last_host_id_); - EXPECT_EQ(kNoCacheId, mock_frontend_.last_cache_id_); - EXPECT_EQ(UNCACHED, mock_frontend_.last_status_); - - // Otherwise, see that it respond as if there is no cache selected. - EXPECT_EQ(1, host.host_id()); - EXPECT_EQ(&service_, host.service()); - EXPECT_EQ(&mock_frontend_, host.frontend()); - EXPECT_EQ(NULL, host.associated_cache()); - EXPECT_FALSE(host.is_selection_pending()); - EXPECT_TRUE(host.preferred_manifest_url().is_empty()); + const GURL kDocAndOriginUrl(GURL("http://whatever/").GetOrigin()); + { + AppCacheHost host(1, &mock_frontend_, &service_); + host.SelectCache(kDocAndOriginUrl, kNoCacheId, GURL()); + EXPECT_EQ(1, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl)); + + // We should have received an OnCacheSelected msg + EXPECT_EQ(1, mock_frontend_.last_host_id_); + EXPECT_EQ(kNoCacheId, mock_frontend_.last_cache_id_); + EXPECT_EQ(UNCACHED, mock_frontend_.last_status_); + + // Otherwise, see that it respond as if there is no cache selected. + EXPECT_EQ(1, host.host_id()); + EXPECT_EQ(&service_, host.service()); + EXPECT_EQ(&mock_frontend_, host.frontend()); + EXPECT_EQ(NULL, host.associated_cache()); + EXPECT_FALSE(host.is_selection_pending()); + EXPECT_TRUE(host.preferred_manifest_url().is_empty()); + } + EXPECT_EQ(0, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl)); + service_.set_quota_manager_proxy(NULL); } TEST_F(AppCacheHostTest, ForeignEntry) { diff --git a/webkit/appcache/appcache_service.cc b/webkit/appcache/appcache_service.cc index 5e477ac..fbfd379 100644 --- a/webkit/appcache/appcache_service.cc +++ b/webkit/appcache/appcache_service.cc @@ -10,6 +10,7 @@ #include "webkit/appcache/appcache_backend_impl.h" #include "webkit/appcache/appcache_entry.h" #include "webkit/appcache/appcache_storage_impl.h" +#include "webkit/quota/quota_manager.h" #include "webkit/quota/special_storage_policy.h" namespace appcache { @@ -175,13 +176,14 @@ void AppCacheService::GetInfoHelper::OnAllInfo( // AppCacheService ------- -AppCacheService::AppCacheService() - : appcache_policy_(NULL), request_context_(NULL) { +AppCacheService::AppCacheService(quota::QuotaManagerProxy* quota_manager_proxy) + : appcache_policy_(NULL), quota_manager_proxy_(quota_manager_proxy), + request_context_(NULL) { + // TODO(michaeln): Create and register our QuotaClient. } AppCacheService::~AppCacheService() { DCHECK(backends_.empty()); - std::for_each(pending_helpers_.begin(), pending_helpers_.end(), std::mem_fun(&AsyncHelper::Cancel)); @@ -221,6 +223,7 @@ void AppCacheService::set_special_storage_policy( quota::SpecialStoragePolicy* policy) { special_storage_policy_ = policy; } + void AppCacheService::RegisterBackend( AppCacheBackendImpl* backend_impl) { DCHECK(backends_.find(backend_impl->process_id()) == backends_.end()); diff --git a/webkit/appcache/appcache_service.h b/webkit/appcache/appcache_service.h index d4ece07..2606a7a 100644 --- a/webkit/appcache/appcache_service.h +++ b/webkit/appcache/appcache_service.h @@ -28,6 +28,7 @@ class MessageLoopProxy; } namespace quota { +class QuotaManagerProxy; class SpecialStoragePolicy; } @@ -50,7 +51,8 @@ struct AppCacheInfoCollection // exclusive access to it's cache_directory on disk. class AppCacheService { public: - AppCacheService(); + // If not using quota management, the proxy may be NULL. + explicit AppCacheService(quota::QuotaManagerProxy* quota_manager_proxy); virtual ~AppCacheService(); void Initialize(const FilePath& cache_directory, @@ -104,6 +106,10 @@ class AppCacheService { } void set_special_storage_policy(quota::SpecialStoragePolicy* policy); + quota::QuotaManagerProxy* quota_manager_proxy() const { + return quota_manager_proxy_.get(); + } + // Each child process in chrome uses a distinct backend instance. // See chrome/browser/AppCacheDispatcherHost. void RegisterBackend(AppCacheBackendImpl* backend_impl); @@ -127,6 +133,7 @@ class AppCacheService { AppCachePolicy* appcache_policy_; scoped_ptr<AppCacheStorage> storage_; scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; + scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; PendingAsyncHelpers pending_helpers_; BackendMap backends_; // One 'backend' per child process. // Context for use during cache updates. diff --git a/webkit/appcache/appcache_storage_impl_unittest.cc b/webkit/appcache/appcache_storage_impl_unittest.cc index af87b08..1237c02 100644 --- a/webkit/appcache/appcache_storage_impl_unittest.cc +++ b/webkit/appcache/appcache_storage_impl_unittest.cc @@ -241,7 +241,7 @@ class AppCacheStorageImplTest : public testing::Test { void SetUpTest() { DCHECK(MessageLoop::current() == io_thread->message_loop()); - service_.reset(new AppCacheService); + service_.reset(new AppCacheService(NULL)); service_->Initialize(FilePath(), NULL); delegate_.reset(new MockStorageDelegate(this)); } diff --git a/webkit/appcache/mock_appcache_service.h b/webkit/appcache/mock_appcache_service.h index 705dc0e..d9f327a 100644 --- a/webkit/appcache/mock_appcache_service.h +++ b/webkit/appcache/mock_appcache_service.h @@ -8,15 +8,20 @@ #include "base/compiler_specific.h" #include "webkit/appcache/appcache_service.h" #include "webkit/appcache/mock_appcache_storage.h" +#include "webkit/quota/quota_manager.h" namespace appcache { // For use by unit tests. class MockAppCacheService : public AppCacheService { public: - MockAppCacheService() { + MockAppCacheService() : AppCacheService(NULL) { storage_.reset(new MockAppCacheStorage(this)); } + + void set_quota_manager_proxy(quota::QuotaManagerProxy* proxy) { + quota_manager_proxy_ = proxy; + } }; } // namespace appcache |