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

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

Issue 2804093002: Various page_load_metrics cleanups and improvements (Closed)
Patch Set: address comments Created 3 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
« no previous file with comments | « no previous file | chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <ostream> 8 #include <ostream>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 21 matching lines...) Expand all
32 #include "net/base/net_errors.h" 32 #include "net/base/net_errors.h"
33 #include "ui/base/page_transition_types.h" 33 #include "ui/base/page_transition_types.h"
34 34
35 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
36 page_load_metrics::MetricsWebContentsObserver); 36 page_load_metrics::MetricsWebContentsObserver);
37 37
38 namespace page_load_metrics { 38 namespace page_load_metrics {
39 39
40 namespace { 40 namespace {
41 41
42 content::RenderFrameHost* GetMainFrame(content::RenderFrameHost* rfh) {
43 // Don't use rfh->GetRenderViewHost()->GetMainFrame() here because
44 // RenderViewHost is being deprecated and because in OOPIF,
45 // RenderViewHost::GetMainFrame() returns nullptr for child frames hosted in a
46 // different process from the main frame.
47 while (rfh->GetParent() != nullptr)
48 rfh = rfh->GetParent();
49 return rfh;
50 }
51
42 UserInitiatedInfo CreateUserInitiatedInfo( 52 UserInitiatedInfo CreateUserInitiatedInfo(
43 content::NavigationHandle* navigation_handle, 53 content::NavigationHandle* navigation_handle,
44 PageLoadTracker* committed_load) { 54 PageLoadTracker* committed_load) {
45 if (!navigation_handle->IsRendererInitiated()) 55 if (!navigation_handle->IsRendererInitiated())
46 return UserInitiatedInfo::BrowserInitiated(); 56 return UserInitiatedInfo::BrowserInitiated();
47 57
48 return UserInitiatedInfo::RenderInitiated( 58 return UserInitiatedInfo::RenderInitiated(
49 navigation_handle->HasUserGesture(), 59 navigation_handle->HasUserGesture(),
50 committed_load && 60 committed_load &&
51 committed_load->input_tracker()->FindAndConsumeInputEventsBefore( 61 committed_load->input_tracker()->FindAndConsumeInputEventsBefore(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 content::RenderViewHost* old_host, 110 content::RenderViewHost* old_host,
101 content::RenderViewHost* new_host) { 111 content::RenderViewHost* new_host) {
102 UnregisterInputEventObserver(old_host); 112 UnregisterInputEventObserver(old_host);
103 RegisterInputEventObserver(new_host); 113 RegisterInputEventObserver(new_host);
104 } 114 }
105 115
106 void MetricsWebContentsObserver::MediaStartedPlaying( 116 void MetricsWebContentsObserver::MediaStartedPlaying(
107 const content::WebContentsObserver::MediaPlayerInfo& video_type, 117 const content::WebContentsObserver::MediaPlayerInfo& video_type,
108 const content::WebContentsObserver::MediaPlayerId& id) { 118 const content::WebContentsObserver::MediaPlayerId& id) {
109 content::RenderFrameHost* render_frame_host = id.first; 119 content::RenderFrameHost* render_frame_host = id.first;
110 if (!render_frame_host->GetRenderViewHost() || 120 if (GetMainFrame(render_frame_host) != web_contents()->GetMainFrame()) {
111 render_frame_host->GetRenderViewHost()->GetMainFrame() !=
112 web_contents()->GetMainFrame()) {
113 // Ignore media that starts playing in a document that was navigated away 121 // Ignore media that starts playing in a document that was navigated away
114 // from. 122 // from.
115 return; 123 return;
116 } 124 }
117 if (committed_load_) 125 if (committed_load_)
118 committed_load_->MediaStartedPlaying( 126 committed_load_->MediaStartedPlaying(
119 video_type, render_frame_host == web_contents()->GetMainFrame()); 127 video_type, render_frame_host == web_contents()->GetMainFrame());
120 } 128 }
121 129
122 bool MetricsWebContentsObserver::OnMessageReceived( 130 bool MetricsWebContentsObserver::OnMessageReceived(
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 aborted_provisional_loads_.clear(); 528 aborted_provisional_loads_.clear();
521 return last_aborted_load; 529 return last_aborted_load;
522 } 530 }
523 531
524 void MetricsWebContentsObserver::OnTimingUpdated( 532 void MetricsWebContentsObserver::OnTimingUpdated(
525 content::RenderFrameHost* render_frame_host, 533 content::RenderFrameHost* render_frame_host,
526 const PageLoadTiming& timing, 534 const PageLoadTiming& timing,
527 const PageLoadMetadata& metadata) { 535 const PageLoadMetadata& metadata) {
528 // We may receive notifications from frames that have been navigated away 536 // We may receive notifications from frames that have been navigated away
529 // from. We simply ignore them. 537 // from. We simply ignore them.
530 if (!render_frame_host->GetRenderViewHost() || 538 if (GetMainFrame(render_frame_host) != web_contents()->GetMainFrame()) {
531 render_frame_host->GetRenderViewHost()->GetMainFrame() !=
532 web_contents()->GetMainFrame()) {
533 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME); 539 RecordInternalError(ERR_IPC_FROM_WRONG_FRAME);
534 return; 540 return;
535 } 541 }
536 542
537 // While timings arriving for the wrong frame are expected, we do not expect 543 // While timings arriving for the wrong frame are expected, we do not expect
538 // any of the errors below. Thus, we track occurrences of all errors below, 544 // any of the errors below. Thus, we track occurrences of all errors below,
539 // rather than returning early after encountering an error. 545 // rather than returning early after encountering an error.
540 546
541 bool error = false; 547 bool error = false;
542 if (!committed_load_) { 548 if (!committed_load_) {
(...skipping 11 matching lines...) Expand all
554 560
555 if (render_frame_host->GetParent() != nullptr) { 561 if (render_frame_host->GetParent() != nullptr) {
556 // Child frames may send PageLoadMetadata updates, but not PageLoadTiming 562 // Child frames may send PageLoadMetadata updates, but not PageLoadTiming
557 // updates. 563 // updates.
558 if (!timing.IsEmpty()) 564 if (!timing.IsEmpty())
559 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME); 565 RecordInternalError(ERR_TIMING_IPC_FROM_SUBFRAME);
560 committed_load_->UpdateChildFrameMetadata(metadata); 566 committed_load_->UpdateChildFrameMetadata(metadata);
561 return; 567 return;
562 } 568 }
563 569
564 if (!committed_load_->UpdateTiming(timing, metadata)) { 570 committed_load_->UpdateTiming(timing, metadata);
565 // If the page load tracker cannot update its timing, something is wrong
566 // with the IPC (it's from another load, or it's invalid in some other way).
567 // We expect this to be a rare occurrence.
568 RecordInternalError(ERR_BAD_TIMING_IPC);
569 }
570 } 571 }
571 572
572 bool MetricsWebContentsObserver::ShouldTrackNavigation( 573 bool MetricsWebContentsObserver::ShouldTrackNavigation(
573 content::NavigationHandle* navigation_handle) const { 574 content::NavigationHandle* navigation_handle) const {
574 DCHECK(navigation_handle->IsInMainFrame()); 575 DCHECK(navigation_handle->IsInMainFrame());
575 DCHECK(!navigation_handle->HasCommitted() || 576 DCHECK(!navigation_handle->HasCommitted() ||
576 !navigation_handle->IsSameDocument()); 577 !navigation_handle->IsSameDocument());
577 578
578 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), 579 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(),
579 navigation_handle).ShouldTrack(); 580 navigation_handle).ShouldTrack();
580 } 581 }
581 582
582 } // namespace page_load_metrics 583 } // namespace page_load_metrics
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698