OLD | NEW |
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 "content/public/browser/render_widget_host.h" | 17 #include "content/public/browser/render_widget_host.h" |
17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_contents_binding_set.h" |
18 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
19 #include "content/public/browser/web_contents_user_data.h" | 21 #include "content/public/browser/web_contents_user_data.h" |
20 #include "content/public/common/resource_type.h" | 22 #include "content/public/common/resource_type.h" |
| 23 #include "mojo/public/cpp/bindings/binding_set.h" |
21 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 24 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
22 | 25 |
23 namespace content { | 26 namespace content { |
24 class NavigationHandle; | 27 class NavigationHandle; |
25 class RenderFrameHost; | 28 class RenderFrameHost; |
26 } // namespace content | 29 } // namespace content |
27 | 30 |
28 namespace IPC { | 31 namespace IPC { |
29 class Message; | 32 class Message; |
30 } // namespace IPC | 33 } // namespace IPC |
31 | 34 |
32 namespace page_load_metrics { | 35 namespace page_load_metrics { |
33 | 36 |
34 class PageLoadMetricsEmbedderInterface; | 37 class PageLoadMetricsEmbedderInterface; |
35 class PageLoadTracker; | 38 class PageLoadTracker; |
36 | 39 |
37 // MetricsWebContentsObserver tracks page loads and loading metrics | 40 // MetricsWebContentsObserver tracks page loads and loading metrics |
38 // related data based on IPC messages received from a | 41 // related data based on IPC messages received from a |
39 // MetricsRenderFrameObserver. | 42 // MetricsRenderFrameObserver. |
40 class MetricsWebContentsObserver | 43 class MetricsWebContentsObserver |
41 : public content::WebContentsObserver, | 44 : public content::WebContentsObserver, |
42 public content::WebContentsUserData<MetricsWebContentsObserver>, | 45 public content::WebContentsUserData<MetricsWebContentsObserver>, |
43 public content::RenderWidgetHost::InputEventObserver { | 46 public content::RenderWidgetHost::InputEventObserver, |
| 47 public mojom::PageLoadMetrics { |
44 public: | 48 public: |
45 // Note that the returned metrics is owned by the web contents. | 49 // Note that the returned metrics is owned by the web contents. |
46 static MetricsWebContentsObserver* CreateForWebContents( | 50 static MetricsWebContentsObserver* CreateForWebContents( |
47 content::WebContents* web_contents, | 51 content::WebContents* web_contents, |
48 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); | 52 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); |
49 MetricsWebContentsObserver( | 53 MetricsWebContentsObserver( |
50 content::WebContents* web_contents, | 54 content::WebContents* web_contents, |
51 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); | 55 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); |
52 ~MetricsWebContentsObserver() override; | 56 ~MetricsWebContentsObserver() override; |
53 | 57 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 97 |
94 // Flush any buffered metrics, as part of the metrics subsystem persisting | 98 // Flush any buffered metrics, as part of the metrics subsystem persisting |
95 // metrics as the application goes into the background. The application may be | 99 // metrics as the application goes into the background. The application may be |
96 // killed at any time after this method is invoked without further | 100 // killed at any time after this method is invoked without further |
97 // notification. | 101 // notification. |
98 void FlushMetricsOnAppEnterBackground(); | 102 void FlushMetricsOnAppEnterBackground(); |
99 | 103 |
100 // This getter function is required for testing. | 104 // This getter function is required for testing. |
101 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad(); | 105 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad(); |
102 | 106 |
| 107 content::WebContentsFrameBindingSet<mojom::PageLoadMetrics>& |
| 108 page_load_metrics_binding_for_testing() { |
| 109 return page_load_metrics_binding_; |
| 110 } |
| 111 |
103 private: | 112 private: |
104 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 113 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
105 | 114 |
| 115 // page_load_metrics::mojom::PageLoadMetrics implementation. |
| 116 void UpdateTiming(const PageLoadTiming& timing, |
| 117 const PageLoadMetadata& metadata) override; |
| 118 |
106 void HandleFailedNavigationForTrackedLoad( | 119 void HandleFailedNavigationForTrackedLoad( |
107 content::NavigationHandle* navigation_handle, | 120 content::NavigationHandle* navigation_handle, |
108 std::unique_ptr<PageLoadTracker> tracker); | 121 std::unique_ptr<PageLoadTracker> tracker); |
109 | 122 |
110 void HandleCommittedNavigationForTrackedLoad( | 123 void HandleCommittedNavigationForTrackedLoad( |
111 content::NavigationHandle* navigation_handle, | 124 content::NavigationHandle* navigation_handle, |
112 std::unique_ptr<PageLoadTracker> tracker); | 125 std::unique_ptr<PageLoadTracker> tracker); |
113 | 126 |
114 // Return a PageLoadTracker (either provisional or committed) that matches the | 127 // Return a PageLoadTracker (either provisional or committed) that matches the |
115 // given request attributes, or nullptr if there are no matching | 128 // given request attributes, or nullptr if there are no matching |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // navigation failed. This is because most provisional loads are destroyed | 179 // navigation failed. This is because most provisional loads are destroyed |
167 // and vanish before we get signal about what caused the abort (new | 180 // and vanish before we get signal about what caused the abort (new |
168 // navigation, stop button, etc.). | 181 // navigation, stop button, etc.). |
169 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; | 182 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; |
170 | 183 |
171 std::unique_ptr<PageLoadTracker> committed_load_; | 184 std::unique_ptr<PageLoadTracker> committed_load_; |
172 | 185 |
173 // Has the MWCO observed at least one navigation? | 186 // Has the MWCO observed at least one navigation? |
174 bool has_navigated_; | 187 bool has_navigated_; |
175 | 188 |
| 189 content::WebContentsFrameBindingSet<mojom::PageLoadMetrics> |
| 190 page_load_metrics_binding_; |
| 191 |
176 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 192 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
177 }; | 193 }; |
178 | 194 |
179 } // namespace page_load_metrics | 195 } // namespace page_load_metrics |
180 | 196 |
181 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ | 197 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ |
OLD | NEW |