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

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

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

Powered by Google App Engine
This is Rietveld 408576698