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

Unified Diff: chrome/browser/ui/android/infobars/translate_compact_infobar.cc

Issue 2920953002: Auto-always/never can at most triggered twice (new translate infobar) (Closed)
Patch Set: fix Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/android/infobars/translate_compact_infobar.cc
diff --git a/chrome/browser/ui/android/infobars/translate_compact_infobar.cc b/chrome/browser/ui/android/infobars/translate_compact_infobar.cc
index c7470dd76216c0c3b81dcee60f3771b1e527b2c0..05ca5b64afa7d408cd58815552d34083556a6396 100644
--- a/chrome/browser/ui/android/infobars/translate_compact_infobar.cc
+++ b/chrome/browser/ui/android/infobars/translate_compact_infobar.cc
@@ -71,6 +71,13 @@ void TranslateCompactInfoBar::ProcessButton(int action) {
JNIEnv* env = base::android::AttachCurrentThread();
Java_TranslateCompactInfoBar_setAutoAlwaysTranslate(env,
GetJavaInfoBar());
+
+ // Auto-always is triggered by the line above. Need to increment the
+ // auto-always counter.
+ delegate->IncrementTranslationAutoAlwaysCount();
+ // Reset translateAcceptedCount so that auto-always could be triggered
+ // again.
+ delegate->ResetTranslationAcceptedCount();
}
} else if (action == InfoBarAndroid::ACTION_TRANSLATE_SHOW_ORIGINAL) {
action_flags_ |= FLAG_REVERT;
@@ -137,7 +144,8 @@ void TranslateCompactInfoBar::ApplyBoolTranslateOption(
bool TranslateCompactInfoBar::ShouldAutoAlwaysTranslate() {
translate::TranslateInfoBarDelegate* delegate = GetDelegate();
- return (delegate->GetTranslationAcceptedCount() == kAcceptCountThreshold);
+ return (delegate->GetTranslationAcceptedCount() == kAcceptCountThreshold &&
+ delegate->GetTranslationAutoAlwaysCount() < kMaxNumberOfAutoAlways);
}
jboolean TranslateCompactInfoBar::ShouldAutoNeverTranslate(
@@ -157,7 +165,24 @@ jboolean TranslateCompactInfoBar::ShouldAutoNeverTranslate(
!delegate->IsTranslatableLanguageByPrefs())
return false;
- return (delegate->GetTranslationDeniedCount() == kDeniedCountThreshold);
+ int auto_never_count = delegate->GetTranslationAutoNeverCount();
+
+ // At the beginning (auto_never_count == 0), deniedCount starts at 0 and is
+ // off-by-one (because this checking is done before increment). However, after
+ // auto-never is triggered once (auto_never_count > 0), deniedCount starts at
+ // 1. So there is no off-by-one by then.
+ int off_by_one = auto_never_count == 0 ? 1 : 0;
+
+ bool never_translate = (delegate->GetTranslationDeniedCount() + off_by_one ==
+ kDeniedCountThreshold &&
+ auto_never_count < kMaxNumberOfAutoNever);
+ if (never_translate) {
+ // Auto-never will be triggered. Need to increment the auto-never counter.
+ delegate->IncrementTranslationAutoNeverCount();
+ // Reset translateDeniedCount so that auto-never could be triggered again.
+ delegate->ResetTranslationDeniedCount();
+ }
+ return never_translate;
}
translate::TranslateInfoBarDelegate* TranslateCompactInfoBar::GetDelegate() {

Powered by Google App Engine
This is Rietveld 408576698