| 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.contextualsearch; | 5 package org.chromium.chrome.browser.contextualsearch; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 | 8 |
| 9 import org.chromium.base.VisibleForTesting; | 9 import org.chromium.base.VisibleForTesting; |
| 10 import org.chromium.chrome.browser.ChromeVersionInfo; | 10 import org.chromium.chrome.browser.ChromeVersionInfo; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 private static ContextualSearchPolicy sInstance; | 30 private static ContextualSearchPolicy sInstance; |
| 31 | 31 |
| 32 private final ChromePreferenceManager mPreferenceManager; | 32 private final ChromePreferenceManager mPreferenceManager; |
| 33 | 33 |
| 34 // Members used only for testing purposes. | 34 // Members used only for testing purposes. |
| 35 private boolean mDidOverrideDecidedStateForTesting; | 35 private boolean mDidOverrideDecidedStateForTesting; |
| 36 private boolean mDecidedStateForTesting; | 36 private boolean mDecidedStateForTesting; |
| 37 private boolean mDidResetCounters; | 37 private boolean mDidResetCounters; |
| 38 | 38 |
| 39 static ContextualSearchPolicy getInstance(Context context) { | 39 public static ContextualSearchPolicy getInstance(Context context) { |
| 40 if (sInstance == null) { | 40 if (sInstance == null) { |
| 41 sInstance = new ContextualSearchPolicy(context); | 41 sInstance = new ContextualSearchPolicy(context); |
| 42 } | 42 } |
| 43 return sInstance; | 43 return sInstance; |
| 44 } | 44 } |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Private constructor -- use {@link #getInstance} to get the singleton inst
ance. | 47 * Private constructor -- use {@link #getInstance} to get the singleton inst
ance. |
| 48 * @param context The Android Context. | 48 * @param context The Android Context. |
| 49 */ | 49 */ |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 /** | 145 /** |
| 146 * @return Whether the Opt-out promo is available to be shown in any panel. | 146 * @return Whether the Opt-out promo is available to be shown in any panel. |
| 147 */ | 147 */ |
| 148 boolean isPromoAvailable() { | 148 boolean isPromoAvailable() { |
| 149 return isUserUndecided(); | 149 return isUserUndecided(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 /** | 152 /** |
| 153 * @return Whether the Peek promo is available to be shown above the Search
Bar. |
| 154 */ |
| 155 public boolean isPeekPromoAvailable(ContextualSearchSelectionController cont
roller) { |
| 156 // Allow Promo to be forcefully enabled for testing. |
| 157 if (ContextualSearchFieldTrial.isPeekPromoForced()) return true; |
| 158 |
| 159 // Check for several conditions to determine whether the Peek Promo is a
vailable. |
| 160 |
| 161 // 1) Enabled by Finch. |
| 162 if (!ContextualSearchFieldTrial.isPeekPromoEnabled()) return false; |
| 163 |
| 164 // 2) If the Panel was never opened. |
| 165 if (getPromoOpenCount() > 0) return false; |
| 166 |
| 167 // 3) User has not opted in. |
| 168 if (!isUserUndecided()) return false; |
| 169 |
| 170 // 4) Selection was caused by a long press. |
| 171 if (controller.getSelectionType() != SelectionType.LONG_PRESS) return fa
lse; |
| 172 |
| 173 // 5) Promo was not shown more than the maximum number of times defined
by Finch. |
| 174 final int maxShowCount = ContextualSearchFieldTrial.getPeekPromoMaxShowC
ount(); |
| 175 final int peekPromoShowCount = mPreferenceManager.getContextualSearchPee
kPromoShowCount(); |
| 176 if (peekPromoShowCount >= maxShowCount) return false; |
| 177 |
| 178 // 6) Only then, show the promo. |
| 179 return true; |
| 180 } |
| 181 |
| 182 /** |
| 183 * Register that the Peek Promo was seen. |
| 184 */ |
| 185 public void registerPeekPromoSeen() { |
| 186 final int peekPromoShowCount = mPreferenceManager.getContextualSearchPee
kPromoShowCount(); |
| 187 mPreferenceManager.setContextualSearchPeekPromoShowCount(peekPromoShowCo
unt + 1); |
| 188 } |
| 189 |
| 190 /** |
| 153 * Registers that a tap has taken place by incrementing tap-tracking counter
s. | 191 * Registers that a tap has taken place by incrementing tap-tracking counter
s. |
| 154 */ | 192 */ |
| 155 void registerTap() { | 193 void registerTap() { |
| 156 if (isPromoAvailable()) { | 194 if (isPromoAvailable()) { |
| 157 DisableablePromoTapCounter promoTapCounter = getPromoTapCounter(); | 195 DisableablePromoTapCounter promoTapCounter = getPromoTapCounter(); |
| 158 // Bump the counter only when it is still enabled. | 196 // Bump the counter only when it is still enabled. |
| 159 if (promoTapCounter.isEnabled()) { | 197 if (promoTapCounter.isEnabled()) { |
| 160 promoTapCounter.increment(); | 198 promoTapCounter.increment(); |
| 161 } | 199 } |
| 162 } | 200 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 | 422 |
| 385 /** | 423 /** |
| 386 * @return The limit of the number of taps to resolve using search term reso
lution. | 424 * @return The limit of the number of taps to resolve using search term reso
lution. |
| 387 */ | 425 */ |
| 388 private int getTapResolveLimit() { | 426 private int getTapResolveLimit() { |
| 389 return isUserUndecided() | 427 return isUserUndecided() |
| 390 ? ContextualSearchFieldTrial.getTapResolveLimitForUndecided() | 428 ? ContextualSearchFieldTrial.getTapResolveLimitForUndecided() |
| 391 : ContextualSearchFieldTrial.getTapResolveLimitForDecided(); | 429 : ContextualSearchFieldTrial.getTapResolveLimitForDecided(); |
| 392 } | 430 } |
| 393 } | 431 } |
| OLD | NEW |