| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "components/translate/core/browser/translate_driver.h" | 27 #include "components/translate/core/browser/translate_driver.h" |
| 28 #include "components/translate/core/browser/translate_error_details.h" | 28 #include "components/translate/core/browser/translate_error_details.h" |
| 29 #include "components/translate/core/browser/translate_experiment.h" | 29 #include "components/translate/core/browser/translate_experiment.h" |
| 30 #include "components/translate/core/browser/translate_language_list.h" | 30 #include "components/translate/core/browser/translate_language_list.h" |
| 31 #include "components/translate/core/browser/translate_prefs.h" | 31 #include "components/translate/core/browser/translate_prefs.h" |
| 32 #include "components/translate/core/browser/translate_ranker.h" | 32 #include "components/translate/core/browser/translate_ranker.h" |
| 33 #include "components/translate/core/browser/translate_script.h" | 33 #include "components/translate/core/browser/translate_script.h" |
| 34 #include "components/translate/core/browser/translate_url_util.h" | 34 #include "components/translate/core/browser/translate_url_util.h" |
| 35 #include "components/translate/core/common/language_detection_details.h" | 35 #include "components/translate/core/common/language_detection_details.h" |
| 36 #include "components/translate/core/common/translate_constants.h" | 36 #include "components/translate/core/common/translate_constants.h" |
| 37 #include "components/translate/core/common/translate_pref_names.h" | |
| 38 #include "components/translate/core/common/translate_switches.h" | 37 #include "components/translate/core/common/translate_switches.h" |
| 39 #include "components/translate/core/common/translate_util.h" | 38 #include "components/translate/core/common/translate_util.h" |
| 40 #include "components/variations/variations_associated_data.h" | 39 #include "components/variations/variations_associated_data.h" |
| 41 #include "google_apis/google_api_keys.h" | 40 #include "google_apis/google_api_keys.h" |
| 42 #include "net/base/network_change_notifier.h" | 41 #include "net/base/network_change_notifier.h" |
| 43 #include "net/base/url_util.h" | 42 #include "net/base/url_util.h" |
| 44 #include "net/http/http_status_code.h" | 43 #include "net/http/http_status_code.h" |
| 45 | 44 |
| 46 namespace translate { | 45 namespace translate { |
| 47 | 46 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 !::google_apis::HasKeysConfigured()) { | 169 !::google_apis::HasKeysConfigured()) { |
| 171 // Without an API key, translate won't work, so don't offer to translate | 170 // Without an API key, translate won't work, so don't offer to translate |
| 172 // in the first place. Leave prefs::kEnableTranslate on, though, because | 171 // in the first place. Leave prefs::kEnableTranslate on, though, because |
| 173 // that settings syncs and we don't want to turn off translate everywhere | 172 // that settings syncs and we don't want to turn off translate everywhere |
| 174 // else. | 173 // else. |
| 175 TranslateBrowserMetrics::ReportInitiationStatus( | 174 TranslateBrowserMetrics::ReportInitiationStatus( |
| 176 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_KEY); | 175 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_KEY); |
| 177 return; | 176 return; |
| 178 } | 177 } |
| 179 | 178 |
| 180 PrefService* prefs = translate_client_->GetPrefs(); | 179 std::unique_ptr<TranslatePrefs> translate_prefs( |
| 181 if (!prefs->GetBoolean(prefs::kEnableTranslate)) { | 180 translate_client_->GetTranslatePrefs()); |
| 181 |
| 182 if (!translate_prefs->IsEnabled()) { |
| 182 TranslateBrowserMetrics::ReportInitiationStatus( | 183 TranslateBrowserMetrics::ReportInitiationStatus( |
| 183 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); | 184 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); |
| 184 RecordTranslateEvent(metrics::TranslateEventProto::DISABLED_BY_PREF); | 185 RecordTranslateEvent(metrics::TranslateEventProto::DISABLED_BY_PREF); |
| 185 const std::string& locale = | 186 const std::string& locale = |
| 186 TranslateDownloadManager::GetInstance()->application_locale(); | 187 TranslateDownloadManager::GetInstance()->application_locale(); |
| 187 TranslateBrowserMetrics::ReportLocalesOnDisabledByPrefs(locale); | 188 TranslateBrowserMetrics::ReportLocalesOnDisabledByPrefs(locale); |
| 188 return; | 189 return; |
| 189 } | 190 } |
| 190 | 191 |
| 191 // Allow disabling of translate from the command line to assist with | 192 // Allow disabling of translate from the command line to assist with |
| (...skipping 15 matching lines...) Expand all Loading... |
| 207 | 208 |
| 208 // Don't translate any Chrome specific page, e.g., New Tab Page, Download, | 209 // Don't translate any Chrome specific page, e.g., New Tab Page, Download, |
| 209 // History, and so on. | 210 // History, and so on. |
| 210 const GURL& page_url = translate_driver_->GetVisibleURL(); | 211 const GURL& page_url = translate_driver_->GetVisibleURL(); |
| 211 if (!translate_client_->IsTranslatableURL(page_url)) { | 212 if (!translate_client_->IsTranslatableURL(page_url)) { |
| 212 TranslateBrowserMetrics::ReportInitiationStatus( | 213 TranslateBrowserMetrics::ReportInitiationStatus( |
| 213 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); | 214 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); |
| 214 return; | 215 return; |
| 215 } | 216 } |
| 216 | 217 |
| 217 std::unique_ptr<TranslatePrefs> translate_prefs( | |
| 218 translate_client_->GetTranslatePrefs()); | |
| 219 | |
| 220 std::string target_lang = GetTargetLanguage(translate_prefs.get()); | 218 std::string target_lang = GetTargetLanguage(translate_prefs.get()); |
| 221 std::string language_code = | 219 std::string language_code = |
| 222 TranslateDownloadManager::GetLanguageCode(page_lang); | 220 TranslateDownloadManager::GetLanguageCode(page_lang); |
| 223 | 221 |
| 224 InitTranslateEvent(language_code, target_lang, *translate_prefs); | 222 InitTranslateEvent(language_code, target_lang, *translate_prefs); |
| 225 | 223 |
| 226 // Don't translate similar languages (ex: en-US to en). | 224 // Don't translate similar languages (ex: en-US to en). |
| 227 if (language_code == target_lang) { | 225 if (language_code == target_lang) { |
| 228 TranslateBrowserMetrics::ReportInitiationStatus( | 226 TranslateBrowserMetrics::ReportInitiationStatus( |
| 229 TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); | 227 TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 DCHECK(metrics::TranslateEventProto::EventType_IsValid(event_type)); | 604 DCHECK(metrics::TranslateEventProto::EventType_IsValid(event_type)); |
| 607 translate_event_->set_event_type( | 605 translate_event_->set_event_type( |
| 608 static_cast<metrics::TranslateEventProto::EventType>(event_type)); | 606 static_cast<metrics::TranslateEventProto::EventType>(event_type)); |
| 609 translate_event_->set_event_timestamp_sec( | 607 translate_event_->set_event_timestamp_sec( |
| 610 (base::TimeTicks::Now() - base::TimeTicks()).InSeconds()); | 608 (base::TimeTicks::Now() - base::TimeTicks()).InSeconds()); |
| 611 translate_ranker_->AddTranslateEvent(*translate_event_, | 609 translate_ranker_->AddTranslateEvent(*translate_event_, |
| 612 translate_driver_->GetVisibleURL()); | 610 translate_driver_->GetVisibleURL()); |
| 613 } | 611 } |
| 614 | 612 |
| 615 } // namespace translate | 613 } // namespace translate |
| OLD | NEW |