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

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

Issue 15646003: Translate: UMA for "Show original" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: (rebase) Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/translate_infobar_delegate.h" 5 #include "chrome/browser/translate/translate_infobar_delegate.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/string_compare.h" 9 #include "base/i18n/string_compare.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/translate/translate_manager.h" 14 #include "chrome/browser/translate/translate_manager.h"
15 #include "chrome/browser/translate/translate_tab_helper.h" 15 #include "chrome/browser/translate/translate_tab_helper.h"
16 #include "content/public/browser/navigation_details.h" 16 #include "content/public/browser/navigation_details.h"
17 #include "content/public/browser/navigation_entry.h" 17 #include "content/public/browser/navigation_entry.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
21 #include "third_party/icu/public/i18n/unicode/coll.h" 21 #include "third_party/icu/public/i18n/unicode/coll.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 23
24 using content::NavigationEntry; 24 using content::NavigationEntry;
25 25
26 namespace { 26 namespace {
27 27
28 const char kTranslateShowErrorInfobar[] = "Translate.ShowErrorInfobar"; 28 const char kDeclineTranslate[] = "Translate.DeclineTranslate";
29 const char kCloseInfobar[] = "Translate.DeclineTranslateCloseInfobar";
30 const char kRevertTranslation[] = "Translate.RevertTranslation";
31 const char kShowErrorInfobar[] = "Translate.ShowErrorInfobar";
32 const char kPerformTranslate[] = "Translate.Translate";
29 33
30 } // namespace 34 } // namespace
31 35
32 // static 36 // static
33 const size_t TranslateInfoBarDelegate::kNoIndex = static_cast<size_t>(-1); 37 const size_t TranslateInfoBarDelegate::kNoIndex = static_cast<size_t>(-1);
34 38
35 TranslateInfoBarDelegate::~TranslateInfoBarDelegate() { 39 TranslateInfoBarDelegate::~TranslateInfoBarDelegate() {
36 } 40 }
37 41
38 // static 42 // static
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 void TranslateInfoBarDelegate::Translate() { 84 void TranslateInfoBarDelegate::Translate() {
81 if (!web_contents()->GetBrowserContext()->IsOffTheRecord()) { 85 if (!web_contents()->GetBrowserContext()->IsOffTheRecord()) {
82 prefs_.ResetTranslationDeniedCount(original_language_code()); 86 prefs_.ResetTranslationDeniedCount(original_language_code());
83 prefs_.IncrementTranslationAcceptedCount(original_language_code()); 87 prefs_.IncrementTranslationAcceptedCount(original_language_code());
84 } 88 }
85 89
86 TranslateManager::GetInstance()->TranslatePage(web_contents(), 90 TranslateManager::GetInstance()->TranslatePage(web_contents(),
87 original_language_code(), 91 original_language_code(),
88 target_language_code()); 92 target_language_code());
89 93
90 UMA_HISTOGRAM_COUNTS("Translate.Translate", 1); 94 UMA_HISTOGRAM_COUNTS(kPerformTranslate, 1);
91 } 95 }
92 96
93 void TranslateInfoBarDelegate::RevertTranslation() { 97 void TranslateInfoBarDelegate::RevertTranslation() {
94 TranslateManager::GetInstance()->RevertTranslation(web_contents()); 98 TranslateManager::GetInstance()->RevertTranslation(web_contents());
95 RemoveSelf(); 99 RemoveSelf();
100
101 UMA_HISTOGRAM_COUNTS(kRevertTranslation, 1);
96 } 102 }
97 103
98 void TranslateInfoBarDelegate::ReportLanguageDetectionError() { 104 void TranslateInfoBarDelegate::ReportLanguageDetectionError() {
99 TranslateManager::GetInstance()-> 105 TranslateManager::GetInstance()->
100 ReportLanguageDetectionError(web_contents()); 106 ReportLanguageDetectionError(web_contents());
101 } 107 }
102 108
103 void TranslateInfoBarDelegate::TranslationDeclined() { 109 void TranslateInfoBarDelegate::TranslationDeclined() {
104 if (!web_contents()->GetBrowserContext()->IsOffTheRecord()) { 110 if (!web_contents()->GetBrowserContext()->IsOffTheRecord()) {
105 prefs_.ResetTranslationAcceptedCount(original_language_code()); 111 prefs_.ResetTranslationAcceptedCount(original_language_code());
106 prefs_.IncrementTranslationDeniedCount(original_language_code()); 112 prefs_.IncrementTranslationDeniedCount(original_language_code());
107 } 113 }
108 114
109 // Remember that the user declined the translation so as to prevent showing a 115 // Remember that the user declined the translation so as to prevent showing a
110 // translate infobar for that page again. (TranslateManager initiates 116 // translate infobar for that page again. (TranslateManager initiates
111 // translations when getting a LANGUAGE_DETERMINED from the page, which 117 // translations when getting a LANGUAGE_DETERMINED from the page, which
112 // happens when a load stops. That could happen multiple times, including 118 // happens when a load stops. That could happen multiple times, including
113 // after the user already declined the translation.) 119 // after the user already declined the translation.)
114 TranslateTabHelper* translate_tab_helper = 120 TranslateTabHelper* translate_tab_helper =
115 TranslateTabHelper::FromWebContents(web_contents()); 121 TranslateTabHelper::FromWebContents(web_contents());
116 translate_tab_helper->language_state().set_translation_declined(true); 122 translate_tab_helper->language_state().set_translation_declined(true);
117 123
118 UMA_HISTOGRAM_COUNTS("Translate.DeclineTranslate", 1); 124 UMA_HISTOGRAM_COUNTS(kDeclineTranslate, 1);
119 } 125 }
120 126
121 bool TranslateInfoBarDelegate::InTranslateNavigation() { 127 bool TranslateInfoBarDelegate::InTranslateNavigation() {
122 TranslateTabHelper* translate_tab_helper = 128 TranslateTabHelper* translate_tab_helper =
123 TranslateTabHelper::FromWebContents(web_contents()); 129 TranslateTabHelper::FromWebContents(web_contents());
124 if (!translate_tab_helper) 130 if (!translate_tab_helper)
125 return false; 131 return false;
126 return translate_tab_helper->language_state().InTranslateNavigation(); 132 return translate_tab_helper->language_state().InTranslateNavigation();
127 } 133 }
128 134
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 RemoveSelf(); 193 RemoveSelf();
188 } 194 }
189 195
190 string16 TranslateInfoBarDelegate::GetMessageInfoBarText() { 196 string16 TranslateInfoBarDelegate::GetMessageInfoBarText() {
191 if (infobar_type_ == TRANSLATING) { 197 if (infobar_type_ == TRANSLATING) {
192 return l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_TRANSLATING_TO, 198 return l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_TRANSLATING_TO,
193 language_name_at(target_language_index_)); 199 language_name_at(target_language_index_));
194 } 200 }
195 201
196 DCHECK_EQ(TRANSLATION_ERROR, infobar_type_); 202 DCHECK_EQ(TRANSLATION_ERROR, infobar_type_);
197 UMA_HISTOGRAM_ENUMERATION(kTranslateShowErrorInfobar, 203 UMA_HISTOGRAM_ENUMERATION(kShowErrorInfobar,
198 error_type_, 204 error_type_,
199 TranslateErrors::TRANSLATE_ERROR_MAX); 205 TranslateErrors::TRANSLATE_ERROR_MAX);
200 switch (error_type_) { 206 switch (error_type_) {
201 case TranslateErrors::NETWORK: 207 case TranslateErrors::NETWORK:
202 return l10n_util::GetStringUTF16( 208 return l10n_util::GetStringUTF16(
203 IDS_TRANSLATE_INFOBAR_ERROR_CANT_CONNECT); 209 IDS_TRANSLATE_INFOBAR_ERROR_CANT_CONNECT);
204 case TranslateErrors::INITIALIZATION_ERROR: 210 case TranslateErrors::INITIALIZATION_ERROR:
205 case TranslateErrors::TRANSLATION_ERROR: 211 case TranslateErrors::TRANSLATION_ERROR:
206 return l10n_util::GetStringUTF16( 212 return l10n_util::GetStringUTF16(
207 IDS_TRANSLATE_INFOBAR_ERROR_CANT_TRANSLATE); 213 IDS_TRANSLATE_INFOBAR_ERROR_CANT_TRANSLATE);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 389
384 return InfoBarDelegate::ShouldExpireInternal(details); 390 return InfoBarDelegate::ShouldExpireInternal(details);
385 } 391 }
386 392
387 void TranslateInfoBarDelegate::InfoBarDismissed() { 393 void TranslateInfoBarDelegate::InfoBarDismissed() {
388 if (infobar_type_ != BEFORE_TRANSLATE) 394 if (infobar_type_ != BEFORE_TRANSLATE)
389 return; 395 return;
390 396
391 // The user closed the infobar without clicking the translate button. 397 // The user closed the infobar without clicking the translate button.
392 TranslationDeclined(); 398 TranslationDeclined();
393 UMA_HISTOGRAM_COUNTS("Translate.DeclineTranslateCloseInfobar", 1); 399 UMA_HISTOGRAM_COUNTS(kCloseInfobar, 1);
394 } 400 }
395 401
396 int TranslateInfoBarDelegate::GetIconID() const { 402 int TranslateInfoBarDelegate::GetIconID() const {
397 return IDR_INFOBAR_TRANSLATE; 403 return IDR_INFOBAR_TRANSLATE;
398 } 404 }
399 405
400 InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() const { 406 InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() const {
401 return PAGE_ACTION_TYPE; 407 return PAGE_ACTION_TYPE;
402 } 408 }
403 409
404 TranslateInfoBarDelegate* 410 TranslateInfoBarDelegate*
405 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { 411 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() {
406 return this; 412 return this;
407 } 413 }
408 414
409 std::string TranslateInfoBarDelegate::GetPageHost() { 415 std::string TranslateInfoBarDelegate::GetPageHost() {
410 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); 416 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry();
411 return entry ? entry->GetURL().HostNoBrackets() : std::string(); 417 return entry ? entry->GetURL().HostNoBrackets() : std::string();
412 } 418 }
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698