OLD | NEW |
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 Loading... |
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 Loading... |
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_ && |
| 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 if (TranslateDownloadManager::IsSupportedLanguage(auto_target_lang)) | 395 if (TranslateDownloadManager::IsSupportedLanguage(auto_target_lang)) |
384 return auto_target_lang; | 396 return auto_target_lang; |
385 } | 397 } |
386 return std::string(); | 398 return std::string(); |
387 } | 399 } |
388 | 400 |
389 LanguageState& TranslateManager::GetLanguageState() { | 401 LanguageState& TranslateManager::GetLanguageState() { |
390 return language_state_; | 402 return language_state_; |
391 } | 403 } |
392 | 404 |
| 405 bool TranslateManager::ignore_missing_key_for_testing_ = false; |
| 406 |
| 407 // static |
| 408 void TranslateManager::SetIgnoreMissingKeyForTesting(bool ignore) { |
| 409 ignore_missing_key_for_testing_ = ignore; |
| 410 } |
| 411 |
393 } // namespace translate | 412 } // namespace translate |
OLD | NEW |