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

Side by Side Diff: components/translate/common/translate_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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/common/translate/translate_common_metrics.h" 5 #include "components/translate/common/translate_metrics.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 9
10 namespace translate {
11
10 namespace { 12 namespace {
11 13
12 // Constant string values to indicate UMA names. All entries should have 14 // Constant string values to indicate UMA names. All entries should have
13 // a corresponding index in MetricsNameIndex and an entry in |kMetricsEntries|. 15 // a corresponding index in MetricsNameIndex and an entry in |kMetricsEntries|.
14 const char kRenderer4LanguageDetection[] = "Renderer4.LanguageDetection"; 16 const char kRenderer4LanguageDetection[] = "Renderer4.LanguageDetection";
15 const char kTranslateContentLanguage[] = "Translate.ContentLanguage"; 17 const char kTranslateContentLanguage[] = "Translate.ContentLanguage";
16 const char kTranslateHtmlLang[] = "Translate.HtmlLang"; 18 const char kTranslateHtmlLang[] = "Translate.HtmlLang";
17 const char kTranslateLanguageVerification[] = "Translate.LanguageVerification"; 19 const char kTranslateLanguageVerification[] = "Translate.LanguageVerification";
18 const char kTranslateTimeToBeReady[] = "Translate.TimeToBeReady"; 20 const char kTranslateTimeToBeReady[] = "Translate.TimeToBeReady";
19 const char kTranslateTimeToLoad[] = "Translate.TimeToLoad"; 21 const char kTranslateTimeToLoad[] = "Translate.TimeToLoad";
20 const char kTranslateTimeToTranslate[] = "Translate.TimeToTranslate"; 22 const char kTranslateTimeToTranslate[] = "Translate.TimeToTranslate";
21 const char kTranslateUserActionDuration[] = "Translate.UserActionDuration"; 23 const char kTranslateUserActionDuration[] = "Translate.UserActionDuration";
22 const char kTranslatePageScheme[] = "Translate.PageScheme"; 24 const char kTranslatePageScheme[] = "Translate.PageScheme";
23 const char kTranslateSimilarLanguageMatch[] = "Translate.SimilarLanguageMatch"; 25 const char kTranslateSimilarLanguageMatch[] = "Translate.SimilarLanguageMatch";
24 26
25 const char kSchemeHttp[] = "http"; 27 const char kSchemeHttp[] = "http";
26 const char kSchemeHttps[] = "https"; 28 const char kSchemeHttps[] = "https";
27 29
28 struct MetricsEntry { 30 struct MetricsEntry {
29 TranslateCommonMetrics::MetricsNameIndex index; 31 MetricsNameIndex index;
30 const char* const name; 32 const char* const name;
31 }; 33 };
32 34
33 // This entry table should be updated when new UMA items are added. 35 // This entry table should be updated when new UMA items are added.
34 const MetricsEntry kMetricsEntries[] = { 36 const MetricsEntry kMetricsEntries[] = {
35 { TranslateCommonMetrics::UMA_LANGUAGE_DETECTION, 37 {UMA_LANGUAGE_DETECTION, kRenderer4LanguageDetection},
36 kRenderer4LanguageDetection }, 38 {UMA_CONTENT_LANGUAGE, kTranslateContentLanguage},
37 { TranslateCommonMetrics::UMA_CONTENT_LANGUAGE, 39 {UMA_HTML_LANG, kTranslateHtmlLang},
38 kTranslateContentLanguage }, 40 {UMA_LANGUAGE_VERIFICATION, kTranslateLanguageVerification},
39 { TranslateCommonMetrics::UMA_HTML_LANG, 41 {UMA_TIME_TO_BE_READY, kTranslateTimeToBeReady},
40 kTranslateHtmlLang }, 42 {UMA_TIME_TO_LOAD, kTranslateTimeToLoad},
41 { TranslateCommonMetrics::UMA_LANGUAGE_VERIFICATION, 43 {UMA_TIME_TO_TRANSLATE, kTranslateTimeToTranslate},
42 kTranslateLanguageVerification }, 44 {UMA_USER_ACTION_DURATION, kTranslateUserActionDuration},
43 { TranslateCommonMetrics::UMA_TIME_TO_BE_READY, 45 {UMA_PAGE_SCHEME, kTranslatePageScheme},
44 kTranslateTimeToBeReady }, 46 {UMA_SIMILAR_LANGUAGE_MATCH, kTranslateSimilarLanguageMatch}, };
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 47
57 COMPILE_ASSERT(arraysize(kMetricsEntries) == TranslateCommonMetrics::UMA_MAX, 48 COMPILE_ASSERT(arraysize(kMetricsEntries) == UMA_MAX,
58 arraysize_of_kMetricsEntries_should_be_UMA_MAX); 49 arraysize_of_kMetricsEntries_should_be_UMA_MAX);
59 50
60 TranslateCommonMetrics::LanguageCheckType GetLanguageCheckMetric( 51 LanguageCheckType GetLanguageCheckMetric(const std::string& provided_code,
61 const std::string& provided_code, 52 const std::string& revised_code) {
62 const std::string& revised_code) {
63 if (provided_code.empty()) 53 if (provided_code.empty())
64 return TranslateCommonMetrics::LANGUAGE_NOT_PROVIDED; 54 return LANGUAGE_NOT_PROVIDED;
65 else if (provided_code == revised_code) 55 else if (provided_code == revised_code)
66 return TranslateCommonMetrics::LANGUAGE_VALID; 56 return LANGUAGE_VALID;
67 return TranslateCommonMetrics::LANGUAGE_INVALID; 57 return LANGUAGE_INVALID;
68 } 58 }
69 59
70 } // namespace 60 } // namespace
71 61
72 namespace TranslateCommonMetrics {
73
74 void ReportContentLanguage(const std::string& provided_code, 62 void ReportContentLanguage(const std::string& provided_code,
75 const std::string& revised_code) { 63 const std::string& revised_code) {
76 UMA_HISTOGRAM_ENUMERATION(kTranslateContentLanguage, 64 UMA_HISTOGRAM_ENUMERATION(kTranslateContentLanguage,
77 GetLanguageCheckMetric(provided_code, revised_code), 65 GetLanguageCheckMetric(provided_code, revised_code),
78 TranslateCommonMetrics::LANGUAGE_MAX); 66 LANGUAGE_MAX);
79 } 67 }
80 68
81 void ReportHtmlLang(const std::string& provided_code, 69 void ReportHtmlLang(const std::string& provided_code,
82 const std::string& revised_code) { 70 const std::string& revised_code) {
83 UMA_HISTOGRAM_ENUMERATION(kTranslateHtmlLang, 71 UMA_HISTOGRAM_ENUMERATION(kTranslateHtmlLang,
84 GetLanguageCheckMetric(provided_code, revised_code), 72 GetLanguageCheckMetric(provided_code, revised_code),
85 TranslateCommonMetrics::LANGUAGE_MAX); 73 LANGUAGE_MAX);
86 } 74 }
87 75
88 void ReportLanguageVerification(LanguageVerificationType type) { 76 void ReportLanguageVerification(LanguageVerificationType type) {
89 UMA_HISTOGRAM_ENUMERATION(kTranslateLanguageVerification, 77 UMA_HISTOGRAM_ENUMERATION(kTranslateLanguageVerification,
90 type, 78 type,
91 LANGUAGE_VERIFICATION_MAX); 79 LANGUAGE_VERIFICATION_MAX);
92 } 80 }
93 81
94 void ReportTimeToBeReady(double time_in_msec) { 82 void ReportTimeToBeReady(double time_in_msec) {
95 UMA_HISTOGRAM_MEDIUM_TIMES( 83 UMA_HISTOGRAM_MEDIUM_TIMES(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 120
133 const char* GetMetricsName(MetricsNameIndex index) { 121 const char* GetMetricsName(MetricsNameIndex index) {
134 for (size_t i = 0; i < arraysize(kMetricsEntries); ++i) { 122 for (size_t i = 0; i < arraysize(kMetricsEntries); ++i) {
135 if (kMetricsEntries[i].index == index) 123 if (kMetricsEntries[i].index == index)
136 return kMetricsEntries[i].name; 124 return kMetricsEntries[i].name;
137 } 125 }
138 NOTREACHED(); 126 NOTREACHED();
139 return NULL; 127 return NULL;
140 } 128 }
141 129
142 } // namespace TranslateCommonMetrics 130 } // namespace translate
OLDNEW
« no previous file with comments | « components/translate/common/translate_metrics.h ('k') | components/translate/common/translate_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698