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 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { | 50 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { |
51 if (collected_paint_metric_) | 51 if (collected_paint_metric_) |
52 return; | 52 return; |
53 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 53 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
54 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 54 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
55 return; | 55 return; |
56 } | 56 } |
57 | 57 |
58 collected_paint_metric_ = true; | 58 collected_paint_metric_ = true; |
59 const base::Time now = base::Time::Now(); | 59 const base::TimeTicks now = base::TimeTicks::Now(); |
60 // Record the old metric unconditionally. | 60 // Record the old metric unconditionally. |
61 startup_metric_utils::RecordDeprecatedFirstWebContentsNonEmptyPaint(now); | 61 startup_metric_utils::RecordDeprecatedFirstWebContentsNonEmptyPaint(now); |
62 if (!finished_) | 62 if (!finished_) |
63 startup_metric_utils::RecordFirstWebContentsNonEmptyPaint(now); | 63 startup_metric_utils::RecordFirstWebContentsNonEmptyPaint(now); |
64 | 64 |
65 metrics::TrackingSynchronizer::OnProfilingPhaseCompleted( | 65 metrics::TrackingSynchronizer::OnProfilingPhaseCompleted( |
66 metrics::ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); | 66 metrics::ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); |
67 | 67 |
68 if (IsFinishedCollectingMetrics()) | 68 if (IsFinishedCollectingMetrics()) |
69 FinishedCollectingMetrics(FinishReason::DONE); | 69 FinishedCollectingMetrics(FinishReason::DONE); |
70 } | 70 } |
71 | 71 |
72 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() { | 72 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() { |
73 if (collected_load_metric_) | 73 if (collected_load_metric_) |
74 return; | 74 return; |
75 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 75 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
76 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 76 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
77 return; | 77 return; |
78 } | 78 } |
79 | 79 |
80 collected_load_metric_ = true; | 80 collected_load_metric_ = true; |
81 const base::Time now = base::Time::Now(); | 81 const base::TimeTicks now = base::TimeTicks::Now(); |
82 // Record the old metric unconditionally. | 82 // Record the old metric unconditionally. |
83 startup_metric_utils::RecordDeprecatedFirstWebContentsMainFrameLoad(now); | 83 startup_metric_utils::RecordDeprecatedFirstWebContentsMainFrameLoad(now); |
84 if (!finished_) | 84 if (!finished_) |
85 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(now); | 85 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(now); |
86 | 86 |
87 if (IsFinishedCollectingMetrics()) | 87 if (IsFinishedCollectingMetrics()) |
88 FinishedCollectingMetrics(FinishReason::DONE); | 88 FinishedCollectingMetrics(FinishReason::DONE); |
89 } | 89 } |
90 | 90 |
91 void FirstWebContentsProfiler::DidStartNavigation( | 91 void FirstWebContentsProfiler::DidStartNavigation( |
92 content::NavigationHandle* navigation_handle) { | 92 content::NavigationHandle* navigation_handle) { |
93 if (collected_main_navigation_start_metric_) | 93 if (collected_main_navigation_start_metric_) |
94 return; | 94 return; |
95 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 95 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
96 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 96 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
97 return; | 97 return; |
98 } | 98 } |
99 | 99 |
100 // The first navigation has to be the main frame's. | 100 // The first navigation has to be the main frame's. |
101 DCHECK(navigation_handle->IsInMainFrame()); | 101 DCHECK(navigation_handle->IsInMainFrame()); |
102 | 102 |
103 collected_main_navigation_start_metric_ = true; | 103 collected_main_navigation_start_metric_ = true; |
104 startup_metric_utils::RecordFirstWebContentsMainNavigationStart( | 104 startup_metric_utils::RecordFirstWebContentsMainNavigationStart( |
105 base::Time::Now()); | 105 base::TimeTicks::Now()); |
106 } | 106 } |
107 | 107 |
108 void FirstWebContentsProfiler::DidFinishNavigation( | 108 void FirstWebContentsProfiler::DidFinishNavigation( |
109 content::NavigationHandle* navigation_handle) { | 109 content::NavigationHandle* navigation_handle) { |
110 if (collected_main_navigation_finished_metric_) { | 110 if (collected_main_navigation_finished_metric_) { |
111 // Abandon profiling on a top-level navigation to a different page as it: | 111 // Abandon profiling on a top-level navigation to a different page as it: |
112 // (1) is no longer a fair timing; and | 112 // (1) is no longer a fair timing; and |
113 // (2) can cause http://crbug.com/525209 where one of the timing | 113 // (2) can cause http://crbug.com/525209 where one of the timing |
114 // heuristics (e.g. first paint) didn't fire for the initial content | 114 // heuristics (e.g. first paint) didn't fire for the initial content |
115 // but fires after a lot of idle time when the user finally navigates | 115 // but fires after a lot of idle time when the user finally navigates |
(...skipping 15 matching lines...) Expand all Loading... |
131 DCHECK(navigation_handle->IsInMainFrame()); | 131 DCHECK(navigation_handle->IsInMainFrame()); |
132 | 132 |
133 if (!navigation_handle->HasCommitted() || | 133 if (!navigation_handle->HasCommitted() || |
134 navigation_handle->IsErrorPage()) { | 134 navigation_handle->IsErrorPage()) { |
135 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION_ERROR); | 135 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION_ERROR); |
136 return; | 136 return; |
137 } | 137 } |
138 | 138 |
139 collected_main_navigation_finished_metric_ = true; | 139 collected_main_navigation_finished_metric_ = true; |
140 startup_metric_utils::RecordFirstWebContentsMainNavigationFinished( | 140 startup_metric_utils::RecordFirstWebContentsMainNavigationFinished( |
141 base::Time::Now()); | 141 base::TimeTicks::Now()); |
142 } | 142 } |
143 | 143 |
144 void FirstWebContentsProfiler::WasHidden() { | 144 void FirstWebContentsProfiler::WasHidden() { |
145 // Stop profiling if the content gets hidden as its load may be deprioritized | 145 // Stop profiling if the content gets hidden as its load may be deprioritized |
146 // and timing it becomes meaningless. | 146 // and timing it becomes meaningless. |
147 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); | 147 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); |
148 } | 148 } |
149 | 149 |
150 void FirstWebContentsProfiler::WebContentsDestroyed() { | 150 void FirstWebContentsProfiler::WebContentsDestroyed() { |
151 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_DESTROYED); | 151 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_DESTROYED); |
(...skipping 17 matching lines...) Expand all Loading... |
169 finish_reason, FinishReason::ENUM_MAX); | 169 finish_reason, FinishReason::ENUM_MAX); |
170 } | 170 } |
171 finished_ = true; | 171 finished_ = true; |
172 } | 172 } |
173 // TODO(gab): Delete right away when getting rid of |finished_|. | 173 // TODO(gab): Delete right away when getting rid of |finished_|. |
174 if (IsFinishedCollectingMetrics()) | 174 if (IsFinishedCollectingMetrics()) |
175 delegate_->ProfilerFinishedCollectingMetrics(); | 175 delegate_->ProfilerFinishedCollectingMetrics(); |
176 } | 176 } |
177 | 177 |
178 #endif // !defined(OS_ANDROID) | 178 #endif // !defined(OS_ANDROID) |
OLD | NEW |