diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-25 21:15:31 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-25 21:15:31 +0000 |
commit | 697af4a94a9351f6994d9207356930f373cf3a6e (patch) | |
tree | 501a3d73683bf94694da5a540c5b6b88501ba961 /webkit/appcache/appcache_update_job.cc | |
parent | 2a8132263c53c361e4a7618af889492407dbb8e2 (diff) | |
download | chromium_src-697af4a94a9351f6994d9207356930f373cf3a6e.zip chromium_src-697af4a94a9351f6994d9207356930f373cf3a6e.tar.gz chromium_src-697af4a94a9351f6994d9207356930f373cf3a6e.tar.bz2 |
Provide more info to the renderer process in appcache progress events.
BUG=39370
TEST= yes, updated unittests
Review URL: http://codereview.chromium.org/2166006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48197 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_update_job.cc')
-rw-r--r-- | webkit/appcache/appcache_update_job.cc | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/webkit/appcache/appcache_update_job.cc b/webkit/appcache/appcache_update_job.cc index dd2c79e..5bd7d42 100644 --- a/webkit/appcache/appcache_update_job.cc +++ b/webkit/appcache/appcache_update_job.cc @@ -96,6 +96,16 @@ class HostNotifier { } } + void SendProgressNotifications( + const GURL& url, int num_total, int num_complete) { + for (NotifyHostMap::iterator it = hosts_to_notify.begin(); + it != hosts_to_notify.end(); ++it) { + AppCacheFrontend* frontend = it->first; + frontend->OnProgressEventRaised(it->second, url, + num_total, num_complete); + } + } + private: NotifyHostMap hosts_to_notify; }; @@ -575,6 +585,7 @@ void AppCacheUpdateJob::HandleUrlFetchCompleted(URLRequest* request) { const GURL& url = request->original_url(); pending_url_fetches_.erase(url); + NotifyProgress(url); ++url_fetches_completed_; int response_code = request->status().is_success() @@ -817,28 +828,42 @@ void AppCacheUpdateJob::NotifyAllPendingMasterHosts(EventID event_id) { } void AppCacheUpdateJob::NotifyAllAssociatedHosts(EventID event_id) { + HostNotifier host_notifier; + AddAllAssociatedHostsToNotifier(&host_notifier); + host_notifier.SendNotifications(event_id); +} + +void AppCacheUpdateJob::NotifyProgress(const GURL& url) { + HostNotifier host_notifier; + AddAllAssociatedHostsToNotifier(&host_notifier); + host_notifier.SendProgressNotifications( + url, url_file_list_.size(), url_fetches_completed_); +} + +void AppCacheUpdateJob::NotifyFinalProgress() { + DCHECK(url_file_list_.size() == url_fetches_completed_); + NotifyProgress(GURL()); +} + +void AppCacheUpdateJob::AddAllAssociatedHostsToNotifier( + HostNotifier* host_notifier) { // Collect hosts so we only send one notification per frontend. // A host can only be associated with a single cache so no need to worry // about duplicate hosts being added to the notifier. - HostNotifier host_notifier; if (inprogress_cache_) { DCHECK(internal_state_ == DOWNLOADING || internal_state_ == CACHE_FAILURE); - host_notifier.AddHosts(inprogress_cache_->associated_hosts()); + host_notifier->AddHosts(inprogress_cache_->associated_hosts()); } AppCacheGroup::Caches old_caches = group_->old_caches(); for (AppCacheGroup::Caches::const_iterator it = old_caches.begin(); it != old_caches.end(); ++it) { - host_notifier.AddHosts((*it)->associated_hosts()); + host_notifier->AddHosts((*it)->associated_hosts()); } AppCache* newest_cache = group_->newest_complete_cache(); if (newest_cache) - host_notifier.AddHosts(newest_cache->associated_hosts()); - - // TODO(jennb): if progress event, also pass params lengthComputable=true, - // total = url_file_list_.size(), loaded=url_fetches_completed_. - host_notifier.SendNotifications(event_id); + host_notifier->AddHosts(newest_cache->associated_hosts()); } void AppCacheUpdateJob::OnDestructionImminent(AppCacheHost* host) { @@ -925,10 +950,6 @@ void AppCacheUpdateJob::FetchUrls() { // each fetch completes. while (pending_url_fetches_.size() < kMaxConcurrentUrlFetches && !urls_to_fetch_.empty()) { - // Notify about progress first to ensure it starts from 0% in case any - // entries are skipped. - NotifyAllAssociatedHosts(PROGRESS_EVENT); - const GURL url = urls_to_fetch_.front().first; bool storage_checked = urls_to_fetch_.front().second; urls_to_fetch_.pop_front(); @@ -937,8 +958,10 @@ void AppCacheUpdateJob::FetchUrls() { DCHECK(it != url_file_list_.end()); AppCacheEntry& entry = it->second; if (ShouldSkipUrlFetch(entry)) { + NotifyProgress(url); ++url_fetches_completed_; } else if (AlreadyFetchedEntry(url, entry.types())) { + NotifyProgress(url); ++url_fetches_completed_; // saved a URL request } else if (!storage_checked && MaybeLoadFromNewestCache(url, entry)) { // Continues asynchronously after data is loaded from newest cache. @@ -1164,6 +1187,7 @@ void AppCacheUpdateJob::OnResponseInfoLoaded( entry.set_response_id(response_id); entry.set_response_size(copy_me->response_size()); inprogress_cache_->AddOrModifyEntry(url, entry); + NotifyProgress(url); ++url_fetches_completed_; } } @@ -1213,6 +1237,7 @@ void AppCacheUpdateJob::MaybeCompleteUpdate() { break; case REFETCH_MANIFEST: DCHECK(stored_state_ == STORED); + NotifyFinalProgress(); if (update_type_ == CACHE_ATTEMPT) NotifyAllAssociatedHosts(CACHED_EVENT); else |