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/macros.h" | 8 #include "base/macros.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "components/page_load_metrics/common/page_load_timing.h" | 10 #include "components/page_load_metrics/common/page_load_timing.h" |
11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | |
16 class NavigationHandle; | 17 class NavigationHandle; |
17 class RenderFrameHost; | 18 class RenderFrameHost; |
19 | |
18 } // namespace content | 20 } // namespace content |
19 | 21 |
20 namespace IPC { | 22 namespace IPC { |
23 | |
21 class Message; | 24 class Message; |
25 | |
22 } // namespace IPC | 26 } // namespace IPC |
23 | 27 |
24 namespace page_load_metrics { | 28 namespace page_load_metrics { |
25 | 29 |
30 class PageLoadTracker { | |
31 public: | |
32 PageLoadTracker(content::NavigationHandle* navigation_handle, | |
Bryan McQuade
2015/09/24 15:14:11
one concern with holding on to a NavigationHandle
Charlie Harrison
2015/09/24 15:48:21
In this case, we don't know that an in-page is rea
| |
33 bool in_foreground); | |
34 ~PageLoadTracker(); | |
35 content::NavigationHandle* NavigationHandle() { return navigation_handle_; } | |
36 void Commit(); | |
37 void Finish(); | |
Bryan McQuade
2015/09/24 15:14:11
I know the term 'finish' is used in the WCO API bu
| |
38 void WebContentsHidden(); | |
39 | |
40 // Returns true if the timing was successfully updated. | |
41 bool UpdateTiming(const PageLoadTiming& timing); | |
42 void RecordTimingHistograms(); | |
43 | |
44 private: | |
45 bool has_commit_; | |
46 bool has_finished_; | |
47 | |
48 // This tracks the navigation handle until it gets committed. This class | |
49 // persists the notion of that committed navigation until the load completes. | |
50 // Note that after commit, this pointer is invalid. | |
51 content::NavigationHandle* navigation_handle_; | |
Bryan McQuade
2015/09/24 15:14:11
if you don't expect this value to change after con
Charlie Harrison
2015/09/24 15:48:21
Done.
| |
52 | |
53 // True if the web contents stayed in the foreground for the entire | |
54 // page load. We record separate metrics for any web contents that have been | |
55 // backgrounded, because metrics like layout/paint are delayed artificially | |
56 // when they occur in the bacground. | |
57 bool page_load_stayed_in_foreground_; | |
58 | |
59 PageLoadTiming timing_; | |
Bryan McQuade
2015/09/24 15:14:11
should add DISALLOW_COPY_AND_ASSIGN(PageLoadTracke
Charlie Harrison
2015/09/24 15:48:21
Done.
| |
60 }; | |
61 | |
26 // MetricsWebContentsObserver logs page load UMA metrics based on | 62 // MetricsWebContentsObserver logs page load UMA metrics based on |
27 // IPC messages received from a MetricsRenderFrameObserver. | 63 // IPC messages received from a MetricsRenderFrameObserver. |
28 class MetricsWebContentsObserver | 64 class MetricsWebContentsObserver |
29 : public content::WebContentsObserver, | 65 : public content::WebContentsObserver, |
30 public content::WebContentsUserData<MetricsWebContentsObserver> { | 66 public content::WebContentsUserData<MetricsWebContentsObserver> { |
31 public: | 67 public: |
32 ~MetricsWebContentsObserver() override; | 68 ~MetricsWebContentsObserver() override; |
33 | 69 |
34 // content::WebContentsObserver implementation: | 70 // content::WebContentsObserver implementation: |
35 bool OnMessageReceived(const IPC::Message& message, | 71 bool OnMessageReceived(const IPC::Message& message, |
36 content::RenderFrameHost* render_frame_host) override; | 72 content::RenderFrameHost* render_frame_host) override; |
37 void DidCommitNavigation( | 73 void DidCommitNavigation( |
38 content::NavigationHandle* navigation_handle) override; | 74 content::NavigationHandle* navigation_handle) override; |
39 void RenderProcessGone(base::TerminationStatus status) override; | 75 void DidStartNavigation( |
76 content::NavigationHandle* navigation_handle) override; | |
77 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | |
Bryan McQuade
2015/09/24 15:14:11
related to above comment, let's add a comment expl
| |
78 const GURL& validated_url) override; | |
79 void DidFailLoad(content::RenderFrameHost* render_frame_host, | |
80 const GURL& validated_url, | |
81 int error_code, | |
82 const base::string16& error_description, | |
83 bool was_ignored_by_handler) override; | |
84 | |
85 void WasShown() override; | |
86 void WasHidden() override; | |
40 | 87 |
41 private: | 88 private: |
42 explicit MetricsWebContentsObserver(content::WebContents* web_contents); | 89 explicit MetricsWebContentsObserver(content::WebContents* web_contents); |
43 friend class content::WebContentsUserData<MetricsWebContentsObserver>; | 90 friend class content::WebContentsUserData<MetricsWebContentsObserver>; |
44 friend class MetricsWebContentsObserverTest; | 91 friend class MetricsWebContentsObserverTest; |
45 | 92 |
46 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); | 93 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); |
47 void RecordTimingHistograms(); | |
48 | 94 |
49 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle); | 95 bool IsRelevantNavigation(content::NavigationHandle* navigation_handle); |
50 | 96 |
51 // Will be null before any navigations have committed. When a navigation | 97 // True if the web contents is currently in the foreground. |
52 // commits we will initialize this as empty. | 98 bool in_foreground_; |
53 scoped_ptr<PageLoadTiming> current_timing_; | 99 |
100 // This vector tracks all of the navigations ongoing that are not committed | |
101 // yet. Once a navigation is committed, it moves from the vector to | |
102 // committed_load_. | |
103 std::vector<PageLoadTracker> provisional_loads_; | |
104 scoped_ptr<PageLoadTracker> committed_load_; | |
54 | 105 |
55 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); | 106 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); |
56 }; | 107 }; |
57 | 108 |
58 } // namespace page_load_metrics | 109 } // namespace page_load_metrics |
59 | 110 |
60 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ | 111 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ |
OLD | NEW |