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

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

Issue 1857443002: Plumb experiment flags through page_load_metrics and add a new observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page_load_experiments
Patch Set: clean up unit tests Created 4 years, 8 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 observer->OnFailedProvisionalLoad(navigation_handle); 291 observer->OnFailedProvisionalLoad(navigation_handle);
292 } 292 }
293 } 293 }
294 294
295 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) { 295 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) {
296 for (const auto& observer : observers_) { 296 for (const auto& observer : observers_) {
297 observer->OnRedirect(navigation_handle); 297 observer->OnRedirect(navigation_handle);
298 } 298 }
299 } 299 }
300 300
301 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing) { 301 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing,
302 const PageLoadMetadata& new_metadata) {
302 // Throw away IPCs that are not relevant to the current navigation. 303 // Throw away IPCs that are not relevant to the current navigation.
303 // Two timing structures cannot refer to the same navigation if they indicate 304 // Two timing structures cannot refer to the same navigation if they indicate
304 // that a navigation started at different times, so a new timing struct with a 305 // that a navigation started at different times, so a new timing struct with a
305 // different start time from an earlier struct is considered invalid. 306 // different start time from an earlier struct is considered invalid.
306 bool valid_timing_descendent = 307 bool valid_timing_descendent =
307 timing_.navigation_start.is_null() || 308 timing_.navigation_start.is_null() ||
308 timing_.navigation_start == new_timing.navigation_start; 309 timing_.navigation_start == new_timing.navigation_start;
309 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) { 310 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) {
310 timing_ = new_timing; 311 timing_ = new_timing;
312 metadata_ = new_metadata;
311 return true; 313 return true;
312 } 314 }
313 return false; 315 return false;
314 } 316 }
315 317
316 bool PageLoadTracker::HasBackgrounded() { 318 bool PageLoadTracker::HasBackgrounded() {
317 return !started_in_foreground_ || !background_time_.is_null(); 319 return !started_in_foreground_ || !background_time_.is_null();
318 } 320 }
319 321
320 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { 322 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) {
(...skipping 20 matching lines...) Expand all
341 } else { 343 } else {
342 DCHECK(abort_time_.is_null()); 344 DCHECK(abort_time_.is_null());
343 } 345 }
344 346
345 if (!commit_time_.is_null()) { 347 if (!commit_time_.is_null()) {
346 DCHECK_GT(commit_time_, navigation_start_); 348 DCHECK_GT(commit_time_, navigation_start_);
347 time_to_commit = commit_time_ - navigation_start_; 349 time_to_commit = commit_time_ - navigation_start_;
348 } else { 350 } else {
349 DCHECK(commit_time_.is_null()); 351 DCHECK(commit_time_.is_null());
350 } 352 }
351 return PageLoadExtraInfo(first_background_time, first_foreground_time, 353 return PageLoadExtraInfo(
352 started_in_foreground_, 354 first_background_time, first_foreground_time, started_in_foreground_,
353 commit_time_.is_null() ? GURL() : url_, 355 commit_time_.is_null() ? GURL() : url_, time_to_commit, abort_type_,
354 time_to_commit, abort_type_, time_to_abort); 356 time_to_abort, metadata_);
355 } 357 }
356 358
357 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, 359 void PageLoadTracker::NotifyAbort(UserAbortType abort_type,
358 base::TimeTicks timestamp) { 360 base::TimeTicks timestamp) {
359 DCHECK_NE(abort_type, ABORT_NONE); 361 DCHECK_NE(abort_type, ABORT_NONE);
360 // Use UpdateAbort to update an already notified PageLoadTracker. 362 // Use UpdateAbort to update an already notified PageLoadTracker.
361 if (abort_type_ != ABORT_NONE) 363 if (abort_type_ != ABORT_NONE)
362 return; 364 return;
363 365
364 UpdateAbortInternal(abort_type, timestamp); 366 UpdateAbortInternal(abort_type, timestamp);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 base::TimeTicks timestamp = new_navigation->NavigationStart(); 648 base::TimeTicks timestamp = new_navigation->NavigationStart();
647 if (last_aborted_load->IsLikelyProvisionalAbort(timestamp)) 649 if (last_aborted_load->IsLikelyProvisionalAbort(timestamp))
648 last_aborted_load->UpdateAbort(ABORT_UNKNOWN_NAVIGATION, timestamp); 650 last_aborted_load->UpdateAbort(ABORT_UNKNOWN_NAVIGATION, timestamp);
649 651
650 aborted_provisional_loads_.clear(); 652 aborted_provisional_loads_.clear();
651 return last_aborted_load; 653 return last_aborted_load;
652 } 654 }
653 655
654 void MetricsWebContentsObserver::OnTimingUpdated( 656 void MetricsWebContentsObserver::OnTimingUpdated(
655 content::RenderFrameHost* render_frame_host, 657 content::RenderFrameHost* render_frame_host,
656 const PageLoadTiming& timing) { 658 const PageLoadTiming& timing,
659 const PageLoadMetadata& metadata) {
657 bool error = false; 660 bool error = false;
658 if (!committed_load_ || !committed_load_->renderer_tracked()) { 661 if (!committed_load_ || !committed_load_->renderer_tracked()) {
659 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); 662 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD);
660 error = true; 663 error = true;
661 } 664 }
662 665
663 // We may receive notifications from frames that have been navigated away 666 // We may receive notifications from frames that have been navigated away
664 // from. We simply ignore them. 667 // from. We simply ignore them.
665 if (render_frame_host != web_contents()->GetMainFrame()) { 668 if (render_frame_host != web_contents()->GetMainFrame()) {
666 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME); 669 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME);
667 error = true; 670 error = true;
668 } 671 }
669 672
670 // For urls like chrome://newtab, the renderer and browser disagree, 673 // For urls like chrome://newtab, the renderer and browser disagree,
671 // so we have to double check that the renderer isn't sending data from a 674 // so we have to double check that the renderer isn't sending data from a
672 // bad url like https://www.google.com/_/chrome/newtab. 675 // bad url like https://www.google.com/_/chrome/newtab.
673 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { 676 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) {
674 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); 677 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME);
675 error = true; 678 error = true;
676 } 679 }
677 680
678 if (error) 681 if (error)
679 return; 682 return;
680 683
681 if (!committed_load_->UpdateTiming(timing)) { 684 if (!committed_load_->UpdateTiming(timing, metadata)) {
682 // If the page load tracker cannot update its timing, something is wrong 685 // If the page load tracker cannot update its timing, something is wrong
683 // with the IPC (it's from another load, or it's invalid in some other way). 686 // with the IPC (it's from another load, or it's invalid in some other way).
684 // We expect this to be a rare occurrence. 687 // We expect this to be a rare occurrence.
685 RecordInternalError(ERR_BAD_TIMING_IPC); 688 RecordInternalError(ERR_BAD_TIMING_IPC);
686 } 689 }
687 } 690 }
688 691
689 } // namespace page_load_metrics 692 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698