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

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

Issue 1185703007: Disable translate when there is no API key (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: don't disable translate when testing Created 5 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_manager.cc
diff --git a/components/translate/core/browser/translate_manager.cc b/components/translate/core/browser/translate_manager.cc
index e97fd49fe99ebad094ebf296b42890aa0f1cf43e..09dfcfd761ae4cc7e7d432bdb7f25c04a556cd03 100644
--- a/components/translate/core/browser/translate_manager.cc
+++ b/components/translate/core/browser/translate_manager.cc
@@ -29,6 +29,7 @@
#include "components/translate/core/common/translate_pref_names.h"
#include "components/translate/core/common/translate_switches.h"
#include "components/translate/core/common/translate_util.h"
+#include "google_apis/google_api_keys.h"
#include "net/base/url_util.h"
#include "net/http/http_status_code.h"
@@ -95,6 +96,17 @@ void TranslateManager::InitiateTranslation(const std::string& page_lang) {
return;
}
+ if (!ignore_missing_key_for_testing_ &&
Miguel Garcia 2015/06/25 07:10:26 can you add a flag to enable it manually? the defa
+ !::google_apis::HasKeysConfigured()) {
+ // Without an API key, translate won't work, so don't offer to translate
+ // in the first place. Leave prefs::kEnableTranslate on, though, because
+ // that settings syncs and we don't want to turn off translate everywhere
+ // else.
+ TranslateBrowserMetrics::ReportInitiationStatus(
+ TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_KEY);
+ return;
+ }
+
PrefService* prefs = translate_client_->GetPrefs();
if (!prefs->GetBoolean(prefs::kEnableTranslate)) {
TranslateBrowserMetrics::ReportInitiationStatus(
@@ -391,4 +403,11 @@ LanguageState& TranslateManager::GetLanguageState() {
return language_state_;
}
+bool TranslateManager::ignore_missing_key_for_testing_ = false;
+
+// static
+void TranslateManager::SetIgnoreMissingKeyForTesting(bool ignore) {
+ ignore_missing_key_for_testing_ = ignore;
+}
+
} // namespace translate

Powered by Google App Engine
This is Rietveld 408576698