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

Side by Side Diff: chrome/renderer/page_load_metrics/metrics_render_frame_observer.cc

Issue 2823523003: [Page Load Metrics] PageLoadMetrics Mojofication. (Closed)
Patch Set: Add Finch trial check and rebase 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
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/renderer/page_load_metrics/metrics_render_frame_observer.h" 5 #include "chrome/renderer/page_load_metrics/metrics_render_frame_observer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "base/timer/timer.h" 11 #include "base/timer/timer.h"
12 #include "chrome/renderer/page_load_metrics/page_timing_metrics_sender.h" 12 #include "chrome/renderer/page_load_metrics/page_timing_metrics_sender.h"
13 #include "chrome/renderer/page_load_metrics/renderer_page_track_decider.h" 13 #include "chrome/renderer/page_load_metrics/renderer_page_track_decider.h"
14 #include "chrome/renderer/searchbox/search_bouncer.h" 14 #include "chrome/renderer/searchbox/search_bouncer.h"
15 #include "content/public/common/associated_interface_provider.h"
15 #include "content/public/renderer/render_frame.h" 16 #include "content/public/renderer/render_frame.h"
16 #include "third_party/WebKit/public/web/WebDataSource.h" 17 #include "third_party/WebKit/public/web/WebDataSource.h"
17 #include "third_party/WebKit/public/web/WebDocument.h" 18 #include "third_party/WebKit/public/web/WebDocument.h"
18 #include "third_party/WebKit/public/web/WebLocalFrame.h" 19 #include "third_party/WebKit/public/web/WebLocalFrame.h"
19 #include "third_party/WebKit/public/web/WebPerformance.h" 20 #include "third_party/WebKit/public/web/WebPerformance.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 namespace page_load_metrics { 23 namespace page_load_metrics {
23 24
24 namespace { 25 namespace {
25 26
26 base::TimeDelta ClampDelta(double event, double start) { 27 base::TimeDelta ClampDelta(double event, double start) {
27 if (event - start < 0) 28 if (event - start < 0)
28 event = start; 29 event = start;
29 return base::Time::FromDoubleT(event) - base::Time::FromDoubleT(start); 30 return base::Time::FromDoubleT(event) - base::Time::FromDoubleT(start);
30 } 31 }
31 32
32 } // namespace 33 } // namespace
33 34
34 MetricsRenderFrameObserver::MetricsRenderFrameObserver( 35 MetricsRenderFrameObserver::MetricsRenderFrameObserver(
35 content::RenderFrame* render_frame) 36 content::RenderFrame* render_frame)
36 : content::RenderFrameObserver(render_frame) {} 37 : content::RenderFrameObserver(render_frame) {}
37 38
38 MetricsRenderFrameObserver::~MetricsRenderFrameObserver() {} 39 MetricsRenderFrameObserver::~MetricsRenderFrameObserver() {}
39 40
41 void MetricsRenderFrameObserver::SendTiming(const PageLoadTiming& timing,
42 const PageLoadMetadata& metadata) {
43 if (HasNoRenderFrame())
44 return;
45 if (!page_load_metrics_) {
46 render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(
47 &page_load_metrics_);
48 }
49 page_load_metrics_->UpdateTiming(timing, metadata);
Zhen Wang 2017/04/19 18:49:54 Why should MetricsRenderFrameObserver care about s
lpy 2017/04/19 21:05:05 MetricsRenderFrameObserver is IPC::Sender, PageTim
Zhen Wang 2017/04/19 21:52:47 Oh, I see.
50 }
51
40 void MetricsRenderFrameObserver::DidChangePerformanceTiming() { 52 void MetricsRenderFrameObserver::DidChangePerformanceTiming() {
41 // Only track timing metrics for main frames. 53 // Only track timing metrics for main frames.
42 if (IsMainFrame()) 54 if (IsMainFrame())
43 SendMetrics(); 55 SendMetrics();
44 } 56 }
45 57
46 void MetricsRenderFrameObserver::DidObserveLoadingBehavior( 58 void MetricsRenderFrameObserver::DidObserveLoadingBehavior(
47 blink::WebLoadingBehaviorFlag behavior) { 59 blink::WebLoadingBehaviorFlag behavior) {
48 if (page_timing_metrics_sender_) 60 if (page_timing_metrics_sender_)
49 page_timing_metrics_sender_->DidObserveLoadingBehavior(behavior); 61 page_timing_metrics_sender_->DidObserveLoadingBehavior(behavior);
(...skipping 21 matching lines...) Expand all
71 // sending and recording metrics. Once page_timing_metrics_sender_ is 83 // sending and recording metrics. Once page_timing_metrics_sender_ is
72 // non-null, we will send metrics for the current page at some later time, as 84 // non-null, we will send metrics for the current page at some later time, as
73 // those metrics become available. 85 // those metrics become available.
74 if (ShouldSendMetrics()) { 86 if (ShouldSendMetrics()) {
75 PageLoadTiming timing; 87 PageLoadTiming timing;
76 if (IsMainFrame()) { 88 if (IsMainFrame()) {
77 // Only populate PageLoadTiming for the main frame. 89 // Only populate PageLoadTiming for the main frame.
78 timing = GetTiming(); 90 timing = GetTiming();
79 DCHECK(!timing.navigation_start.is_null()); 91 DCHECK(!timing.navigation_start.is_null());
80 } 92 }
81 page_timing_metrics_sender_.reset( 93 page_timing_metrics_sender_.reset(new PageTimingMetricsSender(
82 new PageTimingMetricsSender(this, routing_id(), CreateTimer(), timing)); 94 this, routing_id(), this, CreateTimer(), timing));
83 } 95 }
84 } 96 }
85 97
86 void MetricsRenderFrameObserver::SendMetrics() { 98 void MetricsRenderFrameObserver::SendMetrics() {
87 if (!page_timing_metrics_sender_) 99 if (!page_timing_metrics_sender_)
88 return; 100 return;
89 if (HasNoRenderFrame()) 101 if (HasNoRenderFrame())
90 return; 102 return;
91 PageLoadTiming timing(GetTiming()); 103 PageLoadTiming timing(GetTiming());
92 page_timing_metrics_sender_->Send(timing); 104 page_timing_metrics_sender_->Send(timing);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 195
184 void MetricsRenderFrameObserver::OnDestruct() { 196 void MetricsRenderFrameObserver::OnDestruct() {
185 delete this; 197 delete this;
186 } 198 }
187 199
188 bool MetricsRenderFrameObserver::IsMainFrame() const { 200 bool MetricsRenderFrameObserver::IsMainFrame() const {
189 return render_frame()->IsMainFrame(); 201 return render_frame()->IsMainFrame();
190 } 202 }
191 203
192 } // namespace page_load_metrics 204 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698