| 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_ui_delegate.h" | 5 #include "components/translate/core/browser/translate_ui_delegate.h" |
| 6 | 6 |
| 7 #include "base/i18n/string_compare.h" | 7 #include "base/i18n/string_compare.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "components/translate/core/browser/language_state.h" | 9 #include "components/translate/core/browser/language_state.h" |
| 10 #include "components/translate/core/browser/translate_client.h" | 10 #include "components/translate/core/browser/translate_client.h" |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 295 |
| 296 UMA_HISTOGRAM_BOOLEAN(kNeverTranslateSite, value); | 296 UMA_HISTOGRAM_BOOLEAN(kNeverTranslateSite, value); |
| 297 } | 297 } |
| 298 | 298 |
| 299 bool TranslateUIDelegate::ShouldAlwaysTranslate() { | 299 bool TranslateUIDelegate::ShouldAlwaysTranslate() { |
| 300 return prefs_->IsLanguagePairWhitelisted(GetOriginalLanguageCode(), | 300 return prefs_->IsLanguagePairWhitelisted(GetOriginalLanguageCode(), |
| 301 GetTargetLanguageCode()); | 301 GetTargetLanguageCode()); |
| 302 } | 302 } |
| 303 | 303 |
| 304 bool TranslateUIDelegate::ShouldAlwaysTranslateBeCheckedByDefault() { | 304 bool TranslateUIDelegate::ShouldAlwaysTranslateBeCheckedByDefault() { |
| 305 // After 2 clicks on Translate for the same language. | 305 // After N clicks on Translate for the same language. |
| 306 // We check for == 2 instead of >= 2 because if the user translates with the | 306 // We check for == N instead of >= N because if the user translates with the |
| 307 // "Always do this?" on, then the next time the bubble won't show up. | 307 // "Always do this?" on, then the next time the bubble won't show up. |
| 308 // The only chance the bubble will show up is after the user manually unchecks | 308 // The only chance the bubble will show up is after the user manually unchecks |
| 309 // "Always do this?". In that case, since it is after user explictly unchecks, | 309 // "Always do this?". In that case, since it is after user explictly unchecks, |
| 310 // we should show as it as unchecked so we only check == 2 instead of >= 2. | 310 // we should show as it as unchecked so we only check == N instead of >= N. |
| 311 return ShouldAlwaysTranslate() || | 311 return ShouldAlwaysTranslate() || |
| 312 prefs_->GetTranslationAcceptedCount(GetOriginalLanguageCode()) == 2; | 312 prefs_->ShouldAlwaysTranslateBeCheckedByDefault( |
| 313 GetOriginalLanguageCode()); |
| 313 } | 314 } |
| 314 | 315 |
| 315 void TranslateUIDelegate::SetAlwaysTranslate(bool value) { | 316 void TranslateUIDelegate::SetAlwaysTranslate(bool value) { |
| 316 const std::string& original_lang = GetOriginalLanguageCode(); | 317 const std::string& original_lang = GetOriginalLanguageCode(); |
| 317 const std::string& target_lang = GetTargetLanguageCode(); | 318 const std::string& target_lang = GetTargetLanguageCode(); |
| 318 if (value) | 319 if (value) |
| 319 prefs_->WhitelistLanguagePair(original_lang, target_lang); | 320 prefs_->WhitelistLanguagePair(original_lang, target_lang); |
| 320 else | 321 else |
| 321 prefs_->RemoveLanguagePairFromWhitelist(original_lang, target_lang); | 322 prefs_->RemoveLanguagePairFromWhitelist(original_lang, target_lang); |
| 322 | 323 |
| 323 UMA_HISTOGRAM_BOOLEAN(kAlwaysTranslateLang, value); | 324 UMA_HISTOGRAM_BOOLEAN(kAlwaysTranslateLang, value); |
| 324 } | 325 } |
| 325 | 326 |
| 326 std::string TranslateUIDelegate::GetPageHost() { | 327 std::string TranslateUIDelegate::GetPageHost() { |
| 327 if (!translate_driver_->HasCurrentPage()) | 328 if (!translate_driver_->HasCurrentPage()) |
| 328 return std::string(); | 329 return std::string(); |
| 329 return translate_driver_->GetLastCommittedURL().HostNoBrackets(); | 330 return translate_driver_->GetLastCommittedURL().HostNoBrackets(); |
| 330 } | 331 } |
| 331 | 332 |
| 332 } // namespace translate | 333 } // namespace translate |
| OLD | NEW |