| 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 13 matching lines...) Expand all Loading... |
| 24 #include "components/translate/core/browser/translate_language_list.h" | 24 #include "components/translate/core/browser/translate_language_list.h" |
| 25 #include "components/translate/core/browser/translate_prefs.h" | 25 #include "components/translate/core/browser/translate_prefs.h" |
| 26 #include "components/translate/core/browser/translate_script.h" | 26 #include "components/translate/core/browser/translate_script.h" |
| 27 #include "components/translate/core/browser/translate_url_util.h" | 27 #include "components/translate/core/browser/translate_url_util.h" |
| 28 #include "components/translate/core/common/language_detection_details.h" | 28 #include "components/translate/core/common/language_detection_details.h" |
| 29 #include "components/translate/core/common/translate_constants.h" | 29 #include "components/translate/core/common/translate_constants.h" |
| 30 #include "components/translate/core/common/translate_pref_names.h" | 30 #include "components/translate/core/common/translate_pref_names.h" |
| 31 #include "components/translate/core/common/translate_switches.h" | 31 #include "components/translate/core/common/translate_switches.h" |
| 32 #include "components/translate/core/common/translate_util.h" | 32 #include "components/translate/core/common/translate_util.h" |
| 33 #include "google_apis/google_api_keys.h" | 33 #include "google_apis/google_api_keys.h" |
| 34 #include "net/base/network_change_notifier.h" |
| 34 #include "net/base/url_util.h" | 35 #include "net/base/url_util.h" |
| 35 #include "net/http/http_status_code.h" | 36 #include "net/http/http_status_code.h" |
| 36 | 37 |
| 37 namespace translate { | 38 namespace translate { |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 // Callbacks for translate errors. | 42 // Callbacks for translate errors. |
| 42 TranslateManager::TranslateErrorCallbackList* g_callback_list_ = NULL; | 43 TranslateManager::TranslateErrorCallbackList* g_callback_list_ = NULL; |
| 43 | 44 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 void TranslateManager::InitiateTranslation(const std::string& page_lang) { | 83 void TranslateManager::InitiateTranslation(const std::string& page_lang) { |
| 83 // Short-circuit out if not in a state where initiating translation makes | 84 // Short-circuit out if not in a state where initiating translation makes |
| 84 // sense (this method may be called muhtiple times for a given page). | 85 // sense (this method may be called muhtiple times for a given page). |
| 85 if (!language_state_.page_needs_translation() || | 86 if (!language_state_.page_needs_translation() || |
| 86 language_state_.translation_pending() || | 87 language_state_.translation_pending() || |
| 87 language_state_.translation_declined() || | 88 language_state_.translation_declined() || |
| 88 language_state_.IsPageTranslated()) { | 89 language_state_.IsPageTranslated()) { |
| 89 return; | 90 return; |
| 90 } | 91 } |
| 91 | 92 |
| 93 // Also, skip if the connection is currently offline - initiation doesn't make |
| 94 // sense there, either. |
| 95 if (net::NetworkChangeNotifier::IsOffline()) |
| 96 return; |
| 97 |
| 92 if (!ignore_missing_key_for_testing_ && | 98 if (!ignore_missing_key_for_testing_ && |
| 93 !::google_apis::HasKeysConfigured()) { | 99 !::google_apis::HasKeysConfigured()) { |
| 94 // Without an API key, translate won't work, so don't offer to translate | 100 // Without an API key, translate won't work, so don't offer to translate |
| 95 // in the first place. Leave prefs::kEnableTranslate on, though, because | 101 // in the first place. Leave prefs::kEnableTranslate on, though, because |
| 96 // that settings syncs and we don't want to turn off translate everywhere | 102 // that settings syncs and we don't want to turn off translate everywhere |
| 97 // else. | 103 // else. |
| 98 TranslateBrowserMetrics::ReportInitiationStatus( | 104 TranslateBrowserMetrics::ReportInitiationStatus( |
| 99 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_KEY); | 105 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_KEY); |
| 100 return; | 106 return; |
| 101 } | 107 } |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 } | 404 } |
| 399 | 405 |
| 400 bool TranslateManager::ignore_missing_key_for_testing_ = false; | 406 bool TranslateManager::ignore_missing_key_for_testing_ = false; |
| 401 | 407 |
| 402 // static | 408 // static |
| 403 void TranslateManager::SetIgnoreMissingKeyForTesting(bool ignore) { | 409 void TranslateManager::SetIgnoreMissingKeyForTesting(bool ignore) { |
| 404 ignore_missing_key_for_testing_ = ignore; | 410 ignore_missing_key_for_testing_ = ignore; |
| 405 } | 411 } |
| 406 | 412 |
| 407 } // namespace translate | 413 } // namespace translate |
| OLD | NEW |