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 import android.text.TextUtils; | 8 import android.text.TextUtils; |
9 | 9 |
10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 /** | 255 /** |
256 * Updates all the counters to account for an open-action on the panel. | 256 * Updates all the counters to account for an open-action on the panel. |
257 */ | 257 */ |
258 void updateCountersForOpen() { | 258 void updateCountersForOpen() { |
259 // Always completely reset the tap counter, since it just counts taps | 259 // Always completely reset the tap counter, since it just counts taps |
260 // since the last open. | 260 // since the last open. |
261 mPreferenceManager.setContextualSearchTapCount(0); | 261 mPreferenceManager.setContextualSearchTapCount(0); |
| 262 mPreferenceManager.setContextualSearchTapQuickAnswerCount(0); |
262 | 263 |
263 // Disable the "promo tap" counter, but only if we're using the Opt-out
onboarding. | 264 // Disable the "promo tap" counter, but only if we're using the Opt-out
onboarding. |
264 // For Opt-in, we never disable the promo tap counter. | 265 // For Opt-in, we never disable the promo tap counter. |
265 if (isPromoAvailable()) { | 266 if (isPromoAvailable()) { |
266 getPromoTapCounter().disable(); | 267 getPromoTapCounter().disable(); |
267 | 268 |
268 // Bump the total-promo-opens counter. | 269 // Bump the total-promo-opens counter. |
269 int count = mPreferenceManager.getContextualSearchPromoOpenCount(); | 270 int count = mPreferenceManager.getContextualSearchPromoOpenCount(); |
270 mPreferenceManager.setContextualSearchPromoOpenCount(++count); | 271 mPreferenceManager.setContextualSearchPromoOpenCount(++count); |
271 ContextualSearchUma.logPromoOpenCount(count); | 272 ContextualSearchUma.logPromoOpenCount(count); |
272 } | 273 } |
273 } | 274 } |
274 | 275 |
275 /** | 276 /** |
| 277 * Updates Tap counters to account for a quick-answer caption shown on the p
anel. |
| 278 * @param wasActivatedByTap Whether the triggering gesture was a Tap or not. |
| 279 * @param doesAnswer Whether the caption is considered an answer rather than
just |
| 280 * informative. |
| 281 */ |
| 282 void updateCountersForQuickAnswer(boolean wasActivatedByTap, boolean doesAns
wer) { |
| 283 if (wasActivatedByTap && doesAnswer) { |
| 284 int tapsWithAnswerSinceOpen = |
| 285 mPreferenceManager.getContextualSearchTapQuickAnswerCount(); |
| 286 mPreferenceManager.setContextualSearchTapQuickAnswerCount(++tapsWith
AnswerSinceOpen); |
| 287 } |
| 288 } |
| 289 |
| 290 /** |
276 * @return Whether a verbatim request should be made for the given base page
, assuming there | 291 * @return Whether a verbatim request should be made for the given base page
, assuming there |
277 * is no exiting request. | 292 * is no exiting request. |
278 */ | 293 */ |
279 boolean shouldCreateVerbatimRequest() { | 294 boolean shouldCreateVerbatimRequest() { |
280 SelectionType selectionType = mSelectionController.getSelectionType(); | 295 SelectionType selectionType = mSelectionController.getSelectionType(); |
281 return (mSelectionController.getSelectedText() != null | 296 return (mSelectionController.getSelectedText() != null |
282 && (selectionType == SelectionType.LONG_PRESS | 297 && (selectionType == SelectionType.LONG_PRESS |
283 || (selectionType == SelectionType.TAP && !shouldPreviousTapReso
lve()))); | 298 || (selectionType == SelectionType.TAP && !shouldPreviousTapReso
lve()))); |
284 } | 299 } |
285 | 300 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 * @return Whether the given content view is for an HTTP page. | 535 * @return Whether the given content view is for an HTTP page. |
521 */ | 536 */ |
522 private boolean isBasePageHTTP(@Nullable URL url) { | 537 private boolean isBasePageHTTP(@Nullable URL url) { |
523 return url != null && "http".equals(url.getProtocol()); | 538 return url != null && "http".equals(url.getProtocol()); |
524 } | 539 } |
525 | 540 |
526 /** | 541 /** |
527 * @return Whether the tap resolve/prefetch limit has been exceeded. | 542 * @return Whether the tap resolve/prefetch limit has been exceeded. |
528 */ | 543 */ |
529 private boolean isTapBeyondTheLimit() { | 544 private boolean isTapBeyondTheLimit() { |
530 return getTapCount() > getTapLimit(); | 545 // Discount taps that caused a Quick Answer since the tap may not have b
een totally ignored. |
| 546 return getTapCount() - mPreferenceManager.getContextualSearchTapQuickAns
werCount() |
| 547 > getTapLimit(); |
531 } | 548 } |
532 | 549 |
533 /** | 550 /** |
534 * @return The limit of the number of taps to resolve or prefetch. | 551 * @return The limit of the number of taps to resolve or prefetch. |
535 */ | 552 */ |
536 private int getTapLimit() { | 553 private int getTapLimit() { |
537 return isUserUndecided() ? getTapLimitForUndecided() : getTapLimitForDec
ided(); | 554 return isUserUndecided() ? getTapLimitForUndecided() : getTapLimitForDec
ided(); |
538 } | 555 } |
539 | 556 |
540 private int getTapLimitForDecided() { | 557 private int getTapLimitForDecided() { |
(...skipping 18 matching lines...) Expand all Loading... |
559 | 576 |
560 /** | 577 /** |
561 * Sets the {@link ContextualSearchNetworkCommunicator} to use for server re
quests. | 578 * Sets the {@link ContextualSearchNetworkCommunicator} to use for server re
quests. |
562 * @param networkCommunicator The communicator for all future requests. | 579 * @param networkCommunicator The communicator for all future requests. |
563 */ | 580 */ |
564 @VisibleForTesting | 581 @VisibleForTesting |
565 public void setNetworkCommunicator(ContextualSearchNetworkCommunicator netwo
rkCommunicator) { | 582 public void setNetworkCommunicator(ContextualSearchNetworkCommunicator netwo
rkCommunicator) { |
566 mNetworkCommunicator = networkCommunicator; | 583 mNetworkCommunicator = networkCommunicator; |
567 } | 584 } |
568 } | 585 } |
OLD | NEW |