diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-10 02:11:41 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-10 02:11:41 +0000 |
commit | 3da9e382813c630d1e650ace8e79c41d8ccb4a19 (patch) | |
tree | 243156eb55a8d4ecd59eca608a63211e246b7187 /webkit/appcache | |
parent | 8f8a28704dac9cc099dea906383a4d4533a7b89e (diff) | |
download | chromium_src-3da9e382813c630d1e650ace8e79c41d8ccb4a19.zip chromium_src-3da9e382813c630d1e650ace8e79c41d8ccb4a19.tar.gz chromium_src-3da9e382813c630d1e650ace8e79c41d8ccb4a19.tar.bz2 |
applicationCache.swap(), applicationCache.update() and applicationCache.status scriptable API impls
TEST=manual and existing unittests
BUG=none
Review URL: http://codereview.chromium.org/379003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31536 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache')
-rw-r--r-- | webkit/appcache/appcache_host.cc | 61 | ||||
-rw-r--r-- | webkit/appcache/appcache_unittest.cc | 3 |
2 files changed, 53 insertions, 11 deletions
diff --git a/webkit/appcache/appcache_host.cc b/webkit/appcache/appcache_host.cc index 1bf82427..ab1ff6d 100644 --- a/webkit/appcache/appcache_host.cc +++ b/webkit/appcache/appcache_host.cc @@ -137,9 +137,18 @@ void AppCacheHost::StartUpdateWithCallback(StartUpdateCallback* callback, void AppCacheHost::DoPendingStartUpdate() { DCHECK(pending_start_update_callback_); - // TODO(michaeln): start an update if appropiate to do so + // 6.9.8 Application cache API + bool success = false; + if (associated_cache_) { + AppCacheGroup* group = associated_cache_->owning_group(); + if (!group->is_obsolete()) { + success = true; + group->StartUpdate(); + } + } + pending_start_update_callback_->Run( - false, pending_callback_param_); + success, pending_callback_param_); pending_start_update_callback_ = NULL; pending_callback_param_ = NULL; @@ -162,9 +171,22 @@ void AppCacheHost::SwapCacheWithCallback(SwapCacheCallback* callback, void AppCacheHost::DoPendingSwapCache() { DCHECK(pending_swap_cache_callback_); - // TODO(michaeln): swap if we have a cache that can be swapped. + // 6.9.8 Application cache API + bool success = false; + if (associated_cache_) { + if (associated_cache_->owning_group()->is_obsolete()) { + success = true; + AssociateCache(NULL); + } else if (swappable_cache_) { + DCHECK(swappable_cache_.get() == + swappable_cache_->owning_group()->newest_complete_cache()); + success = true; + AssociateCache(swappable_cache_); + } + } + pending_swap_cache_callback_->Run( - false, pending_callback_param_); + success, pending_callback_param_); pending_swap_cache_callback_ = NULL; pending_callback_param_ = NULL; @@ -184,9 +206,22 @@ AppCacheRequestHandler* AppCacheHost::CreateRequestHandler( } Status AppCacheHost::GetStatus() { - // TODO(michaeln): determine a real status value - Status status = associated_cache() ? IDLE : UNCACHED; - return status; + // 6.9.8 Application cache API + AppCache* cache = associated_cache(); + if (!cache) + return UNCACHED; + + DCHECK(cache->owning_group()); + + if (cache->owning_group()->is_obsolete()) + return OBSOLETE; + if (cache->owning_group()->update_status() == AppCacheGroup::CHECKING) + return CHECKING; + if (cache->owning_group()->update_status() == AppCacheGroup::DOWNLOADING) + return DOWNLOADING; + if (swappable_cache_) + return UPDATE_READY; + return IDLE; } void AppCacheHost::LoadOrCreateGroup(const GURL& manifest_url) { @@ -276,11 +311,15 @@ void AppCacheHost::OnUpdateComplete(AppCacheGroup* group) { } void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { - AppCache* new_cache = group ? group->newest_complete_cache() : NULL; - if (new_cache != associated_cache_) - swappable_cache_ = new_cache; - else + if (!group) { swappable_cache_ = NULL; + } else { + AppCache* new_cache = group->newest_complete_cache(); + if (new_cache != associated_cache_) + swappable_cache_ = new_cache; + else + swappable_cache_ = NULL; + } } void AppCacheHost::LoadMainResourceCache(int64 cache_id) { diff --git a/webkit/appcache/appcache_unittest.cc b/webkit/appcache/appcache_unittest.cc index 12f8b30..d188550 100644 --- a/webkit/appcache/appcache_unittest.cc +++ b/webkit/appcache/appcache_unittest.cc @@ -18,6 +18,9 @@ TEST(AppCacheTest, CleanupUnusedCache) { AppCacheFrontendImpl frontend; scoped_refptr<AppCache> cache(new AppCache(&service, 111)); cache->set_complete(true); + scoped_refptr<AppCacheGroup> group( + new AppCacheGroup(&service, GURL("http://blah/manifest"))); + group->AddCache(cache); AppCacheHost host1(1, &frontend, &service); AppCacheHost host2(2, &frontend, &service); |