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

Side by Side Diff: chrome/common/translate/translate_common_metrics.cc

Issue 25531002: Move language detection to a component (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Run translate unittests on iOS Created 7 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/translate/translate_common_metrics.h"
6
7 #include "base/basictypes.h"
8 #include "base/metrics/histogram.h"
9
10 namespace {
11
12 // Constant string values to indicate UMA names. All entries should have
13 // a corresponding index in MetricsNameIndex and an entry in |kMetricsEntries|.
14 const char kRenderer4LanguageDetection[] = "Renderer4.LanguageDetection";
15 const char kTranslateContentLanguage[] = "Translate.ContentLanguage";
16 const char kTranslateHtmlLang[] = "Translate.HtmlLang";
17 const char kTranslateLanguageVerification[] = "Translate.LanguageVerification";
18 const char kTranslateTimeToBeReady[] = "Translate.TimeToBeReady";
19 const char kTranslateTimeToLoad[] = "Translate.TimeToLoad";
20 const char kTranslateTimeToTranslate[] = "Translate.TimeToTranslate";
21 const char kTranslateUserActionDuration[] = "Translate.UserActionDuration";
22 const char kTranslatePageScheme[] = "Translate.PageScheme";
23 const char kTranslateSimilarLanguageMatch[] = "Translate.SimilarLanguageMatch";
24
25 const char kSchemeHttp[] = "http";
26 const char kSchemeHttps[] = "https";
27
28 struct MetricsEntry {
29 TranslateCommonMetrics::MetricsNameIndex index;
30 const char* const name;
31 };
32
33 // This entry table should be updated when new UMA items are added.
34 const MetricsEntry kMetricsEntries[] = {
35 { TranslateCommonMetrics::UMA_LANGUAGE_DETECTION,
36 kRenderer4LanguageDetection },
37 { TranslateCommonMetrics::UMA_CONTENT_LANGUAGE,
38 kTranslateContentLanguage },
39 { TranslateCommonMetrics::UMA_HTML_LANG,
40 kTranslateHtmlLang },
41 { TranslateCommonMetrics::UMA_LANGUAGE_VERIFICATION,
42 kTranslateLanguageVerification },
43 { TranslateCommonMetrics::UMA_TIME_TO_BE_READY,
44 kTranslateTimeToBeReady },
45 { TranslateCommonMetrics::UMA_TIME_TO_LOAD,
46 kTranslateTimeToLoad },
47 { TranslateCommonMetrics::UMA_TIME_TO_TRANSLATE,
48 kTranslateTimeToTranslate },
49 { TranslateCommonMetrics::UMA_USER_ACTION_DURATION,
50 kTranslateUserActionDuration },
51 { TranslateCommonMetrics::UMA_PAGE_SCHEME,
52 kTranslatePageScheme },
53 { TranslateCommonMetrics::UMA_SIMILAR_LANGUAGE_MATCH,
54 kTranslateSimilarLanguageMatch },
55 };
56
57 COMPILE_ASSERT(arraysize(kMetricsEntries) == TranslateCommonMetrics::UMA_MAX,
58 arraysize_of_kMetricsEntries_should_be_UMA_MAX);
59
60 TranslateCommonMetrics::LanguageCheckType GetLanguageCheckMetric(
61 const std::string& provided_code,
62 const std::string& revised_code) {
63 if (provided_code.empty())
64 return TranslateCommonMetrics::LANGUAGE_NOT_PROVIDED;
65 else if (provided_code == revised_code)
66 return TranslateCommonMetrics::LANGUAGE_VALID;
67 return TranslateCommonMetrics::LANGUAGE_INVALID;
68 }
69
70 } // namespace
71
72 namespace TranslateCommonMetrics {
73
74 void ReportContentLanguage(const std::string& provided_code,
75 const std::string& revised_code) {
76 UMA_HISTOGRAM_ENUMERATION(kTranslateContentLanguage,
77 GetLanguageCheckMetric(provided_code, revised_code),
78 TranslateCommonMetrics::LANGUAGE_MAX);
79 }
80
81 void ReportHtmlLang(const std::string& provided_code,
82 const std::string& revised_code) {
83 UMA_HISTOGRAM_ENUMERATION(kTranslateHtmlLang,
84 GetLanguageCheckMetric(provided_code, revised_code),
85 TranslateCommonMetrics::LANGUAGE_MAX);
86 }
87
88 void ReportLanguageVerification(LanguageVerificationType type) {
89 UMA_HISTOGRAM_ENUMERATION(kTranslateLanguageVerification,
90 type,
91 LANGUAGE_VERIFICATION_MAX);
92 }
93
94 void ReportTimeToBeReady(double time_in_msec) {
95 UMA_HISTOGRAM_MEDIUM_TIMES(
96 kTranslateTimeToBeReady,
97 base::TimeDelta::FromMicroseconds(time_in_msec * 1000.0));
98 }
99
100 void ReportTimeToLoad(double time_in_msec) {
101 UMA_HISTOGRAM_MEDIUM_TIMES(
102 kTranslateTimeToLoad,
103 base::TimeDelta::FromMicroseconds(time_in_msec * 1000.0));
104 }
105
106 void ReportTimeToTranslate(double time_in_msec) {
107 UMA_HISTOGRAM_MEDIUM_TIMES(
108 kTranslateTimeToTranslate,
109 base::TimeDelta::FromMicroseconds(time_in_msec * 1000.0));
110 }
111
112 void ReportUserActionDuration(base::TimeTicks begin, base::TimeTicks end) {
113 UMA_HISTOGRAM_LONG_TIMES(kTranslateUserActionDuration, end - begin);
114 }
115
116 void ReportPageScheme(const std::string& scheme) {
117 SchemeType type = SCHEME_OTHERS;
118 if (scheme == kSchemeHttp)
119 type = SCHEME_HTTP;
120 else if (scheme == kSchemeHttps)
121 type = SCHEME_HTTPS;
122 UMA_HISTOGRAM_ENUMERATION(kTranslatePageScheme, type, SCHEME_MAX);
123 }
124
125 void ReportLanguageDetectionTime(base::TimeTicks begin, base::TimeTicks end) {
126 UMA_HISTOGRAM_MEDIUM_TIMES(kRenderer4LanguageDetection, end - begin);
127 }
128
129 void ReportSimilarLanguageMatch(bool match) {
130 UMA_HISTOGRAM_BOOLEAN(kTranslateSimilarLanguageMatch, match);
131 }
132
133 const char* GetMetricsName(MetricsNameIndex index) {
134 for (size_t i = 0; i < arraysize(kMetricsEntries); ++i) {
135 if (kMetricsEntries[i].index == index)
136 return kMetricsEntries[i].name;
137 }
138 NOTREACHED();
139 return NULL;
140 }
141
142 } // namespace TranslateCommonMetrics
OLDNEW
« no previous file with comments | « chrome/common/translate/translate_common_metrics.h ('k') | chrome/common/translate/translate_common_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698