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

Unified Diff: components/translate/core/browser/translate_prefs.cc

Issue 1923143003: Implement the 2016Q2 Translate UI designe spec out in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test breakage Created 4 years, 8 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: components/translate/core/browser/translate_prefs.cc
diff --git a/components/translate/core/browser/translate_prefs.cc b/components/translate/core/browser/translate_prefs.cc
index 436ca076c22fb6bdce50cb573ec94a4cca202004..aeaf76f7461ed1e339f447de33e18c1a5a3bbbd9 100644
--- a/components/translate/core/browser/translate_prefs.cc
+++ b/components/translate/core/browser/translate_prefs.cc
@@ -26,6 +26,8 @@ const char TranslatePrefs::kPrefTranslateWhitelists[] =
"translate_whitelists";
const char TranslatePrefs::kPrefTranslateDeniedCount[] =
"translate_denied_count_for_language";
+const char TranslatePrefs::kPrefTranslateIgnoredCount[] =
+ "translate_ignored_count_for_language";
const char TranslatePrefs::kPrefTranslateAcceptedCount[] =
"translate_accepted_count";
const char TranslatePrefs::kPrefTranslateBlockedLanguages[] =
@@ -96,6 +98,10 @@ void ExpandLanguageCodes(const std::vector<std::string>& languages,
} // namespace
+const base::Feature kTranslateUI2016Q2{
+ "TranslateUI2016Q2", base::FEATURE_DISABLED_BY_DEFAULT};
+
+
DenialTimeUpdate::DenialTimeUpdate(PrefService* prefs,
const std::string& language,
size_t max_denial_count)
@@ -182,6 +188,7 @@ void TranslatePrefs::ResetToDefaults() {
const std::string& language = *it;
ResetTranslationAcceptedCount(language);
ResetTranslationDeniedCount(language);
+ ResetTranslationIgnoredCount(language);
groby-ooo-7-16 2016/04/27 19:08:25 This always makes me queasy, because it spams a _l
ftang 2016/04/27 21:43:16 Acknowledged.
}
prefs_->ClearPref(kPrefTranslateLastDeniedTimeForLanguage);
@@ -316,6 +323,29 @@ void TranslatePrefs::ResetTranslationDeniedCount(const std::string& language) {
update.Get()->SetInteger(language, 0);
}
+int TranslatePrefs::GetTranslationIgnoredCount(
+ const std::string& language) const {
+ const base::DictionaryValue* dict =
+ prefs_->GetDictionary(kPrefTranslateIgnoredCount);
+ int count = 0;
+ return dict->GetInteger(language, &count) ? count : 0;
+}
+
+void TranslatePrefs::IncrementTranslationIgnoredCount(
+ const std::string& language) {
+ DictionaryPrefUpdate update(prefs_, kPrefTranslateIgnoredCount);
+ base::DictionaryValue* dict = update.Get();
+
+ int count = 0;
+ dict->GetInteger(language, &count);
+ dict->SetInteger(language, count + 1);
+}
+
+void TranslatePrefs::ResetTranslationIgnoredCount(const std::string& language) {
+ DictionaryPrefUpdate update(prefs_, kPrefTranslateIgnoredCount);
+ update.Get()->SetInteger(language, 0);
+}
+
int TranslatePrefs::GetTranslationAcceptedCount(const std::string& language) {
const base::DictionaryValue* dict =
prefs_->GetDictionary(kPrefTranslateAcceptedCount);
@@ -358,10 +388,17 @@ void TranslatePrefs::UpdateLastDeniedTime(const std::string& language) {
}
bool TranslatePrefs::IsTooOftenDenied(const std::string& language) const {
- const base::DictionaryValue* dict =
- prefs_->GetDictionary(kPrefTranslateTooOftenDeniedForLanguage);
- bool result = false;
- return dict->GetBoolean(language, &result) ? result : false;
+ if (base::FeatureList::IsEnabled(kTranslateUI2016Q2)) {
groby-ooo-7-16 2016/04/27 19:08:25 This technically does not belong on prefs. It's be
ftang 2016/04/27 21:43:15 I agree. could I do it later in a different cl?
groby-ooo-7-16 2016/04/29 05:26:14 Later CL is perfectly fine. It's not like this *in
+ // In the new logic, we only hide the Bubble if user denied for more than
+ // 3 times or user ignore more than 10 times.
groby-ooo-7-16 2016/04/27 19:08:25 nit: ignored.
ftang 2016/04/27 21:43:15 Done.
+ return (GetTranslationDeniedCount(language) > 3) ||
+ (GetTranslationIgnoredCount(language) > 10);
+ } else {
+ const base::DictionaryValue* dict =
+ prefs_->GetDictionary(kPrefTranslateTooOftenDeniedForLanguage);
+ bool result = false;
+ return dict->GetBoolean(language, &result) ? result : false;
+ }
}
void TranslatePrefs::ResetDenialState() {
@@ -453,6 +490,9 @@ void TranslatePrefs::RegisterProfilePrefs(
kPrefTranslateDeniedCount,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterDictionaryPref(
+ kPrefTranslateIgnoredCount,
+ user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
+ registry->RegisterDictionaryPref(
kPrefTranslateAcceptedCount,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterListPref(kPrefTranslateBlockedLanguages,

Powered by Google App Engine
This is Rietveld 408576698