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

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

Issue 2823523003: [Page Load Metrics] PageLoadMetrics Mojofication. (Closed)
Patch Set: Addressed comments, remove unnecessary RunUntilIdle, call OnTimingUpdated directly in unit tests Created 3 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 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ 5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_
6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" 14 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
15 #include "chrome/common/page_load_metrics/page_load_metrics.mojom.h"
15 #include "chrome/common/page_load_metrics/page_load_timing.h" 16 #include "chrome/common/page_load_metrics/page_load_timing.h"
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h"
17 #include "content/public/browser/render_widget_host.h" 18 #include "content/public/browser/render_widget_host.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/browser/web_contents_binding_set.h"
19 #include "content/public/browser/web_contents_observer.h" 21 #include "content/public/browser/web_contents_observer.h"
20 #include "content/public/browser/web_contents_user_data.h" 22 #include "content/public/browser/web_contents_user_data.h"
21 #include "content/public/common/resource_type.h" 23 #include "content/public/common/resource_type.h"
24 #include "mojo/public/cpp/bindings/binding_set.h"
22 #include "third_party/WebKit/public/platform/WebInputEvent.h" 25 #include "third_party/WebKit/public/platform/WebInputEvent.h"
23 26
24 namespace content { 27 namespace content {
25 class NavigationHandle; 28 class NavigationHandle;
26 class RenderFrameHost; 29 class RenderFrameHost;
27 } // namespace content 30 } // namespace content
28 31
29 namespace IPC { 32 namespace IPC {
30 class Message; 33 class Message;
31 } // namespace IPC 34 } // namespace IPC
32 35
33 namespace page_load_metrics { 36 namespace page_load_metrics {
34 37
35 class PageLoadMetricsEmbedderInterface; 38 class PageLoadMetricsEmbedderInterface;
36 class PageLoadTracker; 39 class PageLoadTracker;
37 40
38 // MetricsWebContentsObserver tracks page loads and loading metrics 41 // MetricsWebContentsObserver tracks page loads and loading metrics
39 // related data based on IPC messages received from a 42 // related data based on IPC messages received from a
40 // MetricsRenderFrameObserver. 43 // MetricsRenderFrameObserver.
41 class MetricsWebContentsObserver 44 class MetricsWebContentsObserver
42 : public content::WebContentsObserver, 45 : public content::WebContentsObserver,
43 public content::WebContentsUserData<MetricsWebContentsObserver>, 46 public content::WebContentsUserData<MetricsWebContentsObserver>,
44 public content::RenderWidgetHost::InputEventObserver { 47 public content::RenderWidgetHost::InputEventObserver,
48 public mojom::PageLoadMetrics {
45 public: 49 public:
46 // Note that the returned metrics is owned by the web contents. 50 // Note that the returned metrics is owned by the web contents.
47 static MetricsWebContentsObserver* CreateForWebContents( 51 static MetricsWebContentsObserver* CreateForWebContents(
48 content::WebContents* web_contents, 52 content::WebContents* web_contents,
49 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); 53 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
50 MetricsWebContentsObserver( 54 MetricsWebContentsObserver(
51 content::WebContents* web_contents, 55 content::WebContents* web_contents,
52 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); 56 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
53 ~MetricsWebContentsObserver() override; 57 ~MetricsWebContentsObserver() override;
54 58
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 106
103 // Flush any buffered metrics, as part of the metrics subsystem persisting 107 // Flush any buffered metrics, as part of the metrics subsystem persisting
104 // metrics as the application goes into the background. The application may be 108 // metrics as the application goes into the background. The application may be
105 // killed at any time after this method is invoked without further 109 // killed at any time after this method is invoked without further
106 // notification. 110 // notification.
107 void FlushMetricsOnAppEnterBackground(); 111 void FlushMetricsOnAppEnterBackground();
108 112
109 // This getter function is required for testing. 113 // This getter function is required for testing.
110 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad(); 114 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad();
111 115
116 content::WebContentsFrameBindingSet<mojom::PageLoadMetrics>&
117 page_load_metrics_binding_for_testing() {
118 return page_load_metrics_binding_;
119 }
120
112 private: 121 private:
113 friend class content::WebContentsUserData<MetricsWebContentsObserver>; 122 friend class content::WebContentsUserData<MetricsWebContentsObserver>;
123 friend class FakePageLoadMetrics;
124 friend class MetricsWebContentsObserverTest;
125 friend class PageLoadMetricsObserverTestHarness;
126
127 // page_load_metrics::mojom::PageLoadMetrics implementation.
128 void UpdateTiming(const PageLoadTiming& timing,
129 const PageLoadMetadata& metadata) override;
114 130
115 void HandleFailedNavigationForTrackedLoad( 131 void HandleFailedNavigationForTrackedLoad(
116 content::NavigationHandle* navigation_handle, 132 content::NavigationHandle* navigation_handle,
117 std::unique_ptr<PageLoadTracker> tracker); 133 std::unique_ptr<PageLoadTracker> tracker);
118 134
119 void HandleCommittedNavigationForTrackedLoad( 135 void HandleCommittedNavigationForTrackedLoad(
120 content::NavigationHandle* navigation_handle, 136 content::NavigationHandle* navigation_handle,
121 std::unique_ptr<PageLoadTracker> tracker); 137 std::unique_ptr<PageLoadTracker> tracker);
122 138
123 // Return a PageLoadTracker (either provisional or committed) that matches the 139 // Return a PageLoadTracker (either provisional or committed) that matches the
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // navigation failed. This is because most provisional loads are destroyed 191 // navigation failed. This is because most provisional loads are destroyed
176 // and vanish before we get signal about what caused the abort (new 192 // and vanish before we get signal about what caused the abort (new
177 // navigation, stop button, etc.). 193 // navigation, stop button, etc.).
178 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; 194 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_;
179 195
180 std::unique_ptr<PageLoadTracker> committed_load_; 196 std::unique_ptr<PageLoadTracker> committed_load_;
181 197
182 // Has the MWCO observed at least one navigation? 198 // Has the MWCO observed at least one navigation?
183 bool has_navigated_; 199 bool has_navigated_;
184 200
201 content::WebContentsFrameBindingSet<mojom::PageLoadMetrics>
202 page_load_metrics_binding_;
203
185 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); 204 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
186 }; 205 };
187 206
188 } // namespace page_load_metrics 207 } // namespace page_load_metrics
189 208
190 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ 209 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698