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

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: No need to add Default group to variation config 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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 observer->OnFailedProvisionalLoad(navigation_handle); 316 observer->OnFailedProvisionalLoad(navigation_handle);
317 } 317 }
318 } 318 }
319 319
320 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) { 320 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) {
321 for (const auto& observer : observers_) { 321 for (const auto& observer : observers_) {
322 observer->OnRedirect(navigation_handle); 322 observer->OnRedirect(navigation_handle);
323 } 323 }
324 } 324 }
325 325
326 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing) { 326 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing,
327 const PageLoadMetadata& new_metadata) {
327 // Throw away IPCs that are not relevant to the current navigation. 328 // Throw away IPCs that are not relevant to the current navigation.
328 // Two timing structures cannot refer to the same navigation if they indicate 329 // Two timing structures cannot refer to the same navigation if they indicate
329 // that a navigation started at different times, so a new timing struct with a 330 // that a navigation started at different times, so a new timing struct with a
330 // different start time from an earlier struct is considered invalid. 331 // different start time from an earlier struct is considered invalid.
331 bool valid_timing_descendent = 332 bool valid_timing_descendent =
Bryan McQuade 2016/04/11 20:18:47 just to be extra safe, could we do a similar test
Charlie Harrison 2016/04/12 15:18:50 Done.
332 timing_.navigation_start.is_null() || 333 timing_.navigation_start.is_null() ||
333 timing_.navigation_start == new_timing.navigation_start; 334 timing_.navigation_start == new_timing.navigation_start;
334 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) { 335 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) {
335 timing_ = new_timing; 336 timing_ = new_timing;
337 metadata_ = new_metadata;
336 return true; 338 return true;
337 } 339 }
338 return false; 340 return false;
339 } 341 }
340 342
341 bool PageLoadTracker::HasBackgrounded() { 343 bool PageLoadTracker::HasBackgrounded() {
342 return !started_in_foreground_ || !background_time_.is_null(); 344 return !started_in_foreground_ || !background_time_.is_null();
343 } 345 }
344 346
345 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) { 347 void PageLoadTracker::set_renderer_tracked(bool renderer_tracked) {
(...skipping 20 matching lines...) Expand all
366 } else { 368 } else {
367 DCHECK(abort_time_.is_null()); 369 DCHECK(abort_time_.is_null());
368 } 370 }
369 371
370 if (!commit_time_.is_null()) { 372 if (!commit_time_.is_null()) {
371 DCHECK_GT(commit_time_, navigation_start_); 373 DCHECK_GT(commit_time_, navigation_start_);
372 time_to_commit = commit_time_ - navigation_start_; 374 time_to_commit = commit_time_ - navigation_start_;
373 } else { 375 } else {
374 DCHECK(commit_time_.is_null()); 376 DCHECK(commit_time_.is_null());
375 } 377 }
376 return PageLoadExtraInfo(first_background_time, first_foreground_time, 378 return PageLoadExtraInfo(
377 started_in_foreground_, 379 first_background_time, first_foreground_time, started_in_foreground_,
378 commit_time_.is_null() ? GURL() : url_, 380 commit_time_.is_null() ? GURL() : url_, time_to_commit, abort_type_,
379 time_to_commit, abort_type_, time_to_abort); 381 time_to_abort, metadata_);
380 } 382 }
381 383
382 void PageLoadTracker::NotifyAbort(UserAbortType abort_type, 384 void PageLoadTracker::NotifyAbort(UserAbortType abort_type,
383 base::TimeTicks timestamp) { 385 base::TimeTicks timestamp) {
384 DCHECK_NE(abort_type, ABORT_NONE); 386 DCHECK_NE(abort_type, ABORT_NONE);
385 // Use UpdateAbort to update an already notified PageLoadTracker. 387 // Use UpdateAbort to update an already notified PageLoadTracker.
386 if (abort_type_ != ABORT_NONE) 388 if (abort_type_ != ABORT_NONE)
387 return; 389 return;
388 390
389 UpdateAbortInternal(abort_type, timestamp); 391 UpdateAbortInternal(abort_type, timestamp);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 base::TimeTicks timestamp = new_navigation->NavigationStart(); 673 base::TimeTicks timestamp = new_navigation->NavigationStart();
672 if (last_aborted_load->IsLikelyProvisionalAbort(timestamp)) 674 if (last_aborted_load->IsLikelyProvisionalAbort(timestamp))
673 last_aborted_load->UpdateAbort(ABORT_UNKNOWN_NAVIGATION, timestamp); 675 last_aborted_load->UpdateAbort(ABORT_UNKNOWN_NAVIGATION, timestamp);
674 676
675 aborted_provisional_loads_.clear(); 677 aborted_provisional_loads_.clear();
676 return last_aborted_load; 678 return last_aborted_load;
677 } 679 }
678 680
679 void MetricsWebContentsObserver::OnTimingUpdated( 681 void MetricsWebContentsObserver::OnTimingUpdated(
680 content::RenderFrameHost* render_frame_host, 682 content::RenderFrameHost* render_frame_host,
681 const PageLoadTiming& timing) { 683 const PageLoadTiming& timing,
684 const PageLoadMetadata& metadata) {
682 bool error = false; 685 bool error = false;
683 if (!committed_load_ || !committed_load_->renderer_tracked()) { 686 if (!committed_load_ || !committed_load_->renderer_tracked()) {
684 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); 687 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD);
685 error = true; 688 error = true;
686 } 689 }
687 690
688 // We may receive notifications from frames that have been navigated away 691 // We may receive notifications from frames that have been navigated away
689 // from. We simply ignore them. 692 // from. We simply ignore them.
690 if (render_frame_host != web_contents()->GetMainFrame()) { 693 if (render_frame_host != web_contents()->GetMainFrame()) {
691 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME); 694 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME);
692 error = true; 695 error = true;
693 } 696 }
694 697
695 // For urls like chrome://newtab, the renderer and browser disagree, 698 // For urls like chrome://newtab, the renderer and browser disagree,
696 // so we have to double check that the renderer isn't sending data from a 699 // so we have to double check that the renderer isn't sending data from a
697 // bad url like https://www.google.com/_/chrome/newtab. 700 // bad url like https://www.google.com/_/chrome/newtab.
698 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) { 701 if (!web_contents()->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) {
699 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME); 702 RecordInternalError(ERR_IPC_FROM_BAD_URL_SCHEME);
700 error = true; 703 error = true;
701 } 704 }
702 705
703 if (error) 706 if (error)
704 return; 707 return;
705 708
706 if (!committed_load_->UpdateTiming(timing)) { 709 if (!committed_load_->UpdateTiming(timing, metadata)) {
707 // If the page load tracker cannot update its timing, something is wrong 710 // If the page load tracker cannot update its timing, something is wrong
708 // with the IPC (it's from another load, or it's invalid in some other way). 711 // with the IPC (it's from another load, or it's invalid in some other way).
709 // We expect this to be a rare occurrence. 712 // We expect this to be a rare occurrence.
710 RecordInternalError(ERR_BAD_TIMING_IPC); 713 RecordInternalError(ERR_BAD_TIMING_IPC);
711 } 714 }
712 } 715 }
713 716
714 } // namespace page_load_metrics 717 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698