Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Side by Side Diff: chrome/browser/translate/chrome_translate_client.cc

Issue 2941953002: Add switches for language detection and translation logging. (Closed)
Patch Set: updates Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/translate/chrome_translate_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/feature_list.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/path_service.h" 12 #include "base/path_service.h"
12 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/infobars/infobar_service.h" 17 #include "chrome/browser/infobars/infobar_service.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/sync/user_event_service_factory.h" 19 #include "chrome/browser/sync/user_event_service_factory.h"
19 #include "chrome/browser/translate/language_model_factory.h" 20 #include "chrome/browser/translate/language_model_factory.h"
20 #include "chrome/browser/translate/translate_accept_languages_factory.h" 21 #include "chrome/browser/translate/translate_accept_languages_factory.h"
21 #include "chrome/browser/translate/translate_ranker_factory.h" 22 #include "chrome/browser/translate/translate_ranker_factory.h"
22 #include "chrome/browser/translate/translate_service.h" 23 #include "chrome/browser/translate/translate_service.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
25 #include "chrome/browser/ui/browser_tabstrip.h" 26 #include "chrome/browser/ui/browser_tabstrip.h"
26 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/browser/ui/translate/translate_bubble_factory.h" 29 #include "chrome/browser/ui/translate/translate_bubble_factory.h"
29 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "chrome/grit/theme_resources.h" 32 #include "chrome/grit/theme_resources.h"
32 #include "components/metrics/proto/translate_event.pb.h" 33 #include "components/metrics/proto/translate_event.pb.h"
33 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
35 #include "components/sync/driver/sync_driver_switches.h"
34 #include "components/sync/protocol/user_event_specifics.pb.h" 36 #include "components/sync/protocol/user_event_specifics.pb.h"
35 #include "components/sync/user_events/user_event_service.h" 37 #include "components/sync/user_events/user_event_service.h"
36 #include "components/translate/core/browser/language_model.h" 38 #include "components/translate/core/browser/language_model.h"
37 #include "components/translate/core/browser/language_state.h" 39 #include "components/translate/core/browser/language_state.h"
38 #include "components/translate/core/browser/page_translated_details.h" 40 #include "components/translate/core/browser/page_translated_details.h"
39 #include "components/translate/core/browser/translate_accept_languages.h" 41 #include "components/translate/core/browser/translate_accept_languages.h"
40 #include "components/translate/core/browser/translate_download_manager.h" 42 #include "components/translate/core/browser/translate_download_manager.h"
41 #include "components/translate/core/browser/translate_infobar_delegate.h" 43 #include "components/translate/core/browser/translate_infobar_delegate.h"
42 #include "components/translate/core/browser/translate_manager.h" 44 #include "components/translate/core/browser/translate_manager.h"
43 #include "components/translate/core/browser/translate_prefs.h" 45 #include "components/translate/core/browser/translate_prefs.h"
44 #include "components/translate/core/common/language_detection_details.h" 46 #include "components/translate/core/common/language_detection_details.h"
45 #include "components/translate/core/common/language_detection_logging_helper.h" 47 #include "components/translate/core/common/language_detection_logging_helper.h"
46 #include "components/translate/core/common/translation_logging_helper.h" 48 #include "components/translate/core/common/translation_logging_helper.h"
47 #include "components/variations/service/variations_service.h" 49 #include "components/variations/service/variations_service.h"
48 #include "content/public/browser/navigation_entry.h" 50 #include "content/public/browser/navigation_entry.h"
49 #include "content/public/browser/notification_service.h" 51 #include "content/public/browser/notification_service.h"
50 #include "content/public/browser/render_view_host.h" 52 #include "content/public/browser/render_view_host.h"
51 #include "content/public/browser/web_contents.h" 53 #include "content/public/browser/web_contents.h"
52 #include "url/gurl.h" 54 #include "url/gurl.h"
53 55
54 namespace { 56 namespace {
57 using base::FeatureList;
55 using metrics::TranslateEventProto; 58 using metrics::TranslateEventProto;
56 59
57 TranslateEventProto::EventType BubbleResultToTranslateEvent( 60 TranslateEventProto::EventType BubbleResultToTranslateEvent(
58 ShowTranslateBubbleResult result) { 61 ShowTranslateBubbleResult result) {
59 switch (result) { 62 switch (result) {
60 case ShowTranslateBubbleResult::BROWSER_WINDOW_NOT_VALID: 63 case ShowTranslateBubbleResult::BROWSER_WINDOW_NOT_VALID:
61 return TranslateEventProto::BROWSER_WINDOW_IS_INVALID; 64 return TranslateEventProto::BROWSER_WINDOW_IS_INVALID;
62 case ShowTranslateBubbleResult::BROWSER_WINDOW_MINIMIZED: 65 case ShowTranslateBubbleResult::BROWSER_WINDOW_MINIMIZED:
63 return TranslateEventProto::BROWSER_WINDOW_IS_MINIMIZED; 66 return TranslateEventProto::BROWSER_WINDOW_IS_MINIMIZED;
64 case ShowTranslateBubbleResult::BROWSER_WINDOW_NOT_ACTIVE: 67 case ShowTranslateBubbleResult::BROWSER_WINDOW_NOT_ACTIVE:
65 return TranslateEventProto::BROWSER_WINDOW_NOT_ACTIVE; 68 return TranslateEventProto::BROWSER_WINDOW_NOT_ACTIVE;
66 case ShowTranslateBubbleResult::WEB_CONTENTS_NOT_ACTIVE: 69 case ShowTranslateBubbleResult::WEB_CONTENTS_NOT_ACTIVE:
67 return TranslateEventProto::WEB_CONTENTS_NOT_ACTIVE; 70 return TranslateEventProto::WEB_CONTENTS_NOT_ACTIVE;
68 case ShowTranslateBubbleResult::EDITABLE_FIELD_IS_ACTIVE: 71 case ShowTranslateBubbleResult::EDITABLE_FIELD_IS_ACTIVE:
69 return TranslateEventProto::EDITABLE_FIELD_IS_ACTIVE; 72 return TranslateEventProto::EDITABLE_FIELD_IS_ACTIVE;
70 default: 73 default:
71 NOTREACHED(); 74 NOTREACHED();
72 return metrics::TranslateEventProto::UNKNOWN; 75 return metrics::TranslateEventProto::UNKNOWN;
73 } 76 }
74 } 77 }
75 78
76 // ========== LOG LANGUAGE DETECTION EVENT ============== 79 // ========== LOG LANGUAGE DETECTION EVENT ==============
77 80
78 void LogLanguageDetectionEvent( 81 void LogLanguageDetectionEvent(
79 const content::WebContents* const web_contents, 82 const content::WebContents* const web_contents,
80 const translate::LanguageDetectionDetails& details) { 83 const translate::LanguageDetectionDetails& details) {
84 if (!FeatureList::IsEnabled(switches::kSyncUserLanguageDetectionEvents))
85 return;
81 auto* const profile = 86 auto* const profile =
82 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 87 Profile::FromBrowserContext(web_contents->GetBrowserContext());
83 88
84 syncer::UserEventService* const user_event_service = 89 syncer::UserEventService* const user_event_service =
85 browser_sync::UserEventServiceFactory::GetForProfile(profile); 90 browser_sync::UserEventServiceFactory::GetForProfile(profile);
86 91
87 const auto* const entry = 92 const auto* const entry =
88 web_contents->GetController().GetLastCommittedEntry(); 93 web_contents->GetController().GetLastCommittedEntry();
89 94
90 // If entry is null, we don't record the page. 95 // If entry is null, we don't record the page.
91 // The navigation entry can be null in situations like download or initial 96 // The navigation entry can be null in situations like download or initial
92 // blank page. 97 // blank page.
93 DCHECK(web_contents); 98 DCHECK(web_contents);
94 if (entry != nullptr && 99 if (entry != nullptr &&
95 TranslateService::IsTranslatableURL(entry->GetVirtualURL())) { 100 TranslateService::IsTranslatableURL(entry->GetVirtualURL())) {
96 user_event_service->RecordUserEvent( 101 user_event_service->RecordUserEvent(
97 translate::ConstructLanguageDetectionEvent( 102 translate::ConstructLanguageDetectionEvent(
98 entry->GetTimestamp().ToInternalValue(), details)); 103 entry->GetTimestamp().ToInternalValue(), details));
99 } 104 }
100 } 105 }
101 106
102 // ========== LOG TRANSLATE EVENT ============== 107 // ========== LOG TRANSLATE EVENT ==============
103 108
104 void LogTranslateEvent(const content::WebContents* const web_contents, 109 void LogTranslateEvent(const content::WebContents* const web_contents,
105 const metrics::TranslateEventProto& translate_event) { 110 const metrics::TranslateEventProto& translate_event) {
111 if (!FeatureList::IsEnabled(switches::kSyncUserTranslationEvents))
112 return;
106 DCHECK(web_contents); 113 DCHECK(web_contents);
107 auto* const profile = 114 auto* const profile =
108 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 115 Profile::FromBrowserContext(web_contents->GetBrowserContext());
109 116
110 syncer::UserEventService* const user_event_service = 117 syncer::UserEventService* const user_event_service =
111 browser_sync::UserEventServiceFactory::GetForProfile(profile); 118 browser_sync::UserEventServiceFactory::GetForProfile(profile);
112 119
113 const auto* const entry = 120 const auto* const entry =
114 web_contents->GetController().GetLastCommittedEntry(); 121 web_contents->GetController().GetLastCommittedEntry();
115 122
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 return ShowTranslateBubbleResult::SUCCESS; 441 return ShowTranslateBubbleResult::SUCCESS;
435 } 442 }
436 443
437 return TranslateBubbleFactory::Show(browser->window(), web_contents(), step, 444 return TranslateBubbleFactory::Show(browser->window(), web_contents(), step,
438 error_type); 445 error_type);
439 #else 446 #else
440 NOTREACHED(); 447 NOTREACHED();
441 return ShowTranslateBubbleResult::SUCCESS; 448 return ShowTranslateBubbleResult::SUCCESS;
442 #endif 449 #endif
443 } 450 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/translate/chrome_translate_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698