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

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

Issue 2400503002: [Translate] Integrate TranslateEventProto UMA logging into TranslateManager. (Closed)
Patch Set: hamelphi@'s comments Created 4 years, 2 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
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 <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/infobars/infobar_service.h" 15 #include "chrome/browser/infobars/infobar_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/translate/language_model_factory.h" 17 #include "chrome/browser/translate/language_model_factory.h"
18 #include "chrome/browser/translate/translate_accept_languages_factory.h" 18 #include "chrome/browser/translate/translate_accept_languages_factory.h"
19 #include "chrome/browser/translate/translate_service.h" 19 #include "chrome/browser/translate/translate_service.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_finder.h" 21 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_tabstrip.h" 22 #include "chrome/browser/ui/browser_tabstrip.h"
23 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/browser/ui/translate/translate_bubble_factory.h" 25 #include "chrome/browser/ui/translate/translate_bubble_factory.h"
26 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "chrome/grit/theme_resources.h" 28 #include "chrome/grit/theme_resources.h"
29 #include "components/metrics/proto/translate_event.pb.h"
29 #include "components/prefs/pref_service.h" 30 #include "components/prefs/pref_service.h"
30 #include "components/translate/core/browser/language_model.h" 31 #include "components/translate/core/browser/language_model.h"
31 #include "components/translate/core/browser/language_state.h" 32 #include "components/translate/core/browser/language_state.h"
32 #include "components/translate/core/browser/page_translated_details.h" 33 #include "components/translate/core/browser/page_translated_details.h"
33 #include "components/translate/core/browser/translate_accept_languages.h" 34 #include "components/translate/core/browser/translate_accept_languages.h"
34 #include "components/translate/core/browser/translate_download_manager.h" 35 #include "components/translate/core/browser/translate_download_manager.h"
35 #include "components/translate/core/browser/translate_infobar_delegate.h" 36 #include "components/translate/core/browser/translate_infobar_delegate.h"
36 #include "components/translate/core/browser/translate_manager.h" 37 #include "components/translate/core/browser/translate_manager.h"
37 #include "components/translate/core/browser/translate_prefs.h" 38 #include "components/translate/core/browser/translate_prefs.h"
38 #include "components/translate/core/common/language_detection_details.h" 39 #include "components/translate/core/common/language_detection_details.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 #endif 192 #endif
192 193
193 // Bubble UI. 194 // Bubble UI.
194 if (step == translate::TRANSLATE_STEP_BEFORE_TRANSLATE) { 195 if (step == translate::TRANSLATE_STEP_BEFORE_TRANSLATE) {
195 // TODO(droger): Move this logic out of UI code. 196 // TODO(droger): Move this logic out of UI code.
196 GetLanguageState().SetTranslateEnabled(true); 197 GetLanguageState().SetTranslateEnabled(true);
197 // In the new UI, continue offering translation after the user navigates to 198 // In the new UI, continue offering translation after the user navigates to
198 // another page. 199 // another page.
199 if (!base::FeatureList::IsEnabled(translate::kTranslateUI2016Q2) && 200 if (!base::FeatureList::IsEnabled(translate::kTranslateUI2016Q2) &&
200 !GetLanguageState().HasLanguageChanged()) { 201 !GetLanguageState().HasLanguageChanged()) {
202 if (translate_manager_) {
groby-ooo-7-16 2016/10/25 18:53:10 Should never be NULL - just DCHECK if you want to
Roger McFarlane (Chromium) 2016/10/25 20:07:56 translate_manager_ is reset to NULL on WebContents
groby-ooo-7-16 2016/10/25 23:17:21 We really shouldn't have to - ChromeTranslateClien
Roger McFarlane (Chromium) 2016/11/07 20:51:58 Done.
203 translate_manager_->RecordTranslateEvent(
204 metrics::TranslateEventProto::MATCHES_PREVIOUS_LANGUAGE);
205 }
201 return; 206 return;
202 } 207 }
203 208
204 if (!triggered_from_menu && 209 if (!triggered_from_menu &&
205 GetTranslatePrefs()->IsTooOftenDenied(source_language)) 210 GetTranslatePrefs()->IsTooOftenDenied(source_language)) {
211 if (translate_manager_) {
212 translate_manager_->RecordTranslateEvent(
213 metrics::TranslateEventProto::LANGUAGE_DISABLED_BY_AUTO_BLACKLIST);
214 }
206 return; 215 return;
216 }
207 } 217 }
208 ShowBubble(step, error_type); 218 ShowBubble(step, error_type);
209 } 219 }
210 220
211 translate::TranslateDriver* ChromeTranslateClient::GetTranslateDriver() { 221 translate::TranslateDriver* ChromeTranslateClient::GetTranslateDriver() {
212 return &translate_driver_; 222 return &translate_driver_;
213 } 223 }
214 224
215 PrefService* ChromeTranslateClient::GetPrefs() { 225 PrefService* ChromeTranslateClient::GetPrefs() {
216 DCHECK(web_contents()); 226 DCHECK(web_contents());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 #if !defined(OS_ANDROID) 322 #if !defined(OS_ANDROID)
313 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 323 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
314 324
315 // |browser| might be NULL when testing. In this case, Show(...) should be 325 // |browser| might be NULL when testing. In this case, Show(...) should be
316 // called because the implementation for testing is used. 326 // called because the implementation for testing is used.
317 if (!browser) { 327 if (!browser) {
318 TranslateBubbleFactory::Show(NULL, web_contents(), step, error_type); 328 TranslateBubbleFactory::Show(NULL, web_contents(), step, error_type);
319 return; 329 return;
320 } 330 }
321 331
322 if (web_contents() != browser->tab_strip_model()->GetActiveWebContents()) 332 if (web_contents() != browser->tab_strip_model()->GetActiveWebContents()) {
333 if (translate_manager_ &&
groby-ooo-7-16 2016/10/25 18:53:10 Is there a specific reason you're checking transla
Roger McFarlane (Chromium) 2016/10/25 20:07:56 Acknowledged. See previous commentary re: WebConte
334 step == translate::TRANSLATE_STEP_BEFORE_TRANSLATE) {
groby-ooo-7-16 2016/10/25 18:53:10 Why is this just recorded for BEFORE_TRANSLATE?
Roger McFarlane (Chromium) 2016/10/25 20:07:56 We're capturing the outcome of showing the transla
groby-ooo-7-16 2016/10/25 23:17:21 If you don't mind, could you add a comment here? B
Roger McFarlane (Chromium) 2016/11/07 20:51:58 Done.
335 translate_manager_->RecordTranslateEvent(
336 metrics::TranslateEventProto::WEBCONTENTS_NOT_ACTIVE);
337 }
323 return; 338 return;
339 }
324 340
325 // This ShowBubble function is also used for upating the existing bubble. 341 // This ShowBubble function is also used for updating the existing bubble.
326 // However, with the bubble shown, any browser windows are NOT activated 342 // However, with the bubble shown, any browser windows are NOT activated
327 // because the bubble takes the focus from the other widgets including the 343 // because the bubble takes the focus from the other widgets including the
328 // browser windows. So it is checked that |browser| is the last activated 344 // browser windows. So it is checked that |browser| is the last activated
329 // browser, not is now activated. 345 // browser, not is now activated.
330 if (browser != chrome::FindLastActive()) 346 if (browser != chrome::FindLastActive()) {
347 if (translate_manager_ &&
348 step == translate::TRANSLATE_STEP_BEFORE_TRANSLATE) {
349 translate_manager_->RecordTranslateEvent(
350 metrics::TranslateEventProto::BROSWER_WINDOW_NOT_ACTIVE);
groby-ooo-7-16 2016/10/25 18:53:10 See above :)
Roger McFarlane (Chromium) 2016/10/25 20:07:56 Acknowledged. See previous commentary re: WebConte
351 }
331 return; 352 return;
groby-ooo-7-16 2016/10/25 18:53:10 On a wider scale, I'm wondering it this should ret
Roger McFarlane (Chromium) 2016/10/25 20:07:56 In the most recent patchset, I've done something s
groby-ooo-7-16 2016/10/25 23:17:21 Is it worth doing in this patchset, or should we p
Roger McFarlane (Chromium) 2016/11/07 20:51:58 Done.
353 }
332 354
333 // During auto-translating, the bubble should not be shown. 355 // During auto-translating, the bubble should not be shown.
334 if (step == translate::TRANSLATE_STEP_TRANSLATING || 356 if (step == translate::TRANSLATE_STEP_TRANSLATING ||
335 step == translate::TRANSLATE_STEP_AFTER_TRANSLATE) { 357 step == translate::TRANSLATE_STEP_AFTER_TRANSLATE) {
336 if (GetLanguageState().InTranslateNavigation()) 358 if (GetLanguageState().InTranslateNavigation())
337 return; 359 return;
338 } 360 }
339 361
340 TranslateBubbleFactory::Show(browser->window(), web_contents(), step, 362 TranslateBubbleFactory::Show(browser->window(), web_contents(), step,
341 error_type); 363 error_type);
342 #else 364 #else
343 NOTREACHED(); 365 NOTREACHED();
344 #endif 366 #endif
345 } 367 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/frame/browser_view.cc » ('j') | chrome/browser/ui/views/frame/browser_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698