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 COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ | 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ |
6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ | 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ |
7 | 7 |
8 #include "base/containers/scoped_ptr_map.h" | |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "base/time/time.h" | 10 #include "base/time/time.h" |
10 #include "components/page_load_metrics/common/page_load_timing.h" | 11 #include "components/page_load_metrics/common/page_load_timing.h" |
11 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
12 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/browser/web_contents_user_data.h" | 14 #include "content/public/browser/web_contents_user_data.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 class NavigationHandle; | 17 class NavigationHandle; |
17 class RenderFrameHost; | 18 class RenderFrameHost; |
18 } // namespace content | 19 } // namespace content |
19 | 20 |
20 namespace IPC { | 21 namespace IPC { |
21 class Message; | 22 class Message; |
22 } // namespace IPC | 23 } // namespace IPC |
23 | 24 |
24 namespace page_load_metrics { | 25 namespace page_load_metrics { |
25 | 26 |
27 class PageLoadTracker { | |
28 public: | |
29 PageLoadTracker(bool in_foreground); | |
Bryan McQuade
2015/09/29 00:32:19
nit: single-arg constructor should be explicit
Charlie Harrison
2015/09/29 14:13:07
Done.
| |
30 ~PageLoadTracker(); | |
31 void Commit(); | |
32 void WebContentsHidden(); | |
33 | |
34 // Returns true if the timing was successfully updated. | |
35 bool UpdateTiming(const PageLoadTiming& timing); | |
36 | |
37 private: | |
38 void RecordTimingHistograms(); | |
39 | |
40 bool has_commit_; | |
41 | |
42 // Initialize |background_time_| to TimeDelta::Max() so that we can see if an | |
43 // event happened before a background by a simple < comparison. This will work | |
44 // even if the page was never backgrounded. We record separate metrics for | |
45 // any web contents that have been backgrounded, because metrics like | |
46 // layout/paint are delayed artificially when they occur in the bacground. | |
47 base::Time background_time_; | |
Bryan McQuade
2015/09/29 00:32:19
let's use a TimeTicks here, just to be clear that
Charlie Harrison
2015/09/29 14:13:07
Done.
| |
48 | |
49 PageLoadTiming timing_; | |
50 | |
51 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); | |
52 }; | |
53 | |
26 // MetricsWebContentsObserver logs page load UMA metrics based on | 54 // MetricsWebContentsObserver logs page load UMA metrics based on |
27 // IPC messages received from a MetricsRenderFrameObserver. | 55 // IPC messages received from a MetricsRenderFrameObserver. |
28 class MetricsWebContentsObserver | 56 class MetricsWebContentsObserver |
29 : public content::WebContentsObserver, | 57 : public content::WebContentsObserver, |
30 public content::WebContentsUserData<MetricsWebContentsObserver> { | 58 public content::WebContentsUserData<MetricsWebContentsObserver> { |
31 public: | 59 public: |
32 ~MetricsWebContentsObserver() override; | 60 ~MetricsWebContentsObserver() override; |
33 | 61 |
34 // content::WebContentsObserver implementation: | 62 // content::WebContentsObserver implementation: |
35 bool OnMessageReceived(const IPC::Message& message, | 63 bool OnMessageReceived(const IPC::Message& message, |
36 content::RenderFrameHost* render_frame_host) override; | 64 content::RenderFrameHost* render_frame_host) override; |
37 void DidFinishNavigation( | 65 void DidFinishNavigation( |
38 content::NavigationHandle* navigation_handle) override; | 66 content::NavigationHandle* navigation_handle) override; |
39 void RenderProcessGone(base::TerminationStatus status) override; | 67 void DidStartNavigation( |
Bryan McQuade
2015/09/29 00:32:19
let's move DidStartNavigation's decl above DidFini
Charlie Harrison
2015/09/29 14:13:07
Done.
| |
68 content::NavigationHandle* navigation_handle) override; | |
69 | |
70 void WasShown() override; | |
71 void WasHidden() override; | |
40 | 72 |
41 private: | 73 private: |
42 explicit MetricsWebContentsObserver(content::WebContents* web_contents); | 74 explicit MetricsWebContentsObserver(content::WebContents* web_contents); |
43 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 75 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
44 friend class MetricsWebContentsObserverTest; | 76 friend class MetricsWebContentsObserverTest; |
45 | 77 |
46 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); | 78 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); |
47 void RecordTimingHistograms(); | |
48 | 79 |
49 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle); | 80 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle); |
50 | 81 |
51 // Will be null before any navigations have committed. When a navigation | 82 // True if the web contents is currently in the foreground. |
52 // commits we will initialize this as empty. | 83 bool in_foreground_; |
53 scoped_ptr<PageLoadTiming> current_timing_; | 84 |
85 // This map tracks all of the navigations ongoing that are not committed | |
86 // yet. Once a navigation is committed, it moves from the map to | |
87 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only | |
88 // valid until commit time, when we remove it from the map. | |
89 base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> | |
90 provisional_loads_; | |
91 scoped_ptr<PageLoadTracker> committed_load_; | |
54 | 92 |
55 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 93 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
56 }; | 94 }; |
57 | 95 |
58 } // namespace page_load_metrics | 96 } // namespace page_load_metrics |
59 | 97 |
60 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ | 98 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ |
OLD | NEW |