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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 language_state_.IsPageTranslated()) { | 160 language_state_.IsPageTranslated()) { |
161 return; | 161 return; |
162 } | 162 } |
163 | 163 |
164 // Also, skip if the connection is currently offline - initiation doesn't make | 164 // Also, skip if the connection is currently offline - initiation doesn't make |
165 // sense there, either. | 165 // sense there, either. |
166 if (net::NetworkChangeNotifier::IsOffline()) | 166 if (net::NetworkChangeNotifier::IsOffline()) |
167 return; | 167 return; |
168 | 168 |
169 if (!ignore_missing_key_for_testing_ && | 169 if (!ignore_missing_key_for_testing_ && |
170 !::google_apis::HasKeysConfigured()) { | 170 !::google_apis::HasKeysConfigured()) { |
Takashi Toyoshima
2017/04/21 02:44:42
Yes, this check was added to fix the issue 500025,
| |
171 // Without an API key, translate won't work, so don't offer to translate | 171 // 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 | 172 // in the first place. Leave prefs::kEnableTranslate on, though, because |
173 // that settings syncs and we don't want to turn off translate everywhere | 173 // that settings syncs and we don't want to turn off translate everywhere |
174 // else. | 174 // else. |
175 TranslateBrowserMetrics::ReportInitiationStatus( | 175 TranslateBrowserMetrics::ReportInitiationStatus( |
176 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_KEY); | 176 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_KEY); |
177 return; | 177 return; |
178 } | 178 } |
179 | 179 |
180 PrefService* prefs = translate_client_->GetPrefs(); | 180 PrefService* prefs = translate_client_->GetPrefs(); |
181 if (!prefs->GetBoolean(prefs::kEnableTranslate)) { | 181 if (!prefs->GetBoolean(prefs::kEnableTranslate)) { |
182 TranslateBrowserMetrics::ReportInitiationStatus( | 182 TranslateBrowserMetrics::ReportInitiationStatus( |
183 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); | 183 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); |
184 RecordTranslateEvent(metrics::TranslateEventProto::DISABLED_BY_PREF); | 184 RecordTranslateEvent(metrics::TranslateEventProto::DISABLED_BY_PREF); |
185 const std::string& locale = | 185 const std::string& locale = |
186 TranslateDownloadManager::GetInstance()->application_locale(); | 186 TranslateDownloadManager::GetInstance()->application_locale(); |
187 TranslateBrowserMetrics::ReportLocalesOnDisabledByPrefs(locale); | 187 TranslateBrowserMetrics::ReportLocalesOnDisabledByPrefs(locale); |
188 return; | 188 return; |
189 } | 189 } |
190 | 190 |
191 // Allow disabling of translate from the command line to assist with | |
192 // automated browser testing. | |
193 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
194 translate::switches::kDisableTranslate)) { | |
195 TranslateBrowserMetrics::ReportInitiationStatus( | |
196 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH); | |
197 return; | |
198 } | |
199 | |
200 // MHTML pages currently cannot be translated. | 191 // MHTML pages currently cannot be translated. |
201 // See bug: 217945. | 192 // See bug: 217945. |
202 if (translate_driver_->GetContentsMimeType() == "multipart/related") { | 193 if (translate_driver_->GetContentsMimeType() == "multipart/related") { |
203 TranslateBrowserMetrics::ReportInitiationStatus( | 194 TranslateBrowserMetrics::ReportInitiationStatus( |
204 TranslateBrowserMetrics::INITIATION_STATUS_MIME_TYPE_IS_NOT_SUPPORTED); | 195 TranslateBrowserMetrics::INITIATION_STATUS_MIME_TYPE_IS_NOT_SUPPORTED); |
205 return; | 196 return; |
206 } | 197 } |
207 | 198 |
208 // Don't translate any Chrome specific page, e.g., New Tab Page, Download, | 199 // Don't translate any Chrome specific page, e.g., New Tab Page, Download, |
209 // History, and so on. | 200 // History, and so on. |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 DCHECK(metrics::TranslateEventProto::EventType_IsValid(event_type)); | 595 DCHECK(metrics::TranslateEventProto::EventType_IsValid(event_type)); |
605 translate_event_->set_event_type( | 596 translate_event_->set_event_type( |
606 static_cast<metrics::TranslateEventProto::EventType>(event_type)); | 597 static_cast<metrics::TranslateEventProto::EventType>(event_type)); |
607 translate_event_->set_event_timestamp_sec( | 598 translate_event_->set_event_timestamp_sec( |
608 (base::TimeTicks::Now() - base::TimeTicks()).InSeconds()); | 599 (base::TimeTicks::Now() - base::TimeTicks()).InSeconds()); |
609 translate_ranker_->AddTranslateEvent(*translate_event_, | 600 translate_ranker_->AddTranslateEvent(*translate_event_, |
610 translate_driver_->GetVisibleURL()); | 601 translate_driver_->GetVisibleURL()); |
611 } | 602 } |
612 | 603 |
613 } // namespace translate | 604 } // namespace translate |
OLD | NEW |