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/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" | 15 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" |
16 #include "chrome/common/page_load_metrics/page_load_metrics.mojom.h" | |
16 #include "chrome/common/page_load_metrics/page_load_timing.h" | 17 #include "chrome/common/page_load_metrics/page_load_timing.h" |
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" | 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" |
18 #include "content/public/browser/render_widget_host.h" | 19 #include "content/public/browser/render_widget_host.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/browser/web_contents_binding_set.h" | |
20 #include "content/public/browser/web_contents_observer.h" | 22 #include "content/public/browser/web_contents_observer.h" |
21 #include "content/public/browser/web_contents_user_data.h" | 23 #include "content/public/browser/web_contents_user_data.h" |
22 #include "content/public/common/resource_type.h" | 24 #include "content/public/common/resource_type.h" |
25 #include "mojo/public/cpp/bindings/binding_set.h" | |
23 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 26 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
24 | 27 |
25 namespace content { | 28 namespace content { |
26 class NavigationHandle; | 29 class NavigationHandle; |
27 class RenderFrameHost; | 30 class RenderFrameHost; |
28 } // namespace content | 31 } // namespace content |
29 | 32 |
30 namespace IPC { | 33 namespace IPC { |
31 class Message; | 34 class Message; |
32 } // namespace IPC | 35 } // namespace IPC |
33 | 36 |
34 namespace page_load_metrics { | 37 namespace page_load_metrics { |
35 | 38 |
36 class PageLoadMetricsEmbedderInterface; | 39 class PageLoadMetricsEmbedderInterface; |
37 class PageLoadTracker; | 40 class PageLoadTracker; |
38 | 41 |
39 // MetricsWebContentsObserver tracks page loads and loading metrics | 42 // MetricsWebContentsObserver tracks page loads and loading metrics |
40 // related data based on IPC messages received from a | 43 // related data based on IPC messages received from a |
41 // MetricsRenderFrameObserver. | 44 // MetricsRenderFrameObserver. |
42 class MetricsWebContentsObserver | 45 class MetricsWebContentsObserver |
43 : public content::WebContentsObserver, | 46 : public content::WebContentsObserver, |
44 public content::WebContentsUserData<MetricsWebContentsObserver>, | 47 public content::WebContentsUserData<MetricsWebContentsObserver>, |
45 public content::RenderWidgetHost::InputEventObserver { | 48 public content::RenderWidgetHost::InputEventObserver, |
49 public mojom::PageLoadMetrics { | |
46 public: | 50 public: |
47 // TestingObserver allows tests to observe MetricsWebContentsObserver state | 51 // TestingObserver allows tests to observe MetricsWebContentsObserver state |
48 // changes. Tests may use TestingObserver to wait until certain state changes, | 52 // changes. Tests may use TestingObserver to wait until certain state changes, |
49 // such as the arrivial of PageLoadTiming messages from the render process, | 53 // such as the arrivial of PageLoadTiming messages from the render process, |
50 // have been observed. | 54 // have been observed. |
51 class TestingObserver { | 55 class TestingObserver { |
52 public: | 56 public: |
53 explicit TestingObserver(content::WebContents* web_contents); | 57 explicit TestingObserver(content::WebContents* web_contents); |
54 virtual ~TestingObserver(); | 58 virtual ~TestingObserver(); |
55 | 59 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 void RemoveTestingObserver(TestingObserver* observer); | 142 void RemoveTestingObserver(TestingObserver* observer); |
139 | 143 |
140 // public only for testing | 144 // public only for testing |
141 void OnTimingUpdated(content::RenderFrameHost* render_frame_host, | 145 void OnTimingUpdated(content::RenderFrameHost* render_frame_host, |
142 const PageLoadTiming& timing, | 146 const PageLoadTiming& timing, |
143 const PageLoadMetadata& metadata); | 147 const PageLoadMetadata& metadata); |
144 | 148 |
145 private: | 149 private: |
146 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 150 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
147 | 151 |
152 // page_load_metrics::mojom::PageLoadMetrics implementation. | |
153 void UpdateTiming(const PageLoadTiming& timing, | |
154 const PageLoadMetadata& metadata) override; | |
155 | |
156 // Called from legacy IPC. | |
157 void OnUpdateTiming(content::RenderFrameHost* render_frame_host, | |
Bryan McQuade
2017/05/08 21:13:29
nit: just to clarify things for readers of the cod
lpy
2017/05/09 17:07:24
Done.
| |
158 const PageLoadTiming& timing, | |
159 const PageLoadMetadata& metadata); | |
160 | |
148 void HandleFailedNavigationForTrackedLoad( | 161 void HandleFailedNavigationForTrackedLoad( |
149 content::NavigationHandle* navigation_handle, | 162 content::NavigationHandle* navigation_handle, |
150 std::unique_ptr<PageLoadTracker> tracker); | 163 std::unique_ptr<PageLoadTracker> tracker); |
151 | 164 |
152 void HandleCommittedNavigationForTrackedLoad( | 165 void HandleCommittedNavigationForTrackedLoad( |
153 content::NavigationHandle* navigation_handle, | 166 content::NavigationHandle* navigation_handle, |
154 std::unique_ptr<PageLoadTracker> tracker); | 167 std::unique_ptr<PageLoadTracker> tracker); |
155 | 168 |
156 // Return a PageLoadTracker (either provisional or committed) that matches the | 169 // Return a PageLoadTracker (either provisional or committed) that matches the |
157 // given request attributes, or nullptr if there are no matching | 170 // given request attributes, or nullptr if there are no matching |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 // and vanish before we get signal about what caused the abort (new | 218 // and vanish before we get signal about what caused the abort (new |
206 // navigation, stop button, etc.). | 219 // navigation, stop button, etc.). |
207 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; | 220 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; |
208 | 221 |
209 std::unique_ptr<PageLoadTracker> committed_load_; | 222 std::unique_ptr<PageLoadTracker> committed_load_; |
210 | 223 |
211 // Has the MWCO observed at least one navigation? | 224 // Has the MWCO observed at least one navigation? |
212 bool has_navigated_; | 225 bool has_navigated_; |
213 | 226 |
214 base::ObserverList<TestingObserver> testing_observers_; | 227 base::ObserverList<TestingObserver> testing_observers_; |
228 content::WebContentsFrameBindingSet<mojom::PageLoadMetrics> | |
229 page_load_metrics_binding_; | |
215 | 230 |
216 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 231 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
217 }; | 232 }; |
218 | 233 |
219 } // namespace page_load_metrics | 234 } // namespace page_load_metrics |
220 | 235 |
221 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ | 236 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ |
OLD | NEW |