| 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 #include "chrome/browser/metrics/first_web_contents_profiler.h" | 5 #include "chrome/browser/metrics/first_web_contents_profiler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 : content::WebContentsObserver(web_contents), | 92 : content::WebContentsObserver(web_contents), |
| 93 collected_paint_metric_(false), | 93 collected_paint_metric_(false), |
| 94 collected_load_metric_(false), | 94 collected_load_metric_(false), |
| 95 collected_main_navigation_start_metric_(false), | 95 collected_main_navigation_start_metric_(false), |
| 96 collected_main_navigation_finished_metric_(false), | 96 collected_main_navigation_finished_metric_(false), |
| 97 workload_(workload) {} | 97 workload_(workload) {} |
| 98 | 98 |
| 99 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { | 99 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { |
| 100 if (collected_paint_metric_) | 100 if (collected_paint_metric_) |
| 101 return; | 101 return; |
| 102 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 102 if (startup_metric_utils::WasMainWindowStartupInterrupted()) { |
| 103 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 103 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 | 106 |
| 107 collected_paint_metric_ = true; | 107 collected_paint_metric_ = true; |
| 108 startup_metric_utils::RecordFirstWebContentsNonEmptyPaint( | 108 startup_metric_utils::RecordFirstWebContentsNonEmptyPaint( |
| 109 base::TimeTicks::Now()); | 109 base::TimeTicks::Now()); |
| 110 | 110 |
| 111 metrics::TrackingSynchronizer::OnProfilingPhaseCompleted( | 111 metrics::TrackingSynchronizer::OnProfilingPhaseCompleted( |
| 112 metrics::ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); | 112 metrics::ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); |
| 113 | 113 |
| 114 if (IsFinishedCollectingMetrics()) | 114 if (IsFinishedCollectingMetrics()) |
| 115 FinishedCollectingMetrics(FinishReason::DONE); | 115 FinishedCollectingMetrics(FinishReason::DONE); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() { | 118 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() { |
| 119 if (collected_load_metric_) | 119 if (collected_load_metric_) |
| 120 return; | 120 return; |
| 121 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 121 if (startup_metric_utils::WasMainWindowStartupInterrupted()) { |
| 122 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 122 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
| 123 return; | 123 return; |
| 124 } | 124 } |
| 125 | 125 |
| 126 collected_load_metric_ = true; | 126 collected_load_metric_ = true; |
| 127 startup_metric_utils::RecordFirstWebContentsMainFrameLoad( | 127 startup_metric_utils::RecordFirstWebContentsMainFrameLoad( |
| 128 base::TimeTicks::Now()); | 128 base::TimeTicks::Now()); |
| 129 | 129 |
| 130 if (IsFinishedCollectingMetrics()) | 130 if (IsFinishedCollectingMetrics()) |
| 131 FinishedCollectingMetrics(FinishReason::DONE); | 131 FinishedCollectingMetrics(FinishReason::DONE); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void FirstWebContentsProfiler::DidStartNavigation( | 134 void FirstWebContentsProfiler::DidStartNavigation( |
| 135 content::NavigationHandle* navigation_handle) { | 135 content::NavigationHandle* navigation_handle) { |
| 136 if (collected_main_navigation_start_metric_) | 136 if (collected_main_navigation_start_metric_) |
| 137 return; | 137 return; |
| 138 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 138 if (startup_metric_utils::WasMainWindowStartupInterrupted()) { |
| 139 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 139 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
| 140 return; | 140 return; |
| 141 } | 141 } |
| 142 | 142 |
| 143 if (content::IsBrowserSideNavigationEnabled()) { | 143 if (content::IsBrowserSideNavigationEnabled()) { |
| 144 // With PlzNavigate, DidStartNavigation is called synchronously on | 144 // With PlzNavigate, DidStartNavigation is called synchronously on |
| 145 // browser-initiated loads instead of through an IPC. This means that we | 145 // browser-initiated loads instead of through an IPC. This means that we |
| 146 // will miss this signal. Instead we record it when the commit completes. | 146 // will miss this signal. Instead we record it when the commit completes. |
| 147 return; | 147 return; |
| 148 } | 148 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 165 // but fires after a lot of idle time when the user finally navigates | 165 // but fires after a lot of idle time when the user finally navigates |
| 166 // to another page that does trigger it. | 166 // to another page that does trigger it. |
| 167 if (navigation_handle->IsInMainFrame() && | 167 if (navigation_handle->IsInMainFrame() && |
| 168 navigation_handle->HasCommitted() && | 168 navigation_handle->HasCommitted() && |
| 169 !navigation_handle->IsSameDocument()) { | 169 !navigation_handle->IsSameDocument()) { |
| 170 FinishedCollectingMetrics(FinishReason::ABANDON_NEW_NAVIGATION); | 170 FinishedCollectingMetrics(FinishReason::ABANDON_NEW_NAVIGATION); |
| 171 } | 171 } |
| 172 return; | 172 return; |
| 173 } | 173 } |
| 174 | 174 |
| 175 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 175 if (startup_metric_utils::WasMainWindowStartupInterrupted()) { |
| 176 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 176 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 | 179 |
| 180 // The first navigation has to be the main frame's. | 180 // The first navigation has to be the main frame's. |
| 181 DCHECK(navigation_handle->IsInMainFrame()); | 181 DCHECK(navigation_handle->IsInMainFrame()); |
| 182 | 182 |
| 183 if (!navigation_handle->HasCommitted() || | 183 if (!navigation_handle->HasCommitted() || |
| 184 navigation_handle->IsErrorPage()) { | 184 navigation_handle->IsErrorPage()) { |
| 185 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION_ERROR); | 185 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION_ERROR); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 const bool single_tab = browser_list->size() == 1 && tab_strip->count() == 1; | 249 const bool single_tab = browser_list->size() == 1 && tab_strip->count() == 1; |
| 250 | 250 |
| 251 // FirstWebContentsProfiler owns itself and is also bound to | 251 // FirstWebContentsProfiler owns itself and is also bound to |
| 252 // |web_contents|'s lifetime by observing WebContentsDestroyed(). | 252 // |web_contents|'s lifetime by observing WebContentsDestroyed(). |
| 253 new FirstWebContentsProfiler(web_contents, | 253 new FirstWebContentsProfiler(web_contents, |
| 254 single_tab ? WebContentsWorkload::SINGLE_TAB | 254 single_tab ? WebContentsWorkload::SINGLE_TAB |
| 255 : WebContentsWorkload::MULTI_TABS); | 255 : WebContentsWorkload::MULTI_TABS); |
| 256 } | 256 } |
| 257 | 257 |
| 258 } // namespace metrics | 258 } // namespace metrics |
| OLD | NEW |