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

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

Issue 2090283002: add experimental param to control the triggering threshold to default Always Translate checked (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit test breakage Created 4 years, 6 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 83c7cc8e7ecc9253e3352199b870f05c4c1df94a..d15a76f24beb1e923cabf84236a81f7404e71a6c 100644
--- a/components/translate/core/browser/translate_prefs.cc
+++ b/components/translate/core/browser/translate_prefs.cc
@@ -7,6 +7,7 @@
#include <set>
#include "base/memory/ptr_util.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
@@ -17,6 +18,7 @@
#include "components/translate/core/browser/translate_download_manager.h"
#include "components/translate/core/browser/translate_experiment.h"
#include "components/translate/core/common/translate_util.h"
+#include "components/variations/variations_associated_data.h"
namespace translate {
@@ -35,6 +37,9 @@ const char TranslatePrefs::kPrefTranslateLastDeniedTimeForLanguage[] =
"translate_last_denied_time_for_language";
const char TranslatePrefs::kPrefTranslateTooOftenDeniedForLanguage[] =
"translate_too_often_denied_for_language";
+const char kTranslateUI2016Q2TrialName[] = "TranslateUI2016Q2";
+const char kNumOfTranslationTriggerAlways[] =
+ "num_of_translation_trigger_always";
// The below properties used to be used but now are deprecated. Don't use them
// since an old profile might have some values there.
@@ -448,6 +453,34 @@ bool TranslatePrefs::ShouldAutoTranslate(const std::string& original_language,
return false;
}
+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
+ const std::string& language) {
+ std::map<std::string, std::string> params;
+ 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.
+ if (variations::GetVariationParams(translate::kTranslateUI2016Q2TrialName,
+ &params)) {
+ 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.
+ params.find(translate::kNumOfTranslationTriggerAlways);
+ if (it != params.end()) {
+ base::StringToInt(it->second,
+ &num_of_translation_trigger_default_checked);
+ }
+ }
+
+ if (num_of_translation_trigger_default_checked < 0) {
+ return false;
+ }
+
+ // After N clicks on Translate for the same language.
+ // We check for == N instead of >= N because if the user translates with the
+ // "Always do this?" on, then the next time the bubble won't show up.
+ // The only chance the bubble will show up is after the user manually unchecks
+ // "Always do this?". In that case, since it is after user explictly unchecks,
+ // we should show as it as unchecked so we only check == N instead of >= N.
+ return GetTranslationAcceptedCount(language) ==
+ num_of_translation_trigger_default_checked;
+}
+
// static
void TranslatePrefs::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {

Powered by Google App Engine
This is Rietveld 408576698