| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 137 |
| 134 // Register / unregister TestingObservers. Should only be called from tests. | 138 // Register / unregister TestingObservers. Should only be called from tests. |
| 135 void AddTestingObserver(TestingObserver* observer); | 139 void AddTestingObserver(TestingObserver* observer); |
| 136 void RemoveTestingObserver(TestingObserver* observer); | 140 void RemoveTestingObserver(TestingObserver* observer); |
| 137 | 141 |
| 138 // public only for testing | 142 // public only for testing |
| 139 void OnTimingUpdated(content::RenderFrameHost* render_frame_host, | 143 void OnTimingUpdated(content::RenderFrameHost* render_frame_host, |
| 140 const PageLoadTiming& timing, | 144 const PageLoadTiming& timing, |
| 141 const PageLoadMetadata& metadata); | 145 const PageLoadMetadata& metadata); |
| 142 | 146 |
| 147 content::WebContentsFrameBindingSet<mojom::PageLoadMetrics>& |
| 148 page_load_metrics_binding_for_testing() { |
| 149 return page_load_metrics_binding_; |
| 150 } |
| 151 |
| 143 private: | 152 private: |
| 144 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 153 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
| 154 friend class FakePageLoadMetrics; |
| 155 friend class MetricsWebContentsObserverTest; |
| 156 friend class PageLoadMetricsObserverTestHarness; |
| 157 |
| 158 // page_load_metrics::mojom::PageLoadMetrics implementation. |
| 159 void UpdateTiming(const PageLoadTiming& timing, |
| 160 const PageLoadMetadata& metadata) override; |
| 145 | 161 |
| 146 void HandleFailedNavigationForTrackedLoad( | 162 void HandleFailedNavigationForTrackedLoad( |
| 147 content::NavigationHandle* navigation_handle, | 163 content::NavigationHandle* navigation_handle, |
| 148 std::unique_ptr<PageLoadTracker> tracker); | 164 std::unique_ptr<PageLoadTracker> tracker); |
| 149 | 165 |
| 150 void HandleCommittedNavigationForTrackedLoad( | 166 void HandleCommittedNavigationForTrackedLoad( |
| 151 content::NavigationHandle* navigation_handle, | 167 content::NavigationHandle* navigation_handle, |
| 152 std::unique_ptr<PageLoadTracker> tracker); | 168 std::unique_ptr<PageLoadTracker> tracker); |
| 153 | 169 |
| 154 // Return a PageLoadTracker (either provisional or committed) that matches the | 170 // Return a PageLoadTracker (either provisional or committed) that matches the |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // and vanish before we get signal about what caused the abort (new | 219 // and vanish before we get signal about what caused the abort (new |
| 204 // navigation, stop button, etc.). | 220 // navigation, stop button, etc.). |
| 205 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; | 221 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; |
| 206 | 222 |
| 207 std::unique_ptr<PageLoadTracker> committed_load_; | 223 std::unique_ptr<PageLoadTracker> committed_load_; |
| 208 | 224 |
| 209 // Has the MWCO observed at least one navigation? | 225 // Has the MWCO observed at least one navigation? |
| 210 bool has_navigated_; | 226 bool has_navigated_; |
| 211 | 227 |
| 212 base::ObserverList<TestingObserver> testing_observers_; | 228 base::ObserverList<TestingObserver> testing_observers_; |
| 229 content::WebContentsFrameBindingSet<mojom::PageLoadMetrics> |
| 230 page_load_metrics_binding_; |
| 213 | 231 |
| 214 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 232 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
| 215 }; | 233 }; |
| 216 | 234 |
| 217 } // namespace page_load_metrics | 235 } // namespace page_load_metrics |
| 218 | 236 |
| 219 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ | 237 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ |
| OLD | NEW |