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

Side by Side Diff: components/page_load_metrics/browser/metrics_web_contents_observer.cc

Issue 1686643002: Add metric with time between background tab being foregrounded and the first paint (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 timing_.IsEmpty()) { 121 timing_.IsEmpty()) {
122 RecordInternalError(ERR_NO_IPCS_RECEIVED); 122 RecordInternalError(ERR_NO_IPCS_RECEIVED);
123 } 123 }
124 for (const auto& observer : observers_) { 124 for (const auto& observer : observers_) {
125 observer->OnComplete(timing_, info); 125 observer->OnComplete(timing_, info);
126 } 126 }
127 } 127 }
128 128
129 void PageLoadTracker::WebContentsHidden() { 129 void PageLoadTracker::WebContentsHidden() {
130 // Only log the first time we background in a given page load. 130 // Only log the first time we background in a given page load.
131 if (started_in_foreground_ && background_time_.is_null()) 131 if (background_time_.is_null())
132 background_time_ = base::TimeTicks::Now(); 132 background_time_ = base::TimeTicks::Now();
133 } 133 }
134 134
135 void PageLoadTracker::WebContentsShown() { 135 void PageLoadTracker::WebContentsShown() {
136 // Only log the first time we foreground in a given page load. 136 // Only log the first time we foreground in a given page load.
137 // Don't log foreground time if we started foregrounded. 137 if (foreground_time_.is_null())
138 if (!started_in_foreground_ && foreground_time_.is_null())
139 foreground_time_ = base::TimeTicks::Now(); 138 foreground_time_ = base::TimeTicks::Now();
140 } 139 }
141 140
142 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { 141 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) {
143 // TODO(bmcquade): To improve accuracy, consider adding commit time to 142 // TODO(bmcquade): To improve accuracy, consider adding commit time to
144 // NavigationHandle. Taking a timestamp here should be close enough for now. 143 // NavigationHandle. Taking a timestamp here should be close enough for now.
145 commit_time_ = base::TimeTicks::Now(); 144 commit_time_ = base::TimeTicks::Now();
146 committed_url_ = navigation_handle->GetURL(); 145 committed_url_ = navigation_handle->GetURL();
147 for (const auto& observer : observers_) { 146 for (const auto& observer : observers_) {
148 observer->OnCommit(navigation_handle); 147 observer->OnCommit(navigation_handle);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 void PageLoadTracker::AddObserver( 187 void PageLoadTracker::AddObserver(
189 scoped_ptr<PageLoadMetricsObserver> observer) { 188 scoped_ptr<PageLoadMetricsObserver> observer) {
190 observers_.push_back(std::move(observer)); 189 observers_.push_back(std::move(observer));
191 } 190 }
192 191
193 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() { 192 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() {
194 base::TimeDelta first_background_time; 193 base::TimeDelta first_background_time;
195 base::TimeDelta first_foreground_time; 194 base::TimeDelta first_foreground_time;
196 base::TimeDelta time_to_abort; 195 base::TimeDelta time_to_abort;
197 base::TimeDelta time_to_commit; 196 base::TimeDelta time_to_commit;
198 if (!background_time_.is_null() && started_in_foreground_) 197 if (!background_time_.is_null())
199 first_background_time = background_time_ - navigation_start_; 198 first_background_time = background_time_ - navigation_start_;
200 if (!foreground_time_.is_null() && !started_in_foreground_) 199 if (!foreground_time_.is_null())
201 first_foreground_time = foreground_time_ - navigation_start_; 200 first_foreground_time = foreground_time_ - navigation_start_;
202 if (abort_type_ != ABORT_NONE) { 201 if (abort_type_ != ABORT_NONE) {
203 DCHECK_GT(abort_time_, navigation_start_); 202 DCHECK_GT(abort_time_, navigation_start_);
204 time_to_abort = abort_time_ - navigation_start_; 203 time_to_abort = abort_time_ - navigation_start_;
205 } else { 204 } else {
206 DCHECK(abort_time_.is_null()); 205 DCHECK(abort_time_.is_null());
207 } 206 }
208 if (!committed_url_.is_empty()) { 207 if (!committed_url_.is_empty()) {
209 DCHECK_GT(commit_time_, navigation_start_); 208 DCHECK_GT(commit_time_, navigation_start_);
210 time_to_commit = commit_time_ - navigation_start_; 209 time_to_commit = commit_time_ - navigation_start_;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 489
491 if (!committed_load_->UpdateTiming(timing)) { 490 if (!committed_load_->UpdateTiming(timing)) {
492 // If the page load tracker cannot update its timing, something is wrong 491 // If the page load tracker cannot update its timing, something is wrong
493 // with the IPC (it's from another load, or it's invalid in some other way). 492 // with the IPC (it's from another load, or it's invalid in some other way).
494 // We expect this to be a rare occurrence. 493 // We expect this to be a rare occurrence.
495 RecordInternalError(ERR_BAD_TIMING_IPC); 494 RecordInternalError(ERR_BAD_TIMING_IPC);
496 } 495 }
497 } 496 }
498 497
499 } // namespace page_load_metrics 498 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698