OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #if !defined(OS_ANDROID) | 5 #if !defined(OS_ANDROID) |
6 | 6 |
7 #include "chrome/browser/metrics/first_web_contents_profiler.h" | 7 #include "chrome/browser/metrics/first_web_contents_profiler.h" |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "chrome/browser/ui/browser.h" | |
17 #include "chrome/browser/ui/browser_list.h" | |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "components/metrics/profiler/tracking_synchronizer.h" | 19 #include "components/metrics/profiler/tracking_synchronizer.h" |
18 #include "components/metrics/proto/profiler_event.pb.h" | 20 #include "components/metrics/proto/profiler_event.pb.h" |
19 #include "components/startup_metric_utils/browser/startup_metric_utils.h" | 21 #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
20 #include "content/public/browser/navigation_handle.h" | 22 #include "content/public/browser/navigation_handle.h" |
23 #include "content/public/common/browser_side_navigation_policy.h" | |
21 | 24 |
22 void FirstWebContentsProfiler::WebContentsStarted( | 25 // static |
23 content::WebContents* web_contents) { | 26 void FirstWebContentsProfiler::Start() { |
24 static bool first_web_contents_profiled = false; | 27 for (auto* browser : *BrowserList::GetInstance()) { |
25 if (first_web_contents_profiled) | 28 content::WebContents* web_contents = |
26 return; | 29 browser->tab_strip_model()->GetActiveWebContents(); |
27 | 30 if (web_contents) { |
28 first_web_contents_profiled = true; | 31 // FirstWebContentsProfiler owns itself and is also bound to |
29 new FirstWebContentsProfiler(web_contents); | 32 // |web_contents|'s lifetime by observing WebContentsDestroyed(). |
33 new FirstWebContentsProfiler(web_contents); | |
34 return; | |
35 } | |
36 } | |
30 } | 37 } |
31 | 38 |
32 FirstWebContentsProfiler::FirstWebContentsProfiler( | 39 FirstWebContentsProfiler::FirstWebContentsProfiler( |
33 content::WebContents* web_contents) | 40 content::WebContents* web_contents) |
34 : content::WebContentsObserver(web_contents), | 41 : content::WebContentsObserver(web_contents), |
35 collected_paint_metric_(false), | 42 collected_paint_metric_(false), |
36 collected_load_metric_(false), | 43 collected_load_metric_(false), |
37 collected_main_navigation_start_metric_(false), | 44 collected_main_navigation_start_metric_(false), |
38 collected_main_navigation_finished_metric_(false) {} | 45 collected_main_navigation_finished_metric_(false) {} |
39 | 46 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 | 81 |
75 void FirstWebContentsProfiler::DidStartNavigation( | 82 void FirstWebContentsProfiler::DidStartNavigation( |
76 content::NavigationHandle* navigation_handle) { | 83 content::NavigationHandle* navigation_handle) { |
77 if (collected_main_navigation_start_metric_) | 84 if (collected_main_navigation_start_metric_) |
78 return; | 85 return; |
79 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 86 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
80 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 87 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
81 return; | 88 return; |
82 } | 89 } |
83 | 90 |
91 if (content::IsBrowserSideNavigationEnabled()) { | |
92 // With PlzNavigate, DidStartNavigation is called synchronously on | |
93 // browser-initiated loads instead of through an IPC. This means that we | |
94 // will miss this signal. Instead we record it when the commit completes. | |
gab
2016/10/24 19:48:17
Does that mean that DidStartNavigation is invoked
gab
2016/10/24 19:58:15
Ah nvm, read too fast, 139 doesn't record TimeTick
jam
2016/10/24 20:39:43
IMO I don't think this is worth documenting (i.e.
| |
95 return; | |
96 } | |
97 | |
84 // The first navigation has to be the main frame's. | 98 // The first navigation has to be the main frame's. |
85 DCHECK(navigation_handle->IsInMainFrame()); | 99 DCHECK(navigation_handle->IsInMainFrame()); |
86 | 100 |
87 collected_main_navigation_start_metric_ = true; | 101 collected_main_navigation_start_metric_ = true; |
88 startup_metric_utils::RecordFirstWebContentsMainNavigationStart( | 102 startup_metric_utils::RecordFirstWebContentsMainNavigationStart( |
89 base::TimeTicks::Now()); | 103 base::TimeTicks::Now()); |
90 } | 104 } |
91 | 105 |
92 void FirstWebContentsProfiler::DidFinishNavigation( | 106 void FirstWebContentsProfiler::DidFinishNavigation( |
93 content::NavigationHandle* navigation_handle) { | 107 content::NavigationHandle* navigation_handle) { |
(...skipping 19 matching lines...) Expand all Loading... | |
113 | 127 |
114 // The first navigation has to be the main frame's. | 128 // The first navigation has to be the main frame's. |
115 DCHECK(navigation_handle->IsInMainFrame()); | 129 DCHECK(navigation_handle->IsInMainFrame()); |
116 | 130 |
117 if (!navigation_handle->HasCommitted() || | 131 if (!navigation_handle->HasCommitted() || |
118 navigation_handle->IsErrorPage()) { | 132 navigation_handle->IsErrorPage()) { |
119 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION_ERROR); | 133 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION_ERROR); |
120 return; | 134 return; |
121 } | 135 } |
122 | 136 |
137 if (content::IsBrowserSideNavigationEnabled()) { | |
138 startup_metric_utils::RecordFirstWebContentsMainNavigationStart( | |
139 navigation_handle->NavigationStart()); | |
140 collected_main_navigation_start_metric_ = true; | |
141 } | |
142 | |
123 collected_main_navigation_finished_metric_ = true; | 143 collected_main_navigation_finished_metric_ = true; |
124 startup_metric_utils::RecordFirstWebContentsMainNavigationFinished( | 144 startup_metric_utils::RecordFirstWebContentsMainNavigationFinished( |
125 base::TimeTicks::Now()); | 145 base::TimeTicks::Now()); |
126 } | 146 } |
127 | 147 |
128 void FirstWebContentsProfiler::WasHidden() { | 148 void FirstWebContentsProfiler::WasHidden() { |
129 // Stop profiling if the content gets hidden as its load may be deprioritized | 149 // Stop profiling if the content gets hidden as its load may be deprioritized |
130 // and timing it becomes meaningless. | 150 // and timing it becomes meaningless. |
131 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); | 151 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); |
132 } | 152 } |
(...skipping 16 matching lines...) Expand all Loading... | |
149 } | 169 } |
150 if (!collected_load_metric_) { | 170 if (!collected_load_metric_) { |
151 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason_NoLoad", | 171 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason_NoLoad", |
152 finish_reason, FinishReason::ENUM_MAX); | 172 finish_reason, FinishReason::ENUM_MAX); |
153 } | 173 } |
154 | 174 |
155 delete this; | 175 delete this; |
156 } | 176 } |
157 | 177 |
158 #endif // !defined(OS_ANDROID) | 178 #endif // !defined(OS_ANDROID) |
OLD | NEW |