Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(608)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchUma.java

Issue 987883002: Upstream Layout.java and associated files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move to SuppressFBWarnings from findbugs_exclude.xml Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.contextualsearch;
6
7 import org.chromium.base.metrics.RecordHistogram;
8 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context ualSearchPanel.PanelState;
9 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context ualSearchPanel.StateChangeReason;
10 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
11
12 import java.util.Collections;
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.concurrent.TimeUnit;
16
17 /**
18 * Centralizes UMA data collection for Contextual Search. All calls must be made from the UI thread.
19 */
20 public class ContextualSearchUma {
21 // Constants used to log UMA "enum" histograms about the Contextual Search's preference state.
22 private static final int PREFERENCE_UNINITIALIZED = 0;
23 private static final int PREFERENCE_ENABLED = 1;
24 private static final int PREFERENCE_DISABLED = 2;
25 private static final int PREFERENCE_HISTOGRAM_BOUNDARY = 3;
26
27 // Constants used to log UMA "enum" histograms about whether search results were seen.
28 private static final int RESULTS_SEEN = 0;
29 private static final int RESULTS_NOT_SEEN = 1;
30 private static final int RESULTS_SEEN_BOUNDARY = 2;
31
32 // Constants used to log UMA "enum" histograms about whether the selection i s valid.
33 private static final int SELECTION_VALID = 0;
34 private static final int SELECTION_INVALID = 1;
35 private static final int SELECTION_BOUNDARY = 2;
36
37 // Constants used to log UMA "enum" histograms about a request's outcome.
38 private static final int REQUEST_NOT_FAILED = 0;
39 private static final int REQUEST_FAILED = 1;
40 private static final int REQUEST_BOUNDARY = 2;
41
42 // Constants used to log UMA "enum" histograms about the panel's state trans itions.
43 // Entry code: first entry into CLOSED.
44 private static final int ENTER_CLOSED_FROM_OTHER = 0;
45 private static final int ENTER_CLOSED_FROM_PEEKED_BACK_PRESS = 1;
46 private static final int ENTER_CLOSED_FROM_PEEKED_BASE_PAGE_SCROLL = 2;
47 private static final int ENTER_CLOSED_FROM_PEEKED_TEXT_SELECT_TAP = 3;
48 private static final int ENTER_CLOSED_FROM_EXPANDED_BACK_PRESS = 4;
49 private static final int ENTER_CLOSED_FROM_EXPANDED_BASE_PAGE_TAP = 5;
50 private static final int ENTER_CLOSED_FROM_EXPANDED_FLING = 6;
51 private static final int ENTER_CLOSED_FROM_MAXIMIZED_BACK_PRESS = 7;
52 private static final int ENTER_CLOSED_FROM_MAXIMIZED_FLING = 8;
53 private static final int ENTER_CLOSED_FROM_MAXIMIZED_TAB_PROMOTION = 9;
54 private static final int ENTER_CLOSED_FROM_MAXIMIZED_SERP_NAVIGATION = 10;
55 private static final int ENTER_CLOSED_FROM_BOUNDARY = 11;
56
57 // Entry code: first entry into PEEKED.
58 private static final int ENTER_PEEKED_FROM_OTHER = 0;
59 private static final int ENTER_PEEKED_FROM_CLOSED_TEXT_SELECT_TAP = 1;
60 private static final int ENTER_PEEKED_FROM_CLOSED_EXT_SELECT_LONG_PRESS = 2;
61 private static final int ENTER_PEEKED_FROM_PEEKED_TEXT_SELECT_TAP = 3;
62 private static final int ENTER_PEEKED_FROM_PEEKED_TEXT_SELECT_LONG_PRESS = 4 ;
63 private static final int ENTER_PEEKED_FROM_EXPANDED_SEARCH_BAR_TAP = 5;
64 private static final int ENTER_PEEKED_FROM_EXPANDED_SWIPE = 6;
65 private static final int ENTER_PEEKED_FROM_EXPANDED_FLING = 7;
66 private static final int ENTER_PEEKED_FROM_MAXIMIZED_SWIPE = 8;
67 private static final int ENTER_PEEKED_FROM_MAXIMIZED_FLING = 9;
68 private static final int ENTER_PEEKED_FROM_BOUNDARY = 10;
69
70 // Entry code: first entry into EXPANDED.
71 private static final int ENTER_EXPANDED_FROM_OTHER = 0;
72 private static final int ENTER_EXPANDED_FROM_PEEKED_SEARCH_BAR_TAP = 1;
73 private static final int ENTER_EXPANDED_FROM_PEEKED_SWIPE = 2;
74 private static final int ENTER_EXPANDED_FROM_PEEKED_FLING = 3;
75 private static final int ENTER_EXPANDED_FROM_MAXIMIZED_SWIPE = 4;
76 private static final int ENTER_EXPANDED_FROM_MAXIMIZED_FLING = 5;
77 private static final int ENTER_EXPANDED_FROM_BOUNDARY = 6;
78
79 // Entry code: first entry into MAXIMIZED.
80 private static final int ENTER_MAXIMIZED_FROM_OTHER = 0;
81 private static final int ENTER_MAXIMIZED_FROM_PEEKED_SWIPE = 1;
82 private static final int ENTER_MAXIMIZED_FROM_PEEKED_FLING = 2;
83 private static final int ENTER_MAXIMIZED_FROM_EXPANDED_SWIPE = 3;
84 private static final int ENTER_MAXIMIZED_FROM_EXPANDED_FLING = 4;
85 private static final int ENTER_MAXIMIZED_FROM_EXPANDED_SERP_NAVIGATION = 5;
86 private static final int ENTER_MAXIMIZED_FROM_BOUNDARY = 6;
87
88 // Exit code: first exit from CLOSED (or UNDEFINED).
89 private static final int EXIT_CLOSED_TO_OTHER = 0;
90 private static final int EXIT_CLOSED_TO_PEEKED_TEXT_SELECT_TAP = 1;
91 private static final int EXIT_CLOSED_TO_PEEKED_TEXT_SELECT_LONG_PRESS = 2;
92 private static final int EXIT_CLOSED_TO_BOUNDARY = 3;
93
94 // Exit code: first exit from PEEKED.
95 private static final int EXIT_PEEKED_TO_OTHER = 0;
96 private static final int EXIT_PEEKED_TO_CLOSED_BACK_PRESS = 1;
97 private static final int EXIT_PEEKED_TO_CLOSED_BASE_PAGE_SCROLL = 2;
98 private static final int EXIT_PEEKED_TO_CLOSED_TEXT_SELECT_TAP = 3;
99 private static final int EXIT_PEEKED_TO_PEEKED_TEXT_SELECT_TAP = 4;
100 private static final int EXIT_PEEKED_TO_PEEKED_TEXT_SELECT_LONG_PRESS = 5;
101 private static final int EXIT_PEEKED_TO_EXPANDED_SEARCH_BAR_TAP = 6;
102 private static final int EXIT_PEEKED_TO_EXPANDED_SWIPE = 7;
103 private static final int EXIT_PEEKED_TO_EXPANDED_FLING = 8;
104 private static final int EXIT_PEEKED_TO_MAXIMIZED_SWIPE = 9;
105 private static final int EXIT_PEEKED_TO_MAXIMIZED_FLING = 10;
106 private static final int EXIT_PEEKED_TO_BOUNDARY = 11;
107
108 // Exit code: first exit from EXPANDED.
109 private static final int EXIT_EXPANDED_TO_OTHER = 0;
110 private static final int EXIT_EXPANDED_TO_CLOSED_BACK_PRESS = 1;
111 private static final int EXIT_EXPANDED_TO_CLOSED_BASE_PAGE_TAP = 2;
112 private static final int EXIT_EXPANDED_TO_CLOSED_FLING = 3;
113 private static final int EXIT_EXPANDED_TO_PEEKED_SEARCH_BAR_TAP = 4;
114 private static final int EXIT_EXPANDED_TO_PEEKED_SWIPE = 5;
115 private static final int EXIT_EXPANDED_TO_PEEKED_FLING = 6;
116 private static final int EXIT_EXPANDED_TO_MAXIMIZED_SWIPE = 7;
117 private static final int EXIT_EXPANDED_TO_MAXIMIZED_FLING = 8;
118 private static final int EXIT_EXPANDED_TO_MAXIMIZED_SERP_NAVIGATION = 9;
119 private static final int EXIT_EXPANDED_TO_BOUNDARY = 10;
120
121 // Exit code: first exit from MAXIMIZED.
122 private static final int EXIT_MAXIMIZED_TO_OTHER = 0;
123 private static final int EXIT_MAXIMIZED_TO_CLOSED_BACK_PRESS = 1;
124 private static final int EXIT_MAXIMIZED_TO_CLOSED_FLING = 2;
125 private static final int EXIT_MAXIMIZED_TO_CLOSED_TAB_PROMOTION = 3;
126 private static final int EXIT_MAXIMIZED_TO_CLOSED_SERP_NAVIGATION = 4;
127 private static final int EXIT_MAXIMIZED_TO_PEEKED_SWIPE = 5;
128 private static final int EXIT_MAXIMIZED_TO_PEEKED_FLING = 6;
129 private static final int EXIT_MAXIMIZED_TO_EXPANDED_SWIPE = 7;
130 private static final int EXIT_MAXIMIZED_TO_EXPANDED_FLING = 8;
131 private static final int EXIT_MAXIMIZED_TO_BOUNDARY = 9;
132
133 /**
134 * Key used in maps from {state, reason} to state entry (exit) logging code.
135 */
136 static class StateChangeKey {
137 final PanelState mState;
138 final StateChangeReason mReason;
139 final int mHashCode;
140
141 StateChangeKey(PanelState state, StateChangeReason reason) {
142 mState = state;
143 mReason = reason;
144 mHashCode = 31 * state.hashCode() + reason.hashCode();
145 }
146
147 @Override
148 public boolean equals(Object obj) {
149 if (!(obj instanceof StateChangeKey)) {
150 return false;
151 }
152 if (obj == this) {
153 return true;
154 }
155 StateChangeKey other = (StateChangeKey) obj;
156 return mState.equals(other.mState) && mReason.equals(other.mReason);
157 }
158
159 @Override
160 public int hashCode() {
161 return mHashCode;
162 }
163 }
164
165 // Entry code map: first entry into CLOSED.
166 private static final Map<StateChangeKey, Integer> ENTER_CLOSED_STATE_CHANGE_ CODES;
167 static {
168 Map<StateChangeKey, Integer> codes = new HashMap<StateChangeKey, Integer >();
169 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.BACK_P RESS),
170 ENTER_CLOSED_FROM_PEEKED_BACK_PRESS);
171 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.BASE_P AGE_SCROLL),
172 ENTER_CLOSED_FROM_PEEKED_BASE_PAGE_SCROLL);
173 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.TEXT_S ELECT_TAP),
174 ENTER_CLOSED_FROM_PEEKED_TEXT_SELECT_TAP);
175 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.BACK _PRESS),
176 ENTER_CLOSED_FROM_EXPANDED_BACK_PRESS);
177 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.BASE _PAGE_TAP),
178 ENTER_CLOSED_FROM_EXPANDED_BASE_PAGE_TAP);
179 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.FLIN G),
180 ENTER_CLOSED_FROM_EXPANDED_FLING);
181 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.BAC K_PRESS),
182 ENTER_CLOSED_FROM_MAXIMIZED_BACK_PRESS);
183 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.FLI NG),
184 ENTER_CLOSED_FROM_MAXIMIZED_FLING);
185 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.TAB _PROMOTION),
186 ENTER_CLOSED_FROM_MAXIMIZED_TAB_PROMOTION);
187 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.SER P_NAVIGATION),
188 ENTER_CLOSED_FROM_MAXIMIZED_SERP_NAVIGATION);
189 ENTER_CLOSED_STATE_CHANGE_CODES = Collections.unmodifiableMap(codes);
190 }
191
192 // Entry code map: first entry into PEEKED.
193 private static final Map<StateChangeKey, Integer> ENTER_PEEKED_STATE_CHANGE_ CODES;
194 static {
195 Map<StateChangeKey, Integer> codes = new HashMap<StateChangeKey, Integer >();
196 // Note: we don't distinguish entering PEEKED from UNDEFINED / CLOSED.
197 codes.put(new StateChangeKey(PanelState.UNDEFINED, StateChangeReason.TEX T_SELECT_TAP),
198 ENTER_PEEKED_FROM_CLOSED_TEXT_SELECT_TAP);
199 codes.put(new StateChangeKey(PanelState.UNDEFINED,
200 StateChangeReason.TEXT_SELECT_LONG_PRESS),
201 ENTER_PEEKED_FROM_CLOSED_EXT_SELECT_LONG_PRESS);
202 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.TEXT_S ELECT_TAP),
203 ENTER_PEEKED_FROM_CLOSED_TEXT_SELECT_TAP);
204 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.TEXT_S ELECT_LONG_PRESS),
205 ENTER_PEEKED_FROM_CLOSED_EXT_SELECT_LONG_PRESS);
206 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.TEXT_S ELECT_TAP),
207 ENTER_PEEKED_FROM_PEEKED_TEXT_SELECT_TAP);
208 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.TEXT_S ELECT_LONG_PRESS),
209 ENTER_PEEKED_FROM_PEEKED_TEXT_SELECT_LONG_PRESS);
210 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.SEAR CH_BAR_TAP),
211 ENTER_PEEKED_FROM_EXPANDED_SEARCH_BAR_TAP);
212 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.SWIP E),
213 ENTER_PEEKED_FROM_EXPANDED_SWIPE);
214 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.FLIN G),
215 ENTER_PEEKED_FROM_EXPANDED_FLING);
216 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.SWI PE),
217 ENTER_PEEKED_FROM_MAXIMIZED_SWIPE);
218 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.FLI NG),
219 ENTER_PEEKED_FROM_MAXIMIZED_FLING);
220 ENTER_PEEKED_STATE_CHANGE_CODES = Collections.unmodifiableMap(codes);
221 }
222
223 // Entry code map: first entry into EXPANDED.
224 private static final Map<StateChangeKey, Integer> ENTER_EXPANDED_STATE_CHANG E_CODES;
225 static {
226 Map<StateChangeKey, Integer> codes = new HashMap<StateChangeKey, Integer >();
227 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.SEARCH _BAR_TAP),
228 ENTER_EXPANDED_FROM_PEEKED_SEARCH_BAR_TAP);
229 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.SWIPE) ,
230 ENTER_EXPANDED_FROM_PEEKED_SWIPE);
231 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.FLING) ,
232 ENTER_EXPANDED_FROM_PEEKED_FLING);
233 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.SWI PE),
234 ENTER_EXPANDED_FROM_MAXIMIZED_SWIPE);
235 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.FLI NG),
236 ENTER_EXPANDED_FROM_MAXIMIZED_FLING);
237 ENTER_EXPANDED_STATE_CHANGE_CODES = Collections.unmodifiableMap(codes);
238 }
239
240 // Entry code map: first entry into MAXIMIZED.
241 private static final Map<StateChangeKey, Integer> ENTER_MAXIMIZED_STATE_CHAN GE_CODES;
242 static {
243 Map<StateChangeKey, Integer> codes = new HashMap<StateChangeKey, Integer >();
244 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.SWIPE) ,
245 ENTER_MAXIMIZED_FROM_PEEKED_SWIPE);
246 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.FLING) ,
247 ENTER_MAXIMIZED_FROM_PEEKED_FLING);
248 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.SWIP E),
249 ENTER_MAXIMIZED_FROM_EXPANDED_SWIPE);
250 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.FLIN G),
251 ENTER_MAXIMIZED_FROM_EXPANDED_FLING);
252 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.SERP _NAVIGATION),
253 ENTER_MAXIMIZED_FROM_EXPANDED_SERP_NAVIGATION);
254 ENTER_MAXIMIZED_STATE_CHANGE_CODES = Collections.unmodifiableMap(codes);
255 }
256
257 // Exit code map: first exit from CLOSED.
258 private static final Map<StateChangeKey, Integer> EXIT_CLOSED_TO_STATE_CHANG E_CODES;
259 static {
260 Map<StateChangeKey, Integer> codes = new HashMap<StateChangeKey, Integer >();
261 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.TEXT_S ELECT_TAP),
262 EXIT_CLOSED_TO_PEEKED_TEXT_SELECT_TAP);
263 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.TEXT_S ELECT_LONG_PRESS),
264 EXIT_CLOSED_TO_PEEKED_TEXT_SELECT_LONG_PRESS);
265 EXIT_CLOSED_TO_STATE_CHANGE_CODES = Collections.unmodifiableMap(codes);
266 }
267
268 // Exit code map: first exit from PEEKED.
269 private static final Map<StateChangeKey, Integer> EXIT_PEEKED_TO_STATE_CHANG E_CODES;
270 static {
271 Map<StateChangeKey, Integer> codes = new HashMap<StateChangeKey, Integer >();
272 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.BACK_P RESS),
273 EXIT_PEEKED_TO_CLOSED_BACK_PRESS);
274 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.BASE_P AGE_SCROLL),
275 EXIT_PEEKED_TO_CLOSED_BASE_PAGE_SCROLL);
276 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.BASE_P AGE_TAP),
277 EXIT_PEEKED_TO_CLOSED_TEXT_SELECT_TAP);
278 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.TEXT_S ELECT_TAP),
279 EXIT_PEEKED_TO_PEEKED_TEXT_SELECT_TAP);
280 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.TEXT_S ELECT_LONG_PRESS),
281 EXIT_PEEKED_TO_PEEKED_TEXT_SELECT_LONG_PRESS);
282 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.SEAR CH_BAR_TAP),
283 EXIT_PEEKED_TO_EXPANDED_SEARCH_BAR_TAP);
284 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.SWIP E),
285 EXIT_PEEKED_TO_EXPANDED_SWIPE);
286 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.FLIN G),
287 EXIT_PEEKED_TO_EXPANDED_FLING);
288 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.SWI PE),
289 EXIT_PEEKED_TO_MAXIMIZED_SWIPE);
290 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.FLI NG),
291 EXIT_PEEKED_TO_MAXIMIZED_FLING);
292 EXIT_PEEKED_TO_STATE_CHANGE_CODES = Collections.unmodifiableMap(codes);
293 }
294
295 // Exit code map: first exit from EXPANDED.
296 private static final Map<StateChangeKey, Integer> EXIT_EXPANDED_TO_STATE_CHA NGE_CODES;
297 static {
298 Map<StateChangeKey, Integer> codes = new HashMap<StateChangeKey, Integer >();
299 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.BACK_P RESS),
300 EXIT_EXPANDED_TO_CLOSED_BACK_PRESS);
301 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.BASE_P AGE_TAP),
302 EXIT_EXPANDED_TO_CLOSED_BASE_PAGE_TAP);
303 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.FLING) ,
304 EXIT_EXPANDED_TO_CLOSED_FLING);
305 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.SEARCH _BAR_TAP),
306 EXIT_EXPANDED_TO_PEEKED_SEARCH_BAR_TAP);
307 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.SWIPE) ,
308 EXIT_EXPANDED_TO_PEEKED_SWIPE);
309 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.FLING) ,
310 EXIT_EXPANDED_TO_PEEKED_FLING);
311 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.SWI PE),
312 EXIT_EXPANDED_TO_MAXIMIZED_SWIPE);
313 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.FLI NG),
314 EXIT_EXPANDED_TO_MAXIMIZED_FLING);
315 codes.put(new StateChangeKey(PanelState.MAXIMIZED, StateChangeReason.SER P_NAVIGATION),
316 EXIT_EXPANDED_TO_MAXIMIZED_SERP_NAVIGATION);
317 EXIT_EXPANDED_TO_STATE_CHANGE_CODES = Collections.unmodifiableMap(codes) ;
318 }
319
320 // Exit code map: first exit from MAXIMIZED.
321 private static final Map<StateChangeKey, Integer> EXIT_MAXIMIZED_TO_STATE_CH ANGE_CODES;
322 static {
323 Map<StateChangeKey, Integer> codes = new HashMap<StateChangeKey, Integer >();
324 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.BACK_P RESS),
325 EXIT_MAXIMIZED_TO_CLOSED_BACK_PRESS);
326 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.FLING) ,
327 EXIT_MAXIMIZED_TO_CLOSED_FLING);
328 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.TAB_PR OMOTION),
329 EXIT_MAXIMIZED_TO_CLOSED_TAB_PROMOTION);
330 codes.put(new StateChangeKey(PanelState.CLOSED, StateChangeReason.SERP_N AVIGATION),
331 EXIT_MAXIMIZED_TO_CLOSED_SERP_NAVIGATION);
332 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.SWIPE) ,
333 EXIT_MAXIMIZED_TO_PEEKED_SWIPE);
334 codes.put(new StateChangeKey(PanelState.PEEKED, StateChangeReason.FLING) ,
335 EXIT_MAXIMIZED_TO_PEEKED_FLING);
336 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.SWIP E),
337 EXIT_MAXIMIZED_TO_EXPANDED_SWIPE);
338 codes.put(new StateChangeKey(PanelState.EXPANDED, StateChangeReason.FLIN G),
339 EXIT_MAXIMIZED_TO_EXPANDED_FLING);
340 EXIT_MAXIMIZED_TO_STATE_CHANGE_CODES = Collections.unmodifiableMap(codes );
341 }
342
343 /**
344 * Logs the state of the Contextual Search preference. This function should be called if the
345 * Contextual Search feature is enabled, and will track the different prefer ence settings
346 * (disabled, enabled or uninitialized). Calling more than once is fine.
347 */
348 public static void logPreferenceState() {
349 RecordHistogram.recordEnumeratedHistogram("Search.ContextualSearchPrefer enceState",
350 getPreferenceValue(), PREFERENCE_HISTOGRAM_BOUNDARY);
351 }
352
353 /**
354 * Logs changes to the Contextual Search preference, aside from those result ing from the first
355 * run flow.
356 * @param enabled Whether the preference is being enabled or disabled.
357 */
358 public static void logPreferenceChange(boolean enabled) {
359 RecordHistogram.recordEnumeratedHistogram("Search.ContextualSearchPrefer enceStateChange",
360 enabled ? PREFERENCE_ENABLED : PREFERENCE_DISABLED, PREFERENCE_H ISTOGRAM_BOUNDARY);
361 }
362
363 /**
364 * Logs the outcome of a first run flow.
365 */
366 public static void logFirstRunFlowOutcome() {
367 RecordHistogram.recordEnumeratedHistogram("Search.ContextualSearchFirstR unFlowOutcome",
368 getPreferenceValue(), PREFERENCE_HISTOGRAM_BOUNDARY);
369 }
370
371 /**
372 * Logs the duration of a Contextual Search.
373 * @param wereResultsSeen Whether search results were seen.
374 * @param isChained Whether the Contextual Search ended with the start of an other.
375 * @param durationMs The duration of the contextual search in milliseconds.
376 */
377 public static void logDuration(boolean wereResultsSeen, boolean isChained, l ong durationMs) {
378 if (wereResultsSeen) {
379 RecordHistogram.recordTimesHistogram("Search.ContextualSearchDuratio nSeen",
380 durationMs, TimeUnit.MILLISECONDS);
381 } else if (isChained) {
382 RecordHistogram.recordTimesHistogram("Search.ContextualSearchDuratio nUnseenChained",
383 durationMs, TimeUnit.MILLISECONDS);
384 } else {
385 RecordHistogram.recordTimesHistogram("Search.ContextualSearchDuratio nUnseen",
386 durationMs, TimeUnit.MILLISECONDS);
387 }
388 }
389
390 /**
391 * Logs whether the first run flow's panel was seen during the contextual se arch. This should
392 * only be called when the user exits the contextual search still in the und ecided state.
393 * @param wasPanelSeen Whether the first run flow's panel was seen.
394 */
395 public static void logFirstRunPanelSeen(boolean wasPanelSeen) {
396 RecordHistogram.recordEnumeratedHistogram("Search.ContextualSearchFirstR unPanelSeen",
397 wasPanelSeen ? RESULTS_SEEN : RESULTS_NOT_SEEN, RESULTS_SEEN_BOU NDARY);
398 }
399
400 /**
401 * Logs whether search results were seen during the contextual search.
402 * @param wereResultsSeen Whether search results were seen.
403 */
404 public static void logResultsSeen(boolean wereResultsSeen) {
405 RecordHistogram.recordEnumeratedHistogram("Search.ContextualSearchResult sSeen",
406 wereResultsSeen ? RESULTS_SEEN : RESULTS_NOT_SEEN, RESULTS_SEEN_ BOUNDARY);
407 }
408
409 /**
410 * Logs whether a selection is valid.
411 * @param isSelectionValid Whether the selection is valid.
412 */
413 public static void logSelectionIsValid(boolean isSelectionValid) {
414 RecordHistogram.recordEnumeratedHistogram("Search.ContextualSearchSelect ionValid",
415 isSelectionValid ? SELECTION_VALID : SELECTION_INVALID, SELECTIO N_BOUNDARY);
416 }
417
418 /**
419 * Logs whether a normal priority search request failed.
420 * @param isFailure Whether the request failed.
421 */
422 public static void logNormalPrioritySearchRequestOutcome(boolean isFailure) {
423 RecordHistogram.recordEnumeratedHistogram(
424 "Search.ContextualSearchNormalPrioritySearchRequestStatus",
425 isFailure ? REQUEST_FAILED : REQUEST_NOT_FAILED, REQUEST_BOUNDAR Y);
426 }
427
428 /**
429 * Logs whether a low priority search request failed.
430 * @param isFailure Whether the request failed.
431 */
432 public static void logLowPrioritySearchRequestOutcome(boolean isFailure) {
433 RecordHistogram.recordEnumeratedHistogram(
434 "Search.ContextualSearchLowPrioritySearchRequestStatus",
435 isFailure ? REQUEST_FAILED : REQUEST_NOT_FAILED, REQUEST_BOUNDAR Y);
436 }
437
438 /**
439 * Logs whether a fallback search request failed.
440 * @param isFailure Whether the request failed.
441 */
442 public static void logFallbackSearchRequestOutcome(boolean isFailure) {
443 RecordHistogram.recordEnumeratedHistogram(
444 "Search.ContextualSearchFallbackSearchRequestStatus",
445 isFailure ? REQUEST_FAILED : REQUEST_NOT_FAILED, REQUEST_BOUNDAR Y);
446 }
447
448 /**
449 * Logs how a state was entered for the first time within a Contextual Searc h.
450 * @param fromState The state to transition from.
451 * @param toState The state to transition to.
452 * @param reason The reason for the state transition.
453 */
454 public static void logFirstStateEntry(PanelState fromState, PanelState toSta te,
455 StateChangeReason reason) {
456 int code;
457 switch (toState) {
458 case CLOSED:
459 code = getStateChangeCode(fromState, reason,
460 ENTER_CLOSED_STATE_CHANGE_CODES, ENTER_CLOSED_FROM_OTHER );
461 RecordHistogram.recordEnumeratedHistogram(
462 "Search.ContextualSearchEnterClosed",
463 code, ENTER_CLOSED_FROM_BOUNDARY);
464 break;
465 case PEEKED:
466 code = getStateChangeCode(fromState, reason,
467 ENTER_PEEKED_STATE_CHANGE_CODES, ENTER_PEEKED_FROM_OTHER );
468 RecordHistogram.recordEnumeratedHistogram(
469 "Search.ContextualSearchEnterPeeked",
470 code, ENTER_PEEKED_FROM_BOUNDARY);
471 break;
472 case EXPANDED:
473 code = getStateChangeCode(fromState, reason,
474 ENTER_EXPANDED_STATE_CHANGE_CODES, ENTER_EXPANDED_FROM_O THER);
475 RecordHistogram.recordEnumeratedHistogram(
476 "Search.ContextualSearchEnterExpanded",
477 code, ENTER_EXPANDED_FROM_BOUNDARY);
478 break;
479 case MAXIMIZED:
480 code = getStateChangeCode(fromState, reason,
481 ENTER_MAXIMIZED_STATE_CHANGE_CODES, ENTER_MAXIMIZED_FROM _OTHER);
482 RecordHistogram.recordEnumeratedHistogram(
483 "Search.ContextualSearchEnterMaximized",
484 code, ENTER_MAXIMIZED_FROM_BOUNDARY);
485 break;
486 default:
487 break;
488 }
489 }
490
491 /**
492 * Logs how a state was exited for the first time within a Contextual Search .
493 * @param fromState The state to transition from.
494 * @param toState The state to transition to.
495 * @param reason The reason for the state transition.
496 */
497 public static void logFirstStateExit(PanelState fromState, PanelState toStat e,
498 StateChangeReason reason) {
499 int code;
500 switch (fromState) {
501 case UNDEFINED:
502 case CLOSED:
503 code = getStateChangeCode(toState, reason,
504 EXIT_CLOSED_TO_STATE_CHANGE_CODES, EXIT_CLOSED_TO_OTHER) ;
505 RecordHistogram.recordEnumeratedHistogram(
506 "Search.ContextualSearchExitClosed", code, EXIT_CLOSED_T O_BOUNDARY);
507 break;
508 case PEEKED:
509 code = getStateChangeCode(toState, reason,
510 EXIT_PEEKED_TO_STATE_CHANGE_CODES, EXIT_PEEKED_TO_OTHER) ;
511 RecordHistogram.recordEnumeratedHistogram(
512 "Search.ContextualSearchExitPeeked", code, EXIT_PEEKED_T O_BOUNDARY);
513 break;
514 case EXPANDED:
515 code = getStateChangeCode(toState, reason,
516 EXIT_EXPANDED_TO_STATE_CHANGE_CODES, EXIT_EXPANDED_TO_OT HER);
517 RecordHistogram.recordEnumeratedHistogram(
518 "Search.ContextualSearchExitExpanded", code, EXIT_EXPAND ED_TO_BOUNDARY);
519 break;
520 case MAXIMIZED:
521 code = getStateChangeCode(toState, reason,
522 EXIT_MAXIMIZED_TO_STATE_CHANGE_CODES, EXIT_MAXIMIZED_TO_ OTHER);
523 RecordHistogram.recordEnumeratedHistogram(
524 "Search.ContextualSearchExitMaximized", code, EXIT_MAXIM IZED_TO_BOUNDARY);
525 break;
526 default:
527 break;
528 }
529 }
530
531 private static int getStateChangeCode(PanelState state, StateChangeReason re ason,
532 Map<StateChangeKey, Integer> stateChangeCodes, int defaultCode) {
533 Integer code = stateChangeCodes.get(new StateChangeKey(state, reason));
534 if (code != null) {
535 return code;
536 }
537 return defaultCode;
538 }
539
540 private static int getPreferenceValue() {
541 PrefServiceBridge preferences = PrefServiceBridge.getInstance();
542 if (preferences.isContextualSearchUninitialized()) {
543 return PREFERENCE_UNINITIALIZED;
544 } else if (preferences.isContextualSearchDisabled()) {
545 return PREFERENCE_DISABLED;
546 }
547 return PREFERENCE_ENABLED;
548 }
549 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698