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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
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_manager.h" 5 #include "components/translate/core/browser/translate_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 11 matching lines...) Expand all
22 #include "components/translate/core/browser/translate_error_details.h" 22 #include "components/translate/core/browser/translate_error_details.h"
23 #include "components/translate/core/browser/translate_language_list.h" 23 #include "components/translate/core/browser/translate_language_list.h"
24 #include "components/translate/core/browser/translate_prefs.h" 24 #include "components/translate/core/browser/translate_prefs.h"
25 #include "components/translate/core/browser/translate_script.h" 25 #include "components/translate/core/browser/translate_script.h"
26 #include "components/translate/core/browser/translate_url_util.h" 26 #include "components/translate/core/browser/translate_url_util.h"
27 #include "components/translate/core/common/language_detection_details.h" 27 #include "components/translate/core/common/language_detection_details.h"
28 #include "components/translate/core/common/translate_constants.h" 28 #include "components/translate/core/common/translate_constants.h"
29 #include "components/translate/core/common/translate_pref_names.h" 29 #include "components/translate/core/common/translate_pref_names.h"
30 #include "components/translate/core/common/translate_switches.h" 30 #include "components/translate/core/common/translate_switches.h"
31 #include "components/translate/core/common/translate_util.h" 31 #include "components/translate/core/common/translate_util.h"
32 #include "google_apis/google_api_keys.h"
32 #include "net/base/url_util.h" 33 #include "net/base/url_util.h"
33 #include "net/http/http_status_code.h" 34 #include "net/http/http_status_code.h"
34 35
35 namespace translate { 36 namespace translate {
36 37
37 namespace { 38 namespace {
38 39
39 // Callbacks for translate errors. 40 // Callbacks for translate errors.
40 TranslateManager::TranslateErrorCallbackList* g_callback_list_ = NULL; 41 TranslateManager::TranslateErrorCallbackList* g_callback_list_ = NULL;
41 42
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 void TranslateManager::InitiateTranslation(const std::string& page_lang) { 89 void TranslateManager::InitiateTranslation(const std::string& page_lang) {
89 // Short-circuit out if not in a state where initiating translation makes 90 // Short-circuit out if not in a state where initiating translation makes
90 // sense (this method may be called muhtiple times for a given page). 91 // sense (this method may be called muhtiple times for a given page).
91 if (!language_state_.page_needs_translation() || 92 if (!language_state_.page_needs_translation() ||
92 language_state_.translation_pending() || 93 language_state_.translation_pending() ||
93 language_state_.translation_declined() || 94 language_state_.translation_declined() ||
94 language_state_.IsPageTranslated()) { 95 language_state_.IsPageTranslated()) {
95 return; 96 return;
96 } 97 }
97 98
99 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
100 !::google_apis::HasKeysConfigured()) {
101 // Without an API key, translate won't work, so don't offer to translate
102 // in the first place. Leave prefs::kEnableTranslate on, though, because
103 // that settings syncs and we don't want to turn off translate everywhere
104 // else.
105 TranslateBrowserMetrics::ReportInitiationStatus(
106 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_KEY);
107 return;
108 }
109
98 PrefService* prefs = translate_client_->GetPrefs(); 110 PrefService* prefs = translate_client_->GetPrefs();
99 if (!prefs->GetBoolean(prefs::kEnableTranslate)) { 111 if (!prefs->GetBoolean(prefs::kEnableTranslate)) {
100 TranslateBrowserMetrics::ReportInitiationStatus( 112 TranslateBrowserMetrics::ReportInitiationStatus(
101 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); 113 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS);
102 const std::string& locale = 114 const std::string& locale =
103 TranslateDownloadManager::GetInstance()->application_locale(); 115 TranslateDownloadManager::GetInstance()->application_locale();
104 TranslateBrowserMetrics::ReportLocalesOnDisabledByPrefs(locale); 116 TranslateBrowserMetrics::ReportLocalesOnDisabledByPrefs(locale);
105 return; 117 return;
106 } 118 }
107 119
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (TranslateDownloadManager::IsSupportedLanguage(auto_target_lang)) 396 if (TranslateDownloadManager::IsSupportedLanguage(auto_target_lang))
385 return auto_target_lang; 397 return auto_target_lang;
386 } 398 }
387 return std::string(); 399 return std::string();
388 } 400 }
389 401
390 LanguageState& TranslateManager::GetLanguageState() { 402 LanguageState& TranslateManager::GetLanguageState() {
391 return language_state_; 403 return language_state_;
392 } 404 }
393 405
406 bool TranslateManager::ignore_missing_key_for_testing_ = false;
407
408 // static
409 void TranslateManager::SetIgnoreMissingKeyForTesting(bool ignore) {
410 ignore_missing_key_for_testing_ = ignore;
411 }
412
394 } // namespace translate 413 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698