| 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" | |
| 17 #include "chrome/common/page_load_metrics/page_load_timing.h" | 16 #include "chrome/common/page_load_metrics/page_load_timing.h" |
| 18 #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" |
| 19 #include "content/public/browser/render_widget_host.h" | 18 #include "content/public/browser/render_widget_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/browser/web_contents_binding_set.h" | |
| 22 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 23 #include "content/public/browser/web_contents_user_data.h" | 21 #include "content/public/browser/web_contents_user_data.h" |
| 24 #include "content/public/common/resource_type.h" | 22 #include "content/public/common/resource_type.h" |
| 25 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 23 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 26 | 24 |
| 27 namespace content { | 25 namespace content { |
| 28 class NavigationHandle; | 26 class NavigationHandle; |
| 29 class RenderFrameHost; | 27 class RenderFrameHost; |
| 30 } // namespace content | 28 } // namespace content |
| 31 | 29 |
| 32 namespace IPC { | 30 namespace IPC { |
| 33 class Message; | 31 class Message; |
| 34 } // namespace IPC | 32 } // namespace IPC |
| 35 | 33 |
| 36 namespace page_load_metrics { | 34 namespace page_load_metrics { |
| 37 | 35 |
| 38 class PageLoadMetricsEmbedderInterface; | 36 class PageLoadMetricsEmbedderInterface; |
| 39 class PageLoadTracker; | 37 class PageLoadTracker; |
| 40 | 38 |
| 41 // MetricsWebContentsObserver tracks page loads and loading metrics | 39 // MetricsWebContentsObserver tracks page loads and loading metrics |
| 42 // related data based on IPC messages received from a | 40 // related data based on IPC messages received from a |
| 43 // MetricsRenderFrameObserver. | 41 // MetricsRenderFrameObserver. |
| 44 class MetricsWebContentsObserver | 42 class MetricsWebContentsObserver |
| 45 : public content::WebContentsObserver, | 43 : public content::WebContentsObserver, |
| 46 public content::WebContentsUserData<MetricsWebContentsObserver>, | 44 public content::WebContentsUserData<MetricsWebContentsObserver>, |
| 47 public content::RenderWidgetHost::InputEventObserver, | 45 public content::RenderWidgetHost::InputEventObserver { |
| 48 public mojom::PageLoadMetrics { | |
| 49 public: | 46 public: |
| 50 // TestingObserver allows tests to observe MetricsWebContentsObserver state | 47 // TestingObserver allows tests to observe MetricsWebContentsObserver state |
| 51 // changes. Tests may use TestingObserver to wait until certain state changes, | 48 // changes. Tests may use TestingObserver to wait until certain state changes, |
| 52 // such as the arrivial of PageLoadTiming messages from the render process, | 49 // such as the arrivial of PageLoadTiming messages from the render process, |
| 53 // have been observed. | 50 // have been observed. |
| 54 class TestingObserver { | 51 class TestingObserver { |
| 55 public: | 52 public: |
| 56 enum class IPCType { LEGACY, MOJO }; | |
| 57 | |
| 58 explicit TestingObserver(content::WebContents* web_contents); | 53 explicit TestingObserver(content::WebContents* web_contents); |
| 59 virtual ~TestingObserver(); | 54 virtual ~TestingObserver(); |
| 60 | 55 |
| 61 void OnGoingAway(); | 56 void OnGoingAway(); |
| 62 | 57 |
| 63 // Invoked when a new PageLoadTiming update has been received and processed. | 58 // Invoked when a new PageLoadTiming update has been received and processed. |
| 64 virtual void OnTimingUpdated(bool is_main_frame, | 59 virtual void OnTimingUpdated(bool is_main_frame, |
| 65 const mojom::PageLoadTiming& timing, | 60 const mojom::PageLoadTiming& timing, |
| 66 const mojom::PageLoadMetadata& metadata) {} | 61 const mojom::PageLoadMetadata& metadata) {} |
| 67 | 62 |
| 68 virtual void DidReceiveTimingUpdate(IPCType type) {} | |
| 69 | |
| 70 private: | 63 private: |
| 71 page_load_metrics::MetricsWebContentsObserver* observer_; | 64 page_load_metrics::MetricsWebContentsObserver* observer_; |
| 72 | 65 |
| 73 DISALLOW_COPY_AND_ASSIGN(TestingObserver); | 66 DISALLOW_COPY_AND_ASSIGN(TestingObserver); |
| 74 }; | 67 }; |
| 75 | 68 |
| 76 // Note that the returned metrics is owned by the web contents. | 69 // Note that the returned metrics is owned by the web contents. |
| 77 static MetricsWebContentsObserver* CreateForWebContents( | 70 static MetricsWebContentsObserver* CreateForWebContents( |
| 78 content::WebContents* web_contents, | 71 content::WebContents* web_contents, |
| 79 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); | 72 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 void RemoveTestingObserver(TestingObserver* observer); | 139 void RemoveTestingObserver(TestingObserver* observer); |
| 147 | 140 |
| 148 // public only for testing | 141 // public only for testing |
| 149 void OnTimingUpdated(content::RenderFrameHost* render_frame_host, | 142 void OnTimingUpdated(content::RenderFrameHost* render_frame_host, |
| 150 const mojom::PageLoadTiming& timing, | 143 const mojom::PageLoadTiming& timing, |
| 151 const mojom::PageLoadMetadata& metadata); | 144 const mojom::PageLoadMetadata& metadata); |
| 152 | 145 |
| 153 private: | 146 private: |
| 154 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 147 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
| 155 | 148 |
| 156 // page_load_metrics::mojom::PageLoadMetrics implementation. | |
| 157 void UpdateTiming(mojom::PageLoadTimingPtr timing, | |
| 158 mojom::PageLoadMetadataPtr metadata) override; | |
| 159 | |
| 160 // Called from legacy IPC. | |
| 161 void OnUpdateTimingOverIPC(content::RenderFrameHost* render_frame_host, | |
| 162 const mojom::PageLoadTiming& timing, | |
| 163 const mojom::PageLoadMetadata& metadata); | |
| 164 | |
| 165 void HandleFailedNavigationForTrackedLoad( | 149 void HandleFailedNavigationForTrackedLoad( |
| 166 content::NavigationHandle* navigation_handle, | 150 content::NavigationHandle* navigation_handle, |
| 167 std::unique_ptr<PageLoadTracker> tracker); | 151 std::unique_ptr<PageLoadTracker> tracker); |
| 168 | 152 |
| 169 void HandleCommittedNavigationForTrackedLoad( | 153 void HandleCommittedNavigationForTrackedLoad( |
| 170 content::NavigationHandle* navigation_handle, | 154 content::NavigationHandle* navigation_handle, |
| 171 std::unique_ptr<PageLoadTracker> tracker); | 155 std::unique_ptr<PageLoadTracker> tracker); |
| 172 | 156 |
| 173 // Return a PageLoadTracker (either provisional or committed) that matches the | 157 // Return a PageLoadTracker (either provisional or committed) that matches the |
| 174 // given request attributes, or nullptr if there are no matching | 158 // given request attributes, or nullptr if there are no matching |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 // and vanish before we get signal about what caused the abort (new | 206 // and vanish before we get signal about what caused the abort (new |
| 223 // navigation, stop button, etc.). | 207 // navigation, stop button, etc.). |
| 224 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; | 208 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; |
| 225 | 209 |
| 226 std::unique_ptr<PageLoadTracker> committed_load_; | 210 std::unique_ptr<PageLoadTracker> committed_load_; |
| 227 | 211 |
| 228 // Has the MWCO observed at least one navigation? | 212 // Has the MWCO observed at least one navigation? |
| 229 bool has_navigated_; | 213 bool has_navigated_; |
| 230 | 214 |
| 231 base::ObserverList<TestingObserver> testing_observers_; | 215 base::ObserverList<TestingObserver> testing_observers_; |
| 232 content::WebContentsFrameBindingSet<mojom::PageLoadMetrics> | |
| 233 page_load_metrics_binding_; | |
| 234 | 216 |
| 235 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 217 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
| 236 }; | 218 }; |
| 237 | 219 |
| 238 } // namespace page_load_metrics | 220 } // namespace page_load_metrics |
| 239 | 221 |
| 240 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ | 222 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_METRICS_WEB_CONTENTS_OBSERVER_H_ |
| OLD | NEW |