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 a7ca46a5fd556de36fb78eea4d974337d5259a52..6b9abee8850081c3c5430aa0187c0208f061038c 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_ && |
+ !::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( |
@@ -390,4 +402,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 |