| 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 "chrome/browser/translate/chrome_translate_client.h" | 5 #include "chrome/browser/translate/chrome_translate_client.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "components/sync/user_events/user_event_service.h" | 35 #include "components/sync/user_events/user_event_service.h" |
| 36 #include "components/translate/core/browser/language_model.h" | 36 #include "components/translate/core/browser/language_model.h" |
| 37 #include "components/translate/core/browser/language_state.h" | 37 #include "components/translate/core/browser/language_state.h" |
| 38 #include "components/translate/core/browser/page_translated_details.h" | 38 #include "components/translate/core/browser/page_translated_details.h" |
| 39 #include "components/translate/core/browser/translate_accept_languages.h" | 39 #include "components/translate/core/browser/translate_accept_languages.h" |
| 40 #include "components/translate/core/browser/translate_download_manager.h" | 40 #include "components/translate/core/browser/translate_download_manager.h" |
| 41 #include "components/translate/core/browser/translate_infobar_delegate.h" | 41 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 42 #include "components/translate/core/browser/translate_manager.h" | 42 #include "components/translate/core/browser/translate_manager.h" |
| 43 #include "components/translate/core/browser/translate_prefs.h" | 43 #include "components/translate/core/browser/translate_prefs.h" |
| 44 #include "components/translate/core/common/language_detection_details.h" | 44 #include "components/translate/core/common/language_detection_details.h" |
| 45 #include "components/translate/core/common/language_detection_logging_helper.h" |
| 45 #include "components/variations/service/variations_service.h" | 46 #include "components/variations/service/variations_service.h" |
| 46 #include "content/public/browser/navigation_entry.h" | 47 #include "content/public/browser/navigation_entry.h" |
| 47 #include "content/public/browser/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
| 48 #include "content/public/browser/render_view_host.h" | 49 #include "content/public/browser/render_view_host.h" |
| 49 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" |
| 50 #include "url/gurl.h" | 51 #include "url/gurl.h" |
| 51 | 52 |
| 52 namespace { | 53 namespace { |
| 53 | 54 |
| 54 metrics::TranslateEventProto::EventType BubbleResultToTranslateEvent( | 55 metrics::TranslateEventProto::EventType BubbleResultToTranslateEvent( |
| 55 ShowTranslateBubbleResult result) { | 56 ShowTranslateBubbleResult result) { |
| 56 switch (result) { | 57 switch (result) { |
| 57 case ShowTranslateBubbleResult::BROWSER_WINDOW_NOT_VALID: | 58 case ShowTranslateBubbleResult::BROWSER_WINDOW_NOT_VALID: |
| 58 return metrics::TranslateEventProto::BROWSER_WINDOW_IS_INVALID; | 59 return metrics::TranslateEventProto::BROWSER_WINDOW_IS_INVALID; |
| 59 case ShowTranslateBubbleResult::BROWSER_WINDOW_MINIMIZED: | 60 case ShowTranslateBubbleResult::BROWSER_WINDOW_MINIMIZED: |
| 60 return metrics::TranslateEventProto::BROWSER_WINDOW_IS_MINIMIZED; | 61 return metrics::TranslateEventProto::BROWSER_WINDOW_IS_MINIMIZED; |
| 61 case ShowTranslateBubbleResult::BROWSER_WINDOW_NOT_ACTIVE: | 62 case ShowTranslateBubbleResult::BROWSER_WINDOW_NOT_ACTIVE: |
| 62 return metrics::TranslateEventProto::BROWSER_WINDOW_NOT_ACTIVE; | 63 return metrics::TranslateEventProto::BROWSER_WINDOW_NOT_ACTIVE; |
| 63 case ShowTranslateBubbleResult::WEB_CONTENTS_NOT_ACTIVE: | 64 case ShowTranslateBubbleResult::WEB_CONTENTS_NOT_ACTIVE: |
| 64 return metrics::TranslateEventProto::WEB_CONTENTS_NOT_ACTIVE; | 65 return metrics::TranslateEventProto::WEB_CONTENTS_NOT_ACTIVE; |
| 65 case ShowTranslateBubbleResult::EDITABLE_FIELD_IS_ACTIVE: | 66 case ShowTranslateBubbleResult::EDITABLE_FIELD_IS_ACTIVE: |
| 66 return metrics::TranslateEventProto::EDITABLE_FIELD_IS_ACTIVE; | 67 return metrics::TranslateEventProto::EDITABLE_FIELD_IS_ACTIVE; |
| 67 default: | 68 default: |
| 68 NOTREACHED(); | 69 NOTREACHED(); |
| 69 return metrics::TranslateEventProto::UNKNOWN; | 70 return metrics::TranslateEventProto::UNKNOWN; |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 | 73 |
| 73 std::unique_ptr<sync_pb::UserEventSpecifics> ConstructLanguageDetectionEvent( | |
| 74 const int entry_id, | |
| 75 const translate::LanguageDetectionDetails& details) { | |
| 76 auto specifics = base::MakeUnique<sync_pb::UserEventSpecifics>(); | |
| 77 specifics->set_event_time_usec(base::Time::Now().ToInternalValue()); | |
| 78 | |
| 79 // TODO(renjieliu): Revisit this field when the best way to identify | |
| 80 // navigations is determined. | |
| 81 specifics->set_navigation_id(base::Time::Now().ToInternalValue()); | |
| 82 | |
| 83 sync_pb::LanguageDetection lang_detection; | |
| 84 auto* const lang = lang_detection.add_detected_languages(); | |
| 85 lang->set_language_code(details.cld_language); | |
| 86 lang->set_is_reliable(details.is_cld_reliable); | |
| 87 // Only set adopted_language when it's different from cld_language. | |
| 88 if (details.adopted_language != details.cld_language) { | |
| 89 lang_detection.set_adopted_language_code(details.adopted_language); | |
| 90 } | |
| 91 *specifics->mutable_language_detection() = lang_detection; | |
| 92 return specifics; | |
| 93 } | |
| 94 | |
| 95 void LogLanguageDetectionEvent( | 74 void LogLanguageDetectionEvent( |
| 96 const content::WebContents* const web_contents, | 75 const content::WebContents* const web_contents, |
| 97 const translate::LanguageDetectionDetails& details) { | 76 const translate::LanguageDetectionDetails& details) { |
| 98 auto* const profile = | 77 auto* const profile = |
| 99 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 78 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 100 | 79 |
| 101 syncer::UserEventService* const user_event_service = | 80 syncer::UserEventService* const user_event_service = |
| 102 browser_sync::UserEventServiceFactory::GetForProfile(profile); | 81 browser_sync::UserEventServiceFactory::GetForProfile(profile); |
| 103 | 82 |
| 104 const auto* const entry = | 83 const auto* const entry = |
| 105 web_contents->GetController().GetLastCommittedEntry(); | 84 web_contents->GetController().GetLastCommittedEntry(); |
| 106 | 85 |
| 107 // If entry is null, we don't record the page. | 86 // If entry is null, we don't record the page. |
| 108 // The navigation entry can be null in situations like download or initial | 87 // The navigation entry can be null in situations like download or initial |
| 109 // blank page. | 88 // blank page. |
| 110 if (entry != nullptr) { | 89 if (entry != nullptr) { |
| 111 user_event_service->RecordUserEvent( | 90 user_event_service->RecordUserEvent( |
| 112 ConstructLanguageDetectionEvent(entry->GetUniqueID(), details)); | 91 translate::ConstructLanguageDetectionEvent(details)); |
| 113 } | 92 } |
| 114 } | 93 } |
| 115 | 94 |
| 116 } // namespace | 95 } // namespace |
| 117 | 96 |
| 118 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient); | 97 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient); |
| 119 | 98 |
| 120 ChromeTranslateClient::ChromeTranslateClient(content::WebContents* web_contents) | 99 ChromeTranslateClient::ChromeTranslateClient(content::WebContents* web_contents) |
| 121 : content::WebContentsObserver(web_contents), | 100 : content::WebContentsObserver(web_contents), |
| 122 translate_driver_(&web_contents->GetController()), | 101 translate_driver_(&web_contents->GetController()), |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 return ShowTranslateBubbleResult::SUCCESS; | 392 return ShowTranslateBubbleResult::SUCCESS; |
| 414 } | 393 } |
| 415 | 394 |
| 416 return TranslateBubbleFactory::Show(browser->window(), web_contents(), step, | 395 return TranslateBubbleFactory::Show(browser->window(), web_contents(), step, |
| 417 error_type); | 396 error_type); |
| 418 #else | 397 #else |
| 419 NOTREACHED(); | 398 NOTREACHED(); |
| 420 return ShowTranslateBubbleResult::SUCCESS; | 399 return ShowTranslateBubbleResult::SUCCESS; |
| 421 #endif | 400 #endif |
| 422 } | 401 } |
| OLD | NEW |