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 package org.chromium.chrome.browser.compositor.bottombar.contextualsearch; | 5 package org.chromium.chrome.browser.compositor.bottombar.contextualsearch; |
6 | 6 |
7 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState; | 7 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState; |
8 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange
Reason; | 8 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange
Reason; |
9 import org.chromium.chrome.browser.contextualsearch.ContextualSearchUma; | 9 import org.chromium.chrome.browser.contextualsearch.ContextualSearchUma; |
10 | 10 |
11 /** | 11 /** |
12 * This class is responsible for all the logging related to Contextual Search. | 12 * This class is responsible for all the logging related to Contextual Search. |
13 */ | 13 */ |
14 public class ContextualSearchPanelMetrics { | 14 public class ContextualSearchPanelMetrics { |
15 | 15 |
16 // Flags for logging. | 16 // Flags for logging. |
17 private boolean mDidSearchInvolvePromo; | 17 private boolean mDidSearchInvolvePromo; |
18 private boolean mWasSearchContentViewSeen; | 18 private boolean mWasSearchContentViewSeen; |
19 private boolean mIsPromoActive; | 19 private boolean mIsPromoActive; |
20 private boolean mHasExpanded; | 20 private boolean mHasExpanded; |
21 private boolean mHasMaximized; | 21 private boolean mHasMaximized; |
22 private boolean mHasExitedPeeking; | 22 private boolean mHasExitedPeeking; |
23 private boolean mHasExitedExpanded; | 23 private boolean mHasExitedExpanded; |
24 private boolean mHasExitedMaximized; | 24 private boolean mHasExitedMaximized; |
25 private boolean mIsSerpNavigation; | 25 private boolean mIsSerpNavigation; |
26 private boolean mWasActivatedByTap; | 26 private boolean mWasActivatedByTap; |
27 private boolean mIsSearchPanelFullyPreloaded; | 27 private boolean mIsSearchPanelFullyPreloaded; |
28 private boolean mWasIconSpriteAnimated; | 28 private boolean mWasIconSpriteAnimated; |
29 private long mSearchStartTimeNs; | 29 // Time when the panel peeks into view (not reset by a chained search). |
30 private long mSearchViewStartTimeNs; | 30 // Used to log total time the panel is showing (not closed). |
| 31 private long mFirstPeekTimeNs; |
| 32 // Time when the panel contents come into view (when the panel is opened). |
| 33 // Used to log preload effectiveness info -- additional time needed to fully
render the |
| 34 // content in the overlay. |
| 35 private long mContentFirstViewTimeNs; |
| 36 // Time when a search request was started. Reset by chained searches. |
| 37 // Used to log the time it takes for a Search Result to become available. |
| 38 private long mSearchRequestStartTimeNs; |
31 | 39 |
32 /** | 40 /** |
33 * Log information when the panel's state has changed. | 41 * Log information when the panel's state has changed. |
34 * @param fromState The state the panel is transitioning from. | 42 * @param fromState The state the panel is transitioning from. |
35 * @param toState The state that the panel is transitioning to. | 43 * @param toState The state that the panel is transitioning to. |
36 * @param reason The reason for the state change. | 44 * @param reason The reason for the state change. |
37 */ | 45 */ |
38 public void onPanelStateChanged(PanelState fromState, PanelState toState, | 46 public void onPanelStateChanged(PanelState fromState, PanelState toState, |
39 StateChangeReason reason) { | 47 StateChangeReason reason) { |
40 // Note: the logging within this function includes the promo, unless spe
cifically | 48 // Note: the logging within this function includes the promo, unless spe
cifically |
41 // excluded. | 49 // excluded. |
42 boolean isStartingSearch = isStartingNewContextualSearch(toState, reason
); | 50 boolean isStartingSearch = isStartingNewContextualSearch(toState, reason
); |
43 boolean isEndingSearch = isEndingContextualSearch(fromState, toState, is
StartingSearch); | 51 boolean isEndingSearch = isEndingContextualSearch(fromState, toState, is
StartingSearch); |
44 boolean isChained = isStartingSearch && isOngoingContextualSearch(fromSt
ate); | 52 boolean isChained = isStartingSearch && isOngoingContextualSearch(fromSt
ate); |
45 boolean isSameState = fromState == toState; | 53 boolean isSameState = fromState == toState; |
46 boolean isFirstExitFromPeeking = fromState == PanelState.PEEKED && !mHas
ExitedPeeking | 54 boolean isFirstExitFromPeeking = fromState == PanelState.PEEKED && !mHas
ExitedPeeking |
47 && (!isSameState || isStartingSearch); | 55 && (!isSameState || isStartingSearch); |
48 boolean isFirstExitFromExpanded = fromState == PanelState.EXPANDED && !m
HasExitedExpanded | 56 boolean isFirstExitFromExpanded = fromState == PanelState.EXPANDED && !m
HasExitedExpanded |
49 && !isSameState; | 57 && !isSameState; |
50 boolean isFirstExitFromMaximized = fromState == PanelState.MAXIMIZED &&
!mHasExitedMaximized | 58 boolean isFirstExitFromMaximized = fromState == PanelState.MAXIMIZED &&
!mHasExitedMaximized |
51 && !isSameState; | 59 && !isSameState; |
52 boolean isFirstSearchView = isFirstExitFromPeeking && toState != PanelSt
ate.CLOSED; | 60 boolean isFirstSearchView = isFirstExitFromPeeking && toState != PanelSt
ate.CLOSED; |
53 // This variable is needed for logging and gets reset in an isStartingSe
arch block below, | 61 // This variable is needed for logging and gets reset in an isStartingSe
arch block below, |
54 // so a local copy is created before the reset. | 62 // so a local copy is created before the reset. |
55 boolean isSearchPanelFullyPreloaded = mIsSearchPanelFullyPreloaded; | 63 boolean isSearchPanelFullyPreloaded = mIsSearchPanelFullyPreloaded; |
56 | 64 |
57 if (isEndingSearch) { | 65 if (isEndingSearch) { |
58 if (!mDidSearchInvolvePromo) { | 66 if (!mDidSearchInvolvePromo) { |
59 // Measure duration only when the promo is not involved. | 67 // Measure duration only when the promo is not involved. |
60 long durationMs = (System.nanoTime() - mSearchStartTimeNs) / 100
0000; | 68 long durationMs = (System.nanoTime() - mFirstPeekTimeNs) / 10000
00; |
61 ContextualSearchUma.logDuration(mWasSearchContentViewSeen, isCha
ined, durationMs); | 69 ContextualSearchUma.logDuration(mWasSearchContentViewSeen, isCha
ined, durationMs); |
62 } | 70 } |
63 if (mIsPromoActive) { | 71 if (mIsPromoActive) { |
64 // The user is exiting still in the promo, without choosing an o
ption. | 72 // The user is exiting still in the promo, without choosing an o
ption. |
65 ContextualSearchUma.logPromoSeen(mWasSearchContentViewSeen, mWas
ActivatedByTap); | 73 ContextualSearchUma.logPromoSeen(mWasSearchContentViewSeen, mWas
ActivatedByTap); |
66 } else { | 74 } else { |
67 ContextualSearchUma.logResultsSeen(mWasSearchContentViewSeen, mW
asActivatedByTap); | 75 ContextualSearchUma.logResultsSeen(mWasSearchContentViewSeen, mW
asActivatedByTap); |
68 } | 76 } |
69 | 77 |
70 ContextualSearchUma.logIconSpriteAnimated(mWasIconSpriteAnimated, | 78 ContextualSearchUma.logIconSpriteAnimated(mWasIconSpriteAnimated, |
71 mWasSearchContentViewSeen, mWasActivatedByTap); | 79 mWasSearchContentViewSeen, mWasActivatedByTap); |
72 } | 80 } |
73 if (isStartingSearch) { | 81 if (isStartingSearch) { |
74 mSearchStartTimeNs = System.nanoTime(); | 82 mFirstPeekTimeNs = System.nanoTime(); |
75 mSearchViewStartTimeNs = 0; | 83 mContentFirstViewTimeNs = 0; |
76 mIsSearchPanelFullyPreloaded = false; | 84 mIsSearchPanelFullyPreloaded = false; |
77 mWasActivatedByTap = reason == StateChangeReason.TEXT_SELECT_TAP; | 85 mWasActivatedByTap = reason == StateChangeReason.TEXT_SELECT_TAP; |
78 } | 86 } |
79 if (isFirstSearchView) { | 87 if (isFirstSearchView) { |
80 onSearchPanelFirstView(); | 88 onSearchPanelFirstView(); |
81 } | 89 } |
82 | 90 |
83 // Log state changes. We only log the first transition to a state within
a contextual | 91 // Log state changes. We only log the first transition to a state within
a contextual |
84 // search. Note that when a user clicks on a link on the search content
view, this will | 92 // search. Note that when a user clicks on a link on the search content
view, this will |
85 // trigger a transition to MAXIMIZED (SERP_NAVIGATION) followed by a tra
nsition to | 93 // trigger a transition to MAXIMIZED (SERP_NAVIGATION) followed by a tra
nsition to |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 166 } |
159 | 167 |
160 /** | 168 /** |
161 * @param wasIconSpriteAnimated Whether the search provider icon sprite was
animated. | 169 * @param wasIconSpriteAnimated Whether the search provider icon sprite was
animated. |
162 */ | 170 */ |
163 public void setWasIconSpriteAnimated(boolean wasIconSpriteAnimated) { | 171 public void setWasIconSpriteAnimated(boolean wasIconSpriteAnimated) { |
164 mWasIconSpriteAnimated = wasIconSpriteAnimated; | 172 mWasIconSpriteAnimated = wasIconSpriteAnimated; |
165 } | 173 } |
166 | 174 |
167 /** | 175 /** |
168 * Gets whether the promo is active. | 176 * Called to record the time when a search request started, for resolve and
prefetch timing. |
169 */ | 177 */ |
170 private boolean getIsPromoActive() { | 178 public void onSearchRequestStarted() { |
171 return mIsPromoActive; | 179 mSearchRequestStartTimeNs = System.nanoTime(); |
172 } | 180 } |
173 | 181 |
174 /** | 182 /** |
| 183 * Called when a Search Term has been resolved. |
| 184 */ |
| 185 public void onSearchTermResolved() { |
| 186 long durationMs = (System.nanoTime() - mSearchRequestStartTimeNs) / 1000
000; |
| 187 ContextualSearchUma.logSearchTermResolutionDuration(durationMs); |
| 188 } |
| 189 |
| 190 /** |
175 * Records timing information when the search results have fully loaded. | 191 * Records timing information when the search results have fully loaded. |
176 * @param wasPrefetch Whether the request was prefetch-enabled. | 192 * @param wasPrefetch Whether the request was prefetch-enabled. |
177 */ | 193 */ |
178 public void onSearchResultsLoaded(boolean wasPrefetch) { | 194 public void onSearchResultsLoaded(boolean wasPrefetch) { |
179 if (mHasExpanded || mHasMaximized) { | 195 if (mHasExpanded || mHasMaximized) { |
180 // Already opened, log how long it took. | 196 // Already opened, log how long it took. |
181 assert mSearchViewStartTimeNs != 0; | 197 assert mContentFirstViewTimeNs != 0; |
182 long durationMs = (System.nanoTime() - mSearchViewStartTimeNs) / 100
0000; | 198 long durationMs = (System.nanoTime() - mContentFirstViewTimeNs) / 10
00000; |
183 logSearchPanelLoadDuration(wasPrefetch, durationMs); | 199 logSearchPanelLoadDuration(wasPrefetch, durationMs); |
184 } | 200 } |
185 | 201 |
186 // Not yet opened, wait till an open to log. | 202 // Not yet opened, wait till an open to log. |
187 mIsSearchPanelFullyPreloaded = true; | 203 mIsSearchPanelFullyPreloaded = true; |
188 } | 204 } |
189 | 205 |
190 /** | 206 /** |
| 207 * Called after the panel has navigated to prefetched Search Results. |
| 208 * This is the point where the search result starts to render in the panel. |
| 209 */ |
| 210 public void onPanelNavigatedToPrefetchedSearch(boolean didResolve) { |
| 211 long durationMs = (System.nanoTime() - mSearchRequestStartTimeNs) / 1000
000; |
| 212 ContextualSearchUma.logPrefetchedSearchNavigatedDuration(durationMs, did
Resolve); |
| 213 } |
| 214 |
| 215 /** |
191 * Records timing information when the search panel has been viewed for the
first time. | 216 * Records timing information when the search panel has been viewed for the
first time. |
192 */ | 217 */ |
193 private void onSearchPanelFirstView() { | 218 private void onSearchPanelFirstView() { |
194 if (mIsSearchPanelFullyPreloaded) { | 219 if (mIsSearchPanelFullyPreloaded) { |
195 // Already fully pre-loaded, record a wait of 0 milliseconds. | 220 // Already fully pre-loaded, record a wait of 0 milliseconds. |
196 logSearchPanelLoadDuration(true, 0); | 221 logSearchPanelLoadDuration(true, 0); |
197 } else { | 222 } else { |
198 // Start a loading timer. | 223 // Start a loading timer. |
199 mSearchViewStartTimeNs = System.nanoTime(); | 224 mContentFirstViewTimeNs = System.nanoTime(); |
200 } | 225 } |
201 } | 226 } |
202 | 227 |
203 /** | 228 /** |
204 * Determine whether a new contextual search is starting. | 229 * Determine whether a new contextual search is starting. |
205 * @param toState The contextual search state that will be transitioned to. | 230 * @param toState The contextual search state that will be transitioned to. |
206 * @param reason The reason for the search state transition. | 231 * @param reason The reason for the search state transition. |
207 * @return Whether a new contextual search is starting. | 232 * @return Whether a new contextual search is starting. |
208 */ | 233 */ |
209 private boolean isStartingNewContextualSearch(PanelState toState, StateChang
eReason reason) { | 234 private boolean isStartingNewContextualSearch(PanelState toState, StateChang
eReason reason) { |
(...skipping 26 matching lines...) Expand all Loading... |
236 /** | 261 /** |
237 * Logs the duration the user waited for the search panel to fully load, onc
e it was opened. | 262 * Logs the duration the user waited for the search panel to fully load, onc
e it was opened. |
238 * @param wasPrefetch Whether the load included prefetch. | 263 * @param wasPrefetch Whether the load included prefetch. |
239 * @param durationMs The duration to log. | 264 * @param durationMs The duration to log. |
240 */ | 265 */ |
241 private void logSearchPanelLoadDuration(boolean wasPrefetch, long durationMs
) { | 266 private void logSearchPanelLoadDuration(boolean wasPrefetch, long durationMs
) { |
242 ContextualSearchUma.logSearchPanelLoadDuration(wasPrefetch, durationMs); | 267 ContextualSearchUma.logSearchPanelLoadDuration(wasPrefetch, durationMs); |
243 } | 268 } |
244 } | 269 } |
245 | 270 |
OLD | NEW |