content: suppress no-op LoadStateChanged
Whenever any requests are running, ResourceDispatcherHostImpl polls for state
changes to running requests, so that these can be reflected in the UI. However,
ResourceDispatcherHostImpl doesn't remember the previous state of a request, so
it always calls LoaderDelegate::LoadStateChanged() for any running request, at
4Hz. This calls into WebContentsImpl::LoadStateChanged(), which *does* have
access to the previous state, which then notifies the UI of a change.
Instead, WebContentsImpl should check if the state notification is redundant,
and if so, should ignore it. This will save doing a bunch of work in the UI. In
principle, ResourceDispatcherHostImpl could do this de-duplication instead, but
that involves storing more data in RDHI for a very small further decrease in
work done.
This also fixes the root cause of an old bug where on Mac, the status bar would
be clobbered (at 4Hz) whenever there was a pending request in the current tab.
This bug was worked around in the Views status bar code by suppressing updates
with no text changes, but that workaround never made it to the Cocoa status
bar.
Bug: 147303
Change-Id: Idbaded695b161543d1750aa9e6253c3bdd0a145a
Reviewed-on: https://chromium-review.googlesource.com/895724
Reviewed-by: Avi Drissman <[email protected]>
Commit-Queue: Elly Fong-Jones <[email protected]>
Cr-Commit-Position: refs/heads/master@{#533309}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 27b496c..34db9757 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -3415,10 +3415,18 @@
const net::LoadStateWithParam& load_state,
uint64_t upload_position,
uint64_t upload_size) {
+ base::string16 host = url_formatter::IDNToUnicode(url.host());
+ // Drop no-op updates.
+ if (load_state_.state == load_state.state &&
+ load_state_.param == load_state.param &&
+ upload_position_ == upload_position && upload_size_ == upload_size &&
+ load_state_host_ == host) {
+ return;
+ }
load_state_ = load_state;
upload_position_ = upload_position;
upload_size_ = upload_size;
- load_state_host_ = url_formatter::IDNToUnicode(url.host());
+ load_state_host_ = host;
if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
SetNotWaitingForResponse();
if (IsLoading()) {