Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/translate/core/browser/translate_infobar_delegate.h" | 5 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 const int kAlwaysTranslateMinCount = 1; | 42 const int kAlwaysTranslateMinCount = 1; |
| 43 const int kNeverTranslateMinCount = 2; | 43 const int kNeverTranslateMinCount = 2; |
| 44 #else | 44 #else |
| 45 const int kAlwaysTranslateMinCount = 3; | 45 const int kAlwaysTranslateMinCount = 3; |
| 46 const int kNeverTranslateMinCount = 3; | 46 const int kNeverTranslateMinCount = 3; |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 // For Compact UI, if number of consecutive translations is equal to this | 49 // For Compact UI, if number of consecutive translations is equal to this |
| 50 // number, infobar will automatically trigger "Always Translate". | 50 // number, infobar will automatically trigger "Always Translate". |
| 51 const int kAcceptCountThreshold = 5; | 51 const int kAcceptCountThreshold = 5; |
| 52 // For Compact UI, if number of consecutive denied is equal to this | |
| 53 // number, infobar will automatically trigger "Never Translate Language". | |
| 54 const int kDeniedCountThreshold = 7; | |
| 52 | 55 |
| 53 } // namespace | 56 } // namespace |
| 54 | 57 |
| 55 const base::Feature kTranslateCompactUI{"TranslateCompactUI", | 58 const base::Feature kTranslateCompactUI{"TranslateCompactUI", |
| 56 base::FEATURE_DISABLED_BY_DEFAULT}; | 59 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 57 | 60 |
| 58 const size_t TranslateInfoBarDelegate::kNoIndex = TranslateUIDelegate::kNoIndex; | 61 const size_t TranslateInfoBarDelegate::kNoIndex = TranslateUIDelegate::kNoIndex; |
| 59 | 62 |
| 60 TranslateInfoBarDelegate::~TranslateInfoBarDelegate() { | 63 TranslateInfoBarDelegate::~TranslateInfoBarDelegate() { |
| 61 } | 64 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 target_language_code(), TranslateErrors::NONE, false); | 304 target_language_code(), TranslateErrors::NONE, false); |
| 302 } | 305 } |
| 303 #endif | 306 #endif |
| 304 | 307 |
| 305 bool TranslateInfoBarDelegate::ShouldAutoAlwaysTranslate() { | 308 bool TranslateInfoBarDelegate::ShouldAutoAlwaysTranslate() { |
| 306 return (IsCompactUIEnabled() && | 309 return (IsCompactUIEnabled() && |
| 307 prefs_->GetTranslationAcceptedCount(original_language_code()) == | 310 prefs_->GetTranslationAcceptedCount(original_language_code()) == |
| 308 kAcceptCountThreshold); | 311 kAcceptCountThreshold); |
| 309 } | 312 } |
| 310 | 313 |
| 314 bool TranslateInfoBarDelegate::ShouldAutoNeverTranslate() { | |
|
Leo
2017/05/12 05:09:07
Can we move all the CompactUIEnabled logic to ui/a
Marti Wong
2017/05/12 07:16:11
Done.
| |
| 315 return (IsCompactUIEnabled() && | |
| 316 prefs_->GetTranslationDeniedCount(original_language_code()) == | |
| 317 kDeniedCountThreshold); | |
| 318 } | |
| 319 | |
| 311 // static | 320 // static |
| 312 void TranslateInfoBarDelegate::GetAfterTranslateStrings( | 321 void TranslateInfoBarDelegate::GetAfterTranslateStrings( |
| 313 std::vector<base::string16>* strings, | 322 std::vector<base::string16>* strings, |
| 314 bool* swap_languages, | 323 bool* swap_languages, |
| 315 bool autodetermined_source_language) { | 324 bool autodetermined_source_language) { |
| 316 DCHECK(strings); | 325 DCHECK(strings); |
| 317 | 326 |
| 318 if (autodetermined_source_language) { | 327 if (autodetermined_source_language) { |
| 319 size_t offset; | 328 size_t offset; |
| 320 base::string16 text = l10n_util::GetStringFUTF16( | 329 base::string16 text = l10n_util::GetStringFUTF16( |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 TranslationDeclined(); | 403 TranslationDeclined(); |
| 395 UMA_HISTOGRAM_BOOLEAN("Translate.DeclineTranslateCloseInfobar", true); | 404 UMA_HISTOGRAM_BOOLEAN("Translate.DeclineTranslateCloseInfobar", true); |
| 396 } | 405 } |
| 397 | 406 |
| 398 TranslateInfoBarDelegate* | 407 TranslateInfoBarDelegate* |
| 399 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 408 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
| 400 return this; | 409 return this; |
| 401 } | 410 } |
| 402 | 411 |
| 403 } // namespace translate | 412 } // namespace translate |
| OLD | NEW |