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

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

Issue 1913693002: Histogram the amount of time spent on HTTP(S) page loads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Equality operations are hard, let's go trybotting Created 4 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 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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 navigation_start_(navigation_handle->NavigationStart()), 246 navigation_start_(navigation_handle->NavigationStart()),
247 url_(navigation_handle->GetURL()), 247 url_(navigation_handle->GetURL()),
248 abort_type_(ABORT_NONE), 248 abort_type_(ABORT_NONE),
249 started_in_foreground_(in_foreground), 249 started_in_foreground_(in_foreground),
250 aborted_chain_size_(aborted_chain_size), 250 aborted_chain_size_(aborted_chain_size),
251 aborted_chain_size_same_url_(aborted_chain_size_same_url), 251 aborted_chain_size_same_url_(aborted_chain_size_same_url),
252 embedder_interface_(embedder_interface) { 252 embedder_interface_(embedder_interface) {
253 DCHECK(!navigation_handle->HasCommitted()); 253 DCHECK(!navigation_handle->HasCommitted());
254 embedder_interface_->RegisterObservers(this); 254 embedder_interface_->RegisterObservers(this);
255 for (const auto& observer : observers_) { 255 for (const auto& observer : observers_) {
256 observer->OnStart(navigation_handle, currently_committed_url); 256 observer->OnStart(navigation_handle, currently_committed_url,
257 started_in_foreground_);
257 } 258 }
258 } 259 }
259 260
260 PageLoadTracker::~PageLoadTracker() { 261 PageLoadTracker::~PageLoadTracker() {
261 const PageLoadExtraInfo info = GetPageLoadMetricsInfo(); 262 const PageLoadExtraInfo info = GetPageLoadMetricsInfo();
262 if (!info.time_to_commit.is_zero() && renderer_tracked() && 263 if (!info.time_to_commit.is_zero() && renderer_tracked() &&
263 timing_.IsEmpty()) { 264 timing_.IsEmpty()) {
264 RecordInternalError(ERR_NO_IPCS_RECEIVED); 265 RecordInternalError(ERR_NO_IPCS_RECEIVED);
265 } 266 }
266 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their 267 // Recall that trackers that are given ABORT_UNKNOWN_NAVIGATION have their
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 322
322 void PageLoadTracker::WebContentsHidden() { 323 void PageLoadTracker::WebContentsHidden() {
323 // Only log the first time we background in a given page load. 324 // Only log the first time we background in a given page load.
324 if (background_time_.is_null()) { 325 if (background_time_.is_null()) {
325 // Make sure we either started in the foreground and haven't been 326 // Make sure we either started in the foreground and haven't been
326 // foregrounded yet, or started in the background and have already been 327 // foregrounded yet, or started in the background and have already been
327 // foregrounded. 328 // foregrounded.
328 DCHECK_EQ(started_in_foreground_, foreground_time_.is_null()); 329 DCHECK_EQ(started_in_foreground_, foreground_time_.is_null());
329 background_time_ = base::TimeTicks::Now(); 330 background_time_ = base::TimeTicks::Now();
330 } 331 }
332
333 for (const auto& observer : observers_)
334 observer->OnHidden();
331 } 335 }
332 336
333 void PageLoadTracker::WebContentsShown() { 337 void PageLoadTracker::WebContentsShown() {
334 // Only log the first time we foreground in a given page load. 338 // Only log the first time we foreground in a given page load.
335 if (foreground_time_.is_null()) { 339 if (foreground_time_.is_null()) {
336 // Make sure we either started in the background and haven't been 340 // Make sure we either started in the background and haven't been
337 // backgrounded yet, or started in the foreground and have already been 341 // backgrounded yet, or started in the foreground and have already been
338 // backgrounded. 342 // backgrounded.
339 DCHECK_NE(started_in_foreground_, background_time_.is_null()); 343 DCHECK_NE(started_in_foreground_, background_time_.is_null());
340 foreground_time_ = base::TimeTicks::Now(); 344 foreground_time_ = base::TimeTicks::Now();
341 } 345 }
346
347 for (const auto& observer : observers_)
348 observer->OnShown();
342 } 349 }
343 350
344 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) { 351 void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) {
345 // TODO(bmcquade): To improve accuracy, consider adding commit time to 352 // TODO(bmcquade): To improve accuracy, consider adding commit time to
346 // NavigationHandle. Taking a timestamp here should be close enough for now. 353 // NavigationHandle. Taking a timestamp here should be close enough for now.
347 commit_time_ = base::TimeTicks::Now(); 354 commit_time_ = base::TimeTicks::Now();
348 url_ = navigation_handle->GetURL(); 355 url_ = navigation_handle->GetURL();
349 for (const auto& observer : observers_) { 356 for (const auto& observer : observers_) {
350 observer->OnCommit(navigation_handle); 357 observer->OnCommit(navigation_handle);
351 } 358 }
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 788
782 if (!committed_load_->UpdateTiming(timing, metadata)) { 789 if (!committed_load_->UpdateTiming(timing, metadata)) {
783 // If the page load tracker cannot update its timing, something is wrong 790 // If the page load tracker cannot update its timing, something is wrong
784 // with the IPC (it's from another load, or it's invalid in some other way). 791 // with the IPC (it's from another load, or it's invalid in some other way).
785 // We expect this to be a rare occurrence. 792 // We expect this to be a rare occurrence.
786 RecordInternalError(ERR_BAD_TIMING_IPC); 793 RecordInternalError(ERR_BAD_TIMING_IPC);
787 } 794 }
788 } 795 }
789 796
790 } // namespace page_load_metrics 797 } // namespace page_load_metrics
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | components/page_load_metrics/browser/metrics_web_contents_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698