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 return getTapCount() - mPreferenceManager.getContextualSearchTapQuickAns werCount() |
twellington
2016/06/27 18:46:40
Do we need to do something like this in the other
Donn Denman
2016/06/27 20:43:00
Yes, thanks for reminding me. We can land this an
pedro (no code reviews)
2016/06/27 21:11:10
Put an explanation here to clarify why we are subt
| |
546 > getTapLimit(); | |
531 } | 547 } |
532 | 548 |
533 /** | 549 /** |
534 * @return The limit of the number of taps to resolve or prefetch. | 550 * @return The limit of the number of taps to resolve or prefetch. |
535 */ | 551 */ |
536 private int getTapLimit() { | 552 private int getTapLimit() { |
537 return isUserUndecided() ? getTapLimitForUndecided() : getTapLimitForDec ided(); | 553 return isUserUndecided() ? getTapLimitForUndecided() : getTapLimitForDec ided(); |
538 } | 554 } |
539 | 555 |
540 private int getTapLimitForDecided() { | 556 private int getTapLimitForDecided() { |
(...skipping 18 matching lines...) Expand all Loading... | |
559 | 575 |
560 /** | 576 /** |
561 * Sets the {@link ContextualSearchNetworkCommunicator} to use for server re quests. | 577 * Sets the {@link ContextualSearchNetworkCommunicator} to use for server re quests. |
562 * @param networkCommunicator The communicator for all future requests. | 578 * @param networkCommunicator The communicator for all future requests. |
563 */ | 579 */ |
564 @VisibleForTesting | 580 @VisibleForTesting |
565 public void setNetworkCommunicator(ContextualSearchNetworkCommunicator netwo rkCommunicator) { | 581 public void setNetworkCommunicator(ContextualSearchNetworkCommunicator netwo rkCommunicator) { |
566 mNetworkCommunicator = networkCommunicator; | 582 mNetworkCommunicator = networkCommunicator; |
567 } | 583 } |
568 } | 584 } |
OLD | NEW |