| 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 "ios/chrome/browser/translate/chrome_ios_translate_client.h" | 5 #include "ios/chrome/browser/translate/chrome_ios_translate_client.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "components/infobars/core/infobar.h" | 13 #include "components/infobars/core/infobar.h" |
| 14 #include "components/metrics/proto/translate_event.pb.h" | 14 #include "components/metrics/proto/translate_event.pb.h" |
| 15 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 16 #include "components/sync/driver/sync_driver_switches.h" | 16 #include "components/sync/driver/sync_driver_switches.h" |
| 17 #include "components/sync/protocol/user_event_specifics.pb.h" | 17 #include "components/sync/protocol/user_event_specifics.pb.h" |
| 18 #include "components/sync/user_events/user_event_service.h" | 18 #include "components/sync/user_events/user_event_service.h" |
| 19 #include "components/translate/core/browser/page_translated_details.h" | 19 #include "components/translate/core/browser/page_translated_details.h" |
| 20 #include "components/translate/core/browser/translate_accept_languages.h" | 20 #include "components/translate/core/browser/translate_accept_languages.h" |
| 21 #include "components/translate/core/browser/translate_infobar_delegate.h" | 21 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 22 #include "components/translate/core/browser/translate_manager.h" | 22 #include "components/translate/core/browser/translate_manager.h" |
| 23 #include "components/translate/core/browser/translate_prefs.h" | 23 #include "components/translate/core/browser/translate_prefs.h" |
| 24 #include "components/translate/core/browser/translate_step.h" | 24 #include "components/translate/core/browser/translate_step.h" |
| 25 #include "components/translate/core/common/language_detection_details.h" | 25 #include "components/translate/core/common/language_detection_details.h" |
| 26 #include "components/translate/core/common/language_detection_logging_helper.h" |
| 26 #include "components/translate/core/common/translation_logging_helper.h" | 27 #include "components/translate/core/common/translation_logging_helper.h" |
| 27 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 28 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 28 #include "ios/chrome/browser/infobars/infobar.h" | 29 #include "ios/chrome/browser/infobars/infobar.h" |
| 29 #include "ios/chrome/browser/infobars/infobar_controller.h" | 30 #include "ios/chrome/browser/infobars/infobar_controller.h" |
| 30 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" | 31 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" |
| 31 #include "ios/chrome/browser/pref_names.h" | 32 #include "ios/chrome/browser/pref_names.h" |
| 32 #import "ios/chrome/browser/sync/ios_user_event_service_factory.h" | 33 #import "ios/chrome/browser/sync/ios_user_event_service_factory.h" |
| 33 #import "ios/chrome/browser/translate/after_translate_infobar_controller.h" | 34 #import "ios/chrome/browser/translate/after_translate_infobar_controller.h" |
| 34 #import "ios/chrome/browser/translate/before_translate_infobar_controller.h" | 35 #import "ios/chrome/browser/translate/before_translate_infobar_controller.h" |
| 35 #include "ios/chrome/browser/translate/language_model_factory.h" | 36 #include "ios/chrome/browser/translate/language_model_factory.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 ios::ChromeBrowserState::FromBrowserState( | 187 ios::ChromeBrowserState::FromBrowserState( |
| 187 web_state()->GetBrowserState())); | 188 web_state()->GetBrowserState())); |
| 188 } | 189 } |
| 189 | 190 |
| 190 int ChromeIOSTranslateClient::GetInfobarIconID() const { | 191 int ChromeIOSTranslateClient::GetInfobarIconID() const { |
| 191 return IDR_IOS_INFOBAR_TRANSLATE; | 192 return IDR_IOS_INFOBAR_TRANSLATE; |
| 192 } | 193 } |
| 193 | 194 |
| 194 void ChromeIOSTranslateClient::RecordLanguageDetectionEvent( | 195 void ChromeIOSTranslateClient::RecordLanguageDetectionEvent( |
| 195 const translate::LanguageDetectionDetails& details) const { | 196 const translate::LanguageDetectionDetails& details) const { |
| 196 // TODO(crbug.com/728491): Implement this. | 197 if (!base::FeatureList::IsEnabled(switches::kSyncUserLanguageDetectionEvents)) |
| 198 return; |
| 199 |
| 200 syncer::UserEventService* const user_event_service = |
| 201 IOSUserEventServiceFactory::GetForBrowserState( |
| 202 ios::ChromeBrowserState::FromBrowserState( |
| 203 web_state()->GetBrowserState())); |
| 204 const auto* const item = |
| 205 web_state()->GetNavigationManager()->GetLastCommittedItem(); |
| 206 |
| 207 // If entry is null, we don't record the page. |
| 208 // The navigation entry can be null in situations like download or initial |
| 209 // blank page. |
| 210 if (item != nullptr && |
| 211 TranslateServiceIOS::IsTranslatableURL(item->GetVirtualURL())) { |
| 212 user_event_service->RecordUserEvent( |
| 213 translate::ConstructLanguageDetectionEvent( |
| 214 item->GetTimestamp().ToInternalValue(), details)); |
| 215 } |
| 197 } | 216 } |
| 198 | 217 |
| 199 bool ChromeIOSTranslateClient::IsTranslatableURL(const GURL& url) { | 218 bool ChromeIOSTranslateClient::IsTranslatableURL(const GURL& url) { |
| 200 return TranslateServiceIOS::IsTranslatableURL(url); | 219 return TranslateServiceIOS::IsTranslatableURL(url); |
| 201 } | 220 } |
| 202 | 221 |
| 203 void ChromeIOSTranslateClient::ShowReportLanguageDetectionErrorUI( | 222 void ChromeIOSTranslateClient::ShowReportLanguageDetectionErrorUI( |
| 204 const GURL& report_url) { | 223 const GURL& report_url) { |
| 205 NOTREACHED(); | 224 NOTREACHED(); |
| 206 } | 225 } |
| 207 | 226 |
| 208 void ChromeIOSTranslateClient::WebStateDestroyed() { | 227 void ChromeIOSTranslateClient::WebStateDestroyed() { |
| 209 // Translation process can be interrupted. | 228 // Translation process can be interrupted. |
| 210 // Destroying the TranslateManager now guarantees that it never has to deal | 229 // Destroying the TranslateManager now guarantees that it never has to deal |
| 211 // with nullptr WebState. | 230 // with nullptr WebState. |
| 212 translate_manager_.reset(); | 231 translate_manager_.reset(); |
| 213 } | 232 } |
| OLD | NEW |