Chromium Code Reviews| 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..58e28bd0e373da1162463a79bc7a4dbceab5dbcf 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,22 @@ jboolean TranslateCompactInfoBar::ShouldAutoNeverTranslate( |
| !delegate->IsTranslatableLanguageByPrefs()) |
| return false; |
| - return (delegate->GetTranslationDeniedCount() == kDeniedCountThreshold); |
| + int auto_never_count = delegate->GetTranslationAutoNeverCount(); |
| + |
| + // Because this checking is done before deniedCount is incremented, |
| + // deniedCount will be off by 1 when auto-never hasn't ever been triggered. |
| + int off_by_one = auto_never_count == 0 ? 1 : 0; |
|
mdjones
2017/06/09 17:43:37
Just out of curiosity, why is this only true if au
Marti Wong
2017/06/13 06:28:40
At the beginning, DeniedCount starts at 0. And the
|
| + |
| + bool return_value = (delegate->GetTranslationDeniedCount() + off_by_one == |
|
mdjones
2017/06/09 17:43:36
nit: "return_value" could probably be a bit more d
Marti Wong
2017/06/13 06:28:40
Done.
|
| + kDeniedCountThreshold && |
| + auto_never_count < kMaxNumberOfAutoNever); |
| + if (return_value) { |
| + // 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 return_value; |
| } |
| translate::TranslateInfoBarDelegate* TranslateCompactInfoBar::GetDelegate() { |