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_prefs.h" | 5 #include "components/translate/core/browser/translate_prefs.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "components/pref_registry/pref_registry_syncable.h" | 14 #include "components/pref_registry/pref_registry_syncable.h" |
| 14 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 15 #include "components/prefs/scoped_user_pref_update.h" | 16 #include "components/prefs/scoped_user_pref_update.h" |
| 16 #include "components/translate/core/browser/translate_accept_languages.h" | 17 #include "components/translate/core/browser/translate_accept_languages.h" |
| 17 #include "components/translate/core/browser/translate_download_manager.h" | 18 #include "components/translate/core/browser/translate_download_manager.h" |
| 18 #include "components/translate/core/browser/translate_experiment.h" | 19 #include "components/translate/core/browser/translate_experiment.h" |
| 19 #include "components/translate/core/common/translate_util.h" | 20 #include "components/translate/core/common/translate_util.h" |
| 21 #include "components/variations/variations_associated_data.h" | |
| 20 | 22 |
| 21 namespace translate { | 23 namespace translate { |
| 22 | 24 |
| 23 const char TranslatePrefs::kPrefTranslateSiteBlacklist[] = | 25 const char TranslatePrefs::kPrefTranslateSiteBlacklist[] = |
| 24 "translate_site_blacklist"; | 26 "translate_site_blacklist"; |
| 25 const char TranslatePrefs::kPrefTranslateWhitelists[] = "translate_whitelists"; | 27 const char TranslatePrefs::kPrefTranslateWhitelists[] = "translate_whitelists"; |
| 26 const char TranslatePrefs::kPrefTranslateDeniedCount[] = | 28 const char TranslatePrefs::kPrefTranslateDeniedCount[] = |
| 27 "translate_denied_count_for_language"; | 29 "translate_denied_count_for_language"; |
| 28 const char TranslatePrefs::kPrefTranslateIgnoredCount[] = | 30 const char TranslatePrefs::kPrefTranslateIgnoredCount[] = |
| 29 "translate_ignored_count_for_language"; | 31 "translate_ignored_count_for_language"; |
| 30 const char TranslatePrefs::kPrefTranslateAcceptedCount[] = | 32 const char TranslatePrefs::kPrefTranslateAcceptedCount[] = |
| 31 "translate_accepted_count"; | 33 "translate_accepted_count"; |
| 32 const char TranslatePrefs::kPrefTranslateBlockedLanguages[] = | 34 const char TranslatePrefs::kPrefTranslateBlockedLanguages[] = |
| 33 "translate_blocked_languages"; | 35 "translate_blocked_languages"; |
| 34 const char TranslatePrefs::kPrefTranslateLastDeniedTimeForLanguage[] = | 36 const char TranslatePrefs::kPrefTranslateLastDeniedTimeForLanguage[] = |
| 35 "translate_last_denied_time_for_language"; | 37 "translate_last_denied_time_for_language"; |
| 36 const char TranslatePrefs::kPrefTranslateTooOftenDeniedForLanguage[] = | 38 const char TranslatePrefs::kPrefTranslateTooOftenDeniedForLanguage[] = |
| 37 "translate_too_often_denied_for_language"; | 39 "translate_too_often_denied_for_language"; |
| 40 const char kTranslateUI2016Q2TrialName[] = "TranslateUI2016Q2"; | |
| 41 const char kNumOfTranslationTriggerAlways[] = | |
| 42 "num_of_translation_trigger_always"; | |
| 38 | 43 |
| 39 // The below properties used to be used but now are deprecated. Don't use them | 44 // The below properties used to be used but now are deprecated. Don't use them |
| 40 // since an old profile might have some values there. | 45 // since an old profile might have some values there. |
| 41 // | 46 // |
| 42 // * translate_last_denied_time | 47 // * translate_last_denied_time |
| 43 // * translate_too_often_denied | 48 // * translate_too_often_denied |
| 44 // * translate_language_blacklist | 49 // * translate_language_blacklist |
| 45 | 50 |
| 46 namespace { | 51 namespace { |
| 47 | 52 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 std::string* target_language) { | 446 std::string* target_language) { |
| 442 const base::DictionaryValue* dict = | 447 const base::DictionaryValue* dict = |
| 443 prefs_->GetDictionary(kPrefTranslateWhitelists); | 448 prefs_->GetDictionary(kPrefTranslateWhitelists); |
| 444 if (dict && dict->GetString(original_language, target_language)) { | 449 if (dict && dict->GetString(original_language, target_language)) { |
| 445 DCHECK(!target_language->empty()); | 450 DCHECK(!target_language->empty()); |
| 446 return !target_language->empty(); | 451 return !target_language->empty(); |
| 447 } | 452 } |
| 448 return false; | 453 return false; |
| 449 } | 454 } |
| 450 | 455 |
| 456 bool TranslatePrefs::ShouldAlwaysTranslateBeCheckedByDefault( | |
|
groby-ooo-7-16
2016/06/27 23:00:34
This is moving even more policy decisions into pre
ftang
2016/06/28 05:01:46
moved
| |
| 457 const std::string& language) { | |
| 458 std::map<std::string, std::string> params; | |
| 459 int num_of_translation_trigger_default_checked = -1; | |
|
groby-ooo-7-16
2016/06/27 23:00:34
StringToInt *will* force this to 0 on error.
ftang
2016/06/28 05:01:46
Done.
| |
| 460 if (variations::GetVariationParams(translate::kTranslateUI2016Q2TrialName, | |
| 461 ¶ms)) { | |
| 462 std::map<std::string, std::string>::const_iterator it = | |
|
groby-ooo-7-16
2016/06/27 23:00:34
auto it = params.find
Or, if you want even short
ftang
2016/06/28 05:01:46
Done.
| |
| 463 params.find(translate::kNumOfTranslationTriggerAlways); | |
| 464 if (it != params.end()) { | |
| 465 base::StringToInt(it->second, | |
| 466 &num_of_translation_trigger_default_checked); | |
| 467 } | |
| 468 } | |
| 469 | |
| 470 if (num_of_translation_trigger_default_checked < 0) { | |
| 471 return false; | |
| 472 } | |
| 473 | |
| 474 // After N clicks on Translate for the same language. | |
| 475 // We check for == N instead of >= N because if the user translates with the | |
| 476 // "Always do this?" on, then the next time the bubble won't show up. | |
| 477 // The only chance the bubble will show up is after the user manually unchecks | |
| 478 // "Always do this?". In that case, since it is after user explictly unchecks, | |
| 479 // we should show as it as unchecked so we only check == N instead of >= N. | |
| 480 return GetTranslationAcceptedCount(language) == | |
| 481 num_of_translation_trigger_default_checked; | |
| 482 } | |
| 483 | |
| 451 // static | 484 // static |
| 452 void TranslatePrefs::RegisterProfilePrefs( | 485 void TranslatePrefs::RegisterProfilePrefs( |
| 453 user_prefs::PrefRegistrySyncable* registry) { | 486 user_prefs::PrefRegistrySyncable* registry) { |
| 454 registry->RegisterListPref(kPrefTranslateSiteBlacklist, | 487 registry->RegisterListPref(kPrefTranslateSiteBlacklist, |
| 455 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 488 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 456 registry->RegisterDictionaryPref( | 489 registry->RegisterDictionaryPref( |
| 457 kPrefTranslateWhitelists, | 490 kPrefTranslateWhitelists, |
| 458 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 491 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 459 registry->RegisterDictionaryPref( | 492 registry->RegisterDictionaryPref( |
| 460 kPrefTranslateDeniedCount, | 493 kPrefTranslateDeniedCount, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 const base::ListValue* blacklist = prefs_->GetList(pref_id); | 593 const base::ListValue* blacklist = prefs_->GetList(pref_id); |
| 561 return (blacklist == NULL || blacklist->empty()); | 594 return (blacklist == NULL || blacklist->empty()); |
| 562 } | 595 } |
| 563 | 596 |
| 564 bool TranslatePrefs::IsDictionaryEmpty(const char* pref_id) const { | 597 bool TranslatePrefs::IsDictionaryEmpty(const char* pref_id) const { |
| 565 const base::DictionaryValue* dict = prefs_->GetDictionary(pref_id); | 598 const base::DictionaryValue* dict = prefs_->GetDictionary(pref_id); |
| 566 return (dict == NULL || dict->empty()); | 599 return (dict == NULL || dict->empty()); |
| 567 } | 600 } |
| 568 | 601 |
| 569 } // namespace translate | 602 } // namespace translate |
| OLD | NEW |