Don't preload rarely seen large images
[chromium-blink-merge.git] / components / translate / core / common / translate_metrics.cc
blob84dcf34eff760bf44d0f3f39f4539ad562a3b733
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
3 // found in the LICENSE file.
5 #include "components/translate/core/common/translate_metrics.h"
7 #include "base/basictypes.h"
8 #include "base/metrics/histogram_macros.h"
9 #include "url/url_constants.h"
11 namespace translate {
13 namespace {
15 // Constant string values to indicate UMA names. All entries should have
16 // a corresponding index in MetricsNameIndex and an entry in |kMetricsEntries|.
17 const char kRenderer4LanguageDetection[] = "Renderer4.LanguageDetection";
18 const char kTranslateContentLanguage[] = "Translate.ContentLanguage";
19 const char kTranslateHtmlLang[] = "Translate.HtmlLang";
20 const char kTranslateLanguageVerification[] = "Translate.LanguageVerification";
21 const char kTranslateTimeToBeReady[] = "Translate.TimeToBeReady";
22 const char kTranslateTimeToLoad[] = "Translate.TimeToLoad";
23 const char kTranslateTimeToTranslate[] = "Translate.TimeToTranslate";
24 const char kTranslateUserActionDuration[] = "Translate.UserActionDuration";
25 const char kTranslatePageScheme[] = "Translate.PageScheme";
26 const char kTranslateSimilarLanguageMatch[] = "Translate.SimilarLanguageMatch";
28 struct MetricsEntry {
29 MetricsNameIndex index;
30 const char* const name;
33 // This entry table should be updated when new UMA items are added.
34 const MetricsEntry kMetricsEntries[] = {
35 {UMA_LANGUAGE_DETECTION, kRenderer4LanguageDetection},
36 {UMA_CONTENT_LANGUAGE, kTranslateContentLanguage},
37 {UMA_HTML_LANG, kTranslateHtmlLang},
38 {UMA_LANGUAGE_VERIFICATION, kTranslateLanguageVerification},
39 {UMA_TIME_TO_BE_READY, kTranslateTimeToBeReady},
40 {UMA_TIME_TO_LOAD, kTranslateTimeToLoad},
41 {UMA_TIME_TO_TRANSLATE, kTranslateTimeToTranslate},
42 {UMA_USER_ACTION_DURATION, kTranslateUserActionDuration},
43 {UMA_PAGE_SCHEME, kTranslatePageScheme},
44 {UMA_SIMILAR_LANGUAGE_MATCH, kTranslateSimilarLanguageMatch}, };
46 static_assert(arraysize(kMetricsEntries) == UMA_MAX,
47 "kMetricsEntries should have UMA_MAX elements");
49 LanguageCheckType GetLanguageCheckMetric(const std::string& provided_code,
50 const std::string& revised_code) {
51 if (provided_code.empty())
52 return LANGUAGE_NOT_PROVIDED;
53 else if (provided_code == revised_code)
54 return LANGUAGE_VALID;
55 return LANGUAGE_INVALID;
58 } // namespace
60 void ReportContentLanguage(const std::string& provided_code,
61 const std::string& revised_code) {
62 UMA_HISTOGRAM_ENUMERATION(kTranslateContentLanguage,
63 GetLanguageCheckMetric(provided_code, revised_code),
64 LANGUAGE_MAX);
67 void ReportHtmlLang(const std::string& provided_code,
68 const std::string& revised_code) {
69 UMA_HISTOGRAM_ENUMERATION(kTranslateHtmlLang,
70 GetLanguageCheckMetric(provided_code, revised_code),
71 LANGUAGE_MAX);
74 void ReportLanguageVerification(LanguageVerificationType type) {
75 UMA_HISTOGRAM_ENUMERATION(kTranslateLanguageVerification,
76 type,
77 LANGUAGE_VERIFICATION_MAX);
80 void ReportTimeToBeReady(double time_in_msec) {
81 UMA_HISTOGRAM_MEDIUM_TIMES(
82 kTranslateTimeToBeReady,
83 base::TimeDelta::FromMicroseconds(
84 static_cast<int64>(time_in_msec * 1000.0)));
87 void ReportTimeToLoad(double time_in_msec) {
88 UMA_HISTOGRAM_MEDIUM_TIMES(
89 kTranslateTimeToLoad,
90 base::TimeDelta::FromMicroseconds(
91 static_cast<int64>(time_in_msec * 1000.0)));
94 void ReportTimeToTranslate(double time_in_msec) {
95 UMA_HISTOGRAM_MEDIUM_TIMES(
96 kTranslateTimeToTranslate,
97 base::TimeDelta::FromMicroseconds(
98 static_cast<int64>(time_in_msec * 1000.0)));
101 void ReportUserActionDuration(base::TimeTicks begin, base::TimeTicks end) {
102 UMA_HISTOGRAM_LONG_TIMES(kTranslateUserActionDuration, end - begin);
105 void ReportPageScheme(const std::string& scheme) {
106 SchemeType type = SCHEME_OTHERS;
107 if (scheme == url::kHttpScheme)
108 type = SCHEME_HTTP;
109 else if (scheme == url::kHttpsScheme)
110 type = SCHEME_HTTPS;
111 UMA_HISTOGRAM_ENUMERATION(kTranslatePageScheme, type, SCHEME_MAX);
114 void ReportLanguageDetectionTime(base::TimeTicks begin, base::TimeTicks end) {
115 UMA_HISTOGRAM_MEDIUM_TIMES(kRenderer4LanguageDetection, end - begin);
118 void ReportSimilarLanguageMatch(bool match) {
119 UMA_HISTOGRAM_BOOLEAN(kTranslateSimilarLanguageMatch, match);
122 const char* GetMetricsName(MetricsNameIndex index) {
123 for (size_t i = 0; i < arraysize(kMetricsEntries); ++i) {
124 if (kMetricsEntries[i].index == index)
125 return kMetricsEntries[i].name;
127 NOTREACHED();
128 return NULL;
131 } // namespace translate