Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 1117923004: Run load state update timer only when needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cpu
Patch Set: Add comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/resource_dispatcher_host_impl.cc
diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc
index 68f28111b25fd4ba9949222498e670ae84fdaf07..5789e92a5d92fcd303a89caa0a4343719b76dccd 100644
--- a/content/browser/loader/resource_dispatcher_host_impl.cc
+++ b/content/browser/loader/resource_dispatcher_host_impl.cc
@@ -452,7 +452,7 @@ ResourceDispatcherHostImpl::ResourceDispatcherHostImpl()
base::Unretained(this)));
update_load_states_timer_.reset(
- new base::RepeatingTimer<ResourceDispatcherHostImpl>());
+ new base::OneShotTimer<ResourceDispatcherHostImpl>());
}
ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() {
@@ -797,12 +797,8 @@ bool ResourceDispatcherHostImpl::HandleExternalProtocol(ResourceLoader* loader,
}
void ResourceDispatcherHostImpl::DidStartRequest(ResourceLoader* loader) {
- // Make sure we have the load state monitor running
- if (!update_load_states_timer_->IsRunning()) {
- update_load_states_timer_->Start(
- FROM_HERE, TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec),
- this, &ResourceDispatcherHostImpl::UpdateLoadInfo);
- }
+ if (scheduler_->HasLoadingClients() || loader->request()->has_upload())
+ ScheduleUpdateLoadInfo();
}
void ResourceDispatcherHostImpl::DidReceiveRedirect(ResourceLoader* loader,
@@ -910,7 +906,7 @@ void ResourceDispatcherHostImpl::OnShutdown() {
// Make sure we shutdown the timer now, otherwise by the time our destructor
// runs if the timer is still running the Task is deleted twice (once by
- // the MessageLoop and the second time by RepeatingTimer).
+ // the MessageLoop and the second time by OneShotTimer).
update_load_states_timer_.reset();
// Clear blocked requests if any left.
@@ -1751,10 +1747,6 @@ void ResourceDispatcherHostImpl::RemovePendingLoader(
IncrementOutstandingRequestsMemory(-1, *info);
pending_loaders_.erase(iter);
-
- // If we have no more pending requests, then stop the load state monitor
- if (pending_loaders_.empty() && update_load_states_timer_)
- update_load_states_timer_->Stop();
}
void ResourceDispatcherHostImpl::CancelRequest(int child_id,
@@ -2150,15 +2142,19 @@ ResourceDispatcherHostImpl::GetLoadInfoForAllRoutes() {
// Populate this map with load state changes, and then send them on to the UI
// thread where they can be passed along to the respective RVHs.
scoped_ptr<LoadInfoMap> info_map(new LoadInfoMap());
+ bool uploading = false;
for (const auto& loader : pending_loaders_) {
- // Also poll for upload progress on this timer and send upload progress ipc
- // messages to the plugin process.
- loader.second->ReportUploadProgress();
-
net::URLRequest* request = loader.second->request();
net::UploadProgress upload_progress = request->GetUploadProgress();
+ // Also poll for upload progress on this timer and send upload progress ipc
+ // messages to the plugin process.
+ if (request->has_upload()) {
+ loader.second->ReportUploadProgress();
+ uploading = true;
+ }
+
LoadInfo load_info;
load_info.url = request->url();
load_info.load_state = request->GetLoadState();
@@ -2173,6 +2169,10 @@ ResourceDispatcherHostImpl::GetLoadInfoForAllRoutes() {
(*info_map)[id] = load_info;
}
}
+
+ if (uploading)
+ ScheduleUpdateLoadInfo();
+
return info_map.Pass();
}
@@ -2186,6 +2186,9 @@ void ResourceDispatcherHostImpl::UpdateLoadInfo() {
BrowserThread::UI, FROM_HERE,
base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread,
base::Passed(&info_map)));
+
+ if (scheduler_->HasLoadingClients())
+ ScheduleUpdateLoadInfo();
}
void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id,
@@ -2350,4 +2353,12 @@ int ResourceDispatcherHostImpl::BuildLoadFlagsForRequest(
return load_flags;
}
+void ResourceDispatcherHostImpl::ScheduleUpdateLoadInfo() {
+ if (!update_load_states_timer_->IsRunning()) {
+ update_load_states_timer_->Start(
+ FROM_HERE, TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec),
+ this, &ResourceDispatcherHostImpl::UpdateLoadInfo);
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698