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

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

Issue 2056153002: Convert PageLoadMetrics to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gyp build deps Created 4 years, 5 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 COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_
6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_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 "components/page_load_metrics/browser/page_load_metrics_observer.h" 14 #include "components/page_load_metrics/browser/page_load_metrics_observer.h"
15 #include "components/page_load_metrics/common/page_load_metrics.mojom.h"
15 #include "components/page_load_metrics/common/page_load_timing.h" 16 #include "components/page_load_metrics/common/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"
18 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
19 #include "content/public/browser/web_contents_user_data.h" 20 #include "content/public/browser/web_contents_user_data.h"
21 #include "mojo/public/cpp/bindings/binding.h"
20 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
21 #include "third_party/WebKit/public/web/WebInputEvent.h" 23 #include "third_party/WebKit/public/web/WebInputEvent.h"
22 24
23 namespace content { 25 namespace content {
24 class NavigationHandle; 26 class NavigationHandle;
25 class RenderFrameHost; 27 class RenderFrameHost;
26 } // namespace content 28 } // namespace content
27 29
28 namespace IPC { 30 namespace IPC {
29 class Message; 31 class Message;
30 } // namespace IPC 32 } // namespace IPC
31 33
32 namespace page_load_metrics { 34 namespace page_load_metrics {
33 35
36 class MetricsWebContentsObserver;
34 class PageLoadTracker; 37 class PageLoadTracker;
35 38
36 namespace internal { 39 namespace internal {
37 40
38 extern const char kErrorEvents[]; 41 extern const char kErrorEvents[];
39 extern const char kAbortChainSizeReload[]; 42 extern const char kAbortChainSizeReload[];
40 extern const char kAbortChainSizeForwardBack[]; 43 extern const char kAbortChainSizeForwardBack[];
41 extern const char kAbortChainSizeNewNavigation[]; 44 extern const char kAbortChainSizeNewNavigation[];
42 extern const char kAbortChainSizeNoCommit[]; 45 extern const char kAbortChainSizeNoCommit[];
43 extern const char kAbortChainSizeSameURL[]; 46 extern const char kAbortChainSizeSameURL[];
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 const int aborted_chain_size_same_url_; 250 const int aborted_chain_size_same_url_;
248 251
249 // Interface to chrome features. Must outlive the class. 252 // Interface to chrome features. Must outlive the class.
250 PageLoadMetricsEmbedderInterface* const embedder_interface_; 253 PageLoadMetricsEmbedderInterface* const embedder_interface_;
251 254
252 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_; 255 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_;
253 256
254 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); 257 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker);
255 }; 258 };
256 259
260 class PageLoadMetricsImpl : public mojom::PageLoadMetrics {
Sam McNally 2016/07/07 05:10:48 Can you move this definition into the .cc file?
tibell 2016/07/08 01:12:53 Done.
261 public:
262 // Does not take ownership of the arguments, which need to outlive this
263 // object.
264 PageLoadMetricsImpl(MetricsWebContentsObserver* observer,
265 content::RenderFrameHost* host);
266 ~PageLoadMetricsImpl() override;
267
268 void Bind(mojo::InterfaceRequest<mojom::PageLoadMetrics> request);
269
270 // mojom::PageLoadMetrics override.
271 void TimingUpdated(const PageLoadTiming& timing,
272 const PageLoadMetadata& metadata) override;
273
274 private:
275 MetricsWebContentsObserver* observer_;
Sam McNally 2016/07/07 05:10:48 const
tibell 2016/07/08 01:12:53 We call OnTimingUpdated, which isn't const.
276 content::RenderFrameHost* host_;
Sam McNally 2016/07/07 05:10:48 const
tibell 2016/07/08 01:12:53 OnTimingUpdated takes a non-const RFH.
277 mojo::Binding<mojom::PageLoadMetrics> binding_;
278
279 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsImpl);
280 };
281
257 // MetricsWebContentsObserver tracks page loads and loading metrics 282 // MetricsWebContentsObserver tracks page loads and loading metrics
258 // related data based on IPC messages received from a 283 // related data based on IPC messages received from a
259 // MetricsRenderFrameObserver. 284 // MetricsRenderFrameObserver.
260 class MetricsWebContentsObserver 285 class MetricsWebContentsObserver
261 : public content::WebContentsObserver, 286 : public content::WebContentsObserver,
262 public content::WebContentsUserData<MetricsWebContentsObserver>, 287 public content::WebContentsUserData<MetricsWebContentsObserver>,
263 public content::RenderWidgetHost::InputEventObserver { 288 public content::RenderWidgetHost::InputEventObserver {
264 public: 289 public:
265 // Note that the returned metrics is owned by the web contents. 290 // Note that the returned metrics is owned by the web contents.
266 static MetricsWebContentsObserver* CreateForWebContents( 291 static MetricsWebContentsObserver* CreateForWebContents(
267 content::WebContents* web_contents, 292 content::WebContents* web_contents,
268 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); 293 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
269 MetricsWebContentsObserver( 294 MetricsWebContentsObserver(
270 content::WebContents* web_contents, 295 content::WebContents* web_contents,
271 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface); 296 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface);
272 ~MetricsWebContentsObserver() override; 297 ~MetricsWebContentsObserver() override;
273 298
274 // content::WebContentsObserver implementation: 299 // content::WebContentsObserver implementation:
275 bool OnMessageReceived(const IPC::Message& message, 300 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
276 content::RenderFrameHost* render_frame_host) override; 301 void RenderFrameHostChanged(content::RenderFrameHost* old_host,
302 content::RenderFrameHost* new_host) override;
303 void WebContentsDestroyed() override;
277 void DidStartNavigation( 304 void DidStartNavigation(
278 content::NavigationHandle* navigation_handle) override; 305 content::NavigationHandle* navigation_handle) override;
279 void DidFinishNavigation( 306 void DidFinishNavigation(
280 content::NavigationHandle* navigation_handle) override; 307 content::NavigationHandle* navigation_handle) override;
281 void DidRedirectNavigation( 308 void DidRedirectNavigation(
282 content::NavigationHandle* navigation_handle) override; 309 content::NavigationHandle* navigation_handle) override;
283 void NavigationStopped() override; 310 void NavigationStopped() override;
284 void OnInputEvent(const blink::WebInputEvent& event) override; 311 void OnInputEvent(const blink::WebInputEvent& event) override;
285 void WasShown() override; 312 void WasShown() override;
286 void WasHidden() override; 313 void WasHidden() override;
287 void RenderProcessGone(base::TerminationStatus status) override; 314 void RenderProcessGone(base::TerminationStatus status) override;
288 void RenderViewHostChanged(content::RenderViewHost* old_host, 315 void RenderViewHostChanged(content::RenderViewHost* old_host,
289 content::RenderViewHost* new_host) override; 316 content::RenderViewHost* new_host) override;
290 317
291 // This getter function is required for testing. 318 // This getter function is required for testing.
292 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad(); 319 const PageLoadExtraInfo GetPageLoadExtraInfoForCommittedLoad();
293 320
321 // Exposed for testing.
322 void OnTimingUpdated(content::RenderFrameHost*,
323 const PageLoadTiming& timing,
324 const PageLoadMetadata& metadata);
325
294 private: 326 private:
295 friend class content::WebContentsUserData<MetricsWebContentsObserver>; 327 friend class content::WebContentsUserData<MetricsWebContentsObserver>;
328 friend class MetricsWebContentsObserverTest;
296 329
297 // Notify all loads, provisional and committed, that we performed an action 330 // Notify all loads, provisional and committed, that we performed an action
298 // that might abort them. 331 // that might abort them.
299 void NotifyAbortAllLoads(UserAbortType abort_type); 332 void NotifyAbortAllLoads(UserAbortType abort_type);
300 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type, 333 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type,
301 base::TimeTicks timestamp, 334 base::TimeTicks timestamp,
302 bool is_certainly_browser_timestamp); 335 bool is_certainly_browser_timestamp);
303 336
304 // Register / Unregister input event callback to given RenderViewHost 337 // Register / Unregister input event callback to given RenderViewHost
305 void RegisterInputEventObserver(content::RenderViewHost* host); 338 void RegisterInputEventObserver(content::RenderViewHost* host);
306 void UnregisterInputEventObserver(content::RenderViewHost* host); 339 void UnregisterInputEventObserver(content::RenderViewHost* host);
307 340
308 // Notify aborted provisional loads that a new navigation occurred. This is 341 // Notify aborted provisional loads that a new navigation occurred. This is
309 // used for more consistent attribution tracking for aborted provisional 342 // used for more consistent attribution tracking for aborted provisional
310 // loads. This method returns the provisional load that was likely aborted 343 // loads. This method returns the provisional load that was likely aborted
311 // by this navigation, to help instantiate the new PageLoadTracker. 344 // by this navigation, to help instantiate the new PageLoadTracker.
312 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation( 345 std::unique_ptr<PageLoadTracker> NotifyAbortedProvisionalLoadsNewNavigation(
313 content::NavigationHandle* new_navigation); 346 content::NavigationHandle* new_navigation);
314 347
315 void OnTimingUpdated(content::RenderFrameHost*, 348 // Create and register a new PageLoadMetricsImpl, listening for messages to
316 const PageLoadTiming& timing, 349 // |host|.
317 const PageLoadMetadata& metadata); 350 void CreateRegisteredInterface(content::RenderFrameHost* host);
318 351
319 // True if the web contents is currently in the foreground. 352 // True if the web contents is currently in the foreground.
320 bool in_foreground_; 353 bool in_foreground_;
321 354
322 // The PageLoadTrackers must be deleted before the |embedded_interface_|, 355 // The PageLoadTrackers must be deleted before the |embedded_interface_|,
323 // because they hold a pointer to the |embedder_interface_|. 356 // because they hold a pointer to the |embedder_interface_|.
324 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; 357 std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_;
325 358
326 // This map tracks all of the navigations ongoing that are not committed 359 // This map tracks all of the navigations ongoing that are not committed
327 // yet. Once a navigation is committed, it moves from the map to 360 // yet. Once a navigation is committed, it moves from the map to
328 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only 361 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only
329 // valid until commit time, when we remove it from the map. 362 // valid until commit time, when we remove it from the map.
330 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>> 363 std::map<content::NavigationHandle*, std::unique_ptr<PageLoadTracker>>
331 provisional_loads_; 364 provisional_loads_;
332 365
333 // Tracks aborted provisional loads for a little bit longer than usual (one 366 // Tracks aborted provisional loads for a little bit longer than usual (one
334 // more navigation commit at the max), in order to better understand how the 367 // more navigation commit at the max), in order to better understand how the
335 // navigation failed. This is because most provisional loads are destroyed 368 // navigation failed. This is because most provisional loads are destroyed
336 // and vanish before we get signal about what caused the abort (new 369 // and vanish before we get signal about what caused the abort (new
337 // navigation, stop button, etc.). 370 // navigation, stop button, etc.).
338 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_; 371 std::vector<std::unique_ptr<PageLoadTracker>> aborted_provisional_loads_;
339 372
340 std::unique_ptr<PageLoadTracker> committed_load_; 373 std::unique_ptr<PageLoadTracker> committed_load_;
341 374
342 // Has the MWCO observed at least one navigation? 375 // Has the MWCO observed at least one navigation?
343 bool has_navigated_; 376 bool has_navigated_;
344 377
378 // Interface implementations we need to delete.
379 std::vector<std::unique_ptr<PageLoadMetricsImpl>> registered_interfaces_;
380
345 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); 381 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
346 }; 382 };
347 383
348 } // namespace page_load_metrics 384 } // namespace page_load_metrics
349 385
350 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_ 386 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_METRICS_WEB_CONTENTS_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698