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
3 // found in the LICENSE file.
5 #include "content/browser/appcache/appcache_histograms.h"
7 #include "base/metrics/histogram.h"
8 #include "content/public/common/origin_util.h"
12 static std::string
OriginToCustomHistogramSuffix(const GURL
& origin_url
) {
13 if (origin_url
.host() == "docs.google.com")
18 void AppCacheHistograms::CountInitResult(InitResultType init_result
) {
19 UMA_HISTOGRAM_ENUMERATION(
20 "appcache.InitResult",
21 init_result
, NUM_INIT_RESULT_TYPES
);
24 void AppCacheHistograms::CountReinitAttempt(bool repeated_attempt
) {
25 UMA_HISTOGRAM_BOOLEAN("appcache.ReinitAttempt", repeated_attempt
);
28 void AppCacheHistograms::CountCorruptionDetected() {
29 UMA_HISTOGRAM_BOOLEAN("appcache.CorruptionDetected", true);
32 void AppCacheHistograms::CountUpdateJobResult(
33 AppCacheUpdateJob::ResultType result
,
34 const GURL
& origin_url
) {
35 UMA_HISTOGRAM_ENUMERATION(
36 "appcache.UpdateJobResult",
37 result
, AppCacheUpdateJob::NUM_UPDATE_JOB_RESULT_TYPES
);
39 const std::string suffix
= OriginToCustomHistogramSuffix(origin_url
);
40 if (!suffix
.empty()) {
41 base::LinearHistogram::FactoryGet(
42 "appcache.UpdateJobResult" + suffix
,
44 AppCacheUpdateJob::NUM_UPDATE_JOB_RESULT_TYPES
,
45 AppCacheUpdateJob::NUM_UPDATE_JOB_RESULT_TYPES
+ 1,
46 base::HistogramBase::kUmaTargetedHistogramFlag
)->Add(result
);
50 void AppCacheHistograms::CountCheckResponseResult(
51 CheckResponseResultType result
) {
52 UMA_HISTOGRAM_ENUMERATION(
53 "appcache.CheckResponseResult",
54 result
, NUM_CHECK_RESPONSE_RESULT_TYPES
);
57 void AppCacheHistograms::CountResponseRetrieval(
58 bool success
, bool is_main_resource
, const GURL
& origin_url
) {
60 if (is_main_resource
) {
61 label
= "appcache.MainResourceResponseRetrieval";
62 UMA_HISTOGRAM_BOOLEAN(label
, success
);
64 // Also count HTTP vs HTTPS appcache usage.
65 UMA_HISTOGRAM_BOOLEAN("appcache.MainPageLoad", IsOriginSecure(origin_url
));
67 label
= "appcache.SubResourceResponseRetrieval";
68 UMA_HISTOGRAM_BOOLEAN(label
, success
);
70 const std::string suffix
= OriginToCustomHistogramSuffix(origin_url
);
71 if (!suffix
.empty()) {
72 base::BooleanHistogram::FactoryGet(
74 base::HistogramBase::kUmaTargetedHistogramFlag
)->Add(success
);
78 void AppCacheHistograms::LogUpdateFailureStats(
79 const GURL
& origin_url
,
82 bool was_off_origin_resource_failure
) {
83 const std::string suffix
= OriginToCustomHistogramSuffix(origin_url
);
85 std::string label
= "appcache.UpdateProgressAtPointOfFaliure";
86 UMA_HISTOGRAM_PERCENTAGE(label
, percent_complete
);
87 if (!suffix
.empty()) {
88 base::LinearHistogram::FactoryGet(
91 base::HistogramBase::kUmaTargetedHistogramFlag
)->Add(percent_complete
);
94 label
= "appcache.UpdateWasStalledAtPointOfFailure";
95 UMA_HISTOGRAM_BOOLEAN(label
, was_stalled
);
96 if (!suffix
.empty()) {
97 base::BooleanHistogram::FactoryGet(
99 base::HistogramBase::kUmaTargetedHistogramFlag
)->Add(was_stalled
);
102 label
= "appcache.UpdateWasOffOriginAtPointOfFailure";
103 UMA_HISTOGRAM_BOOLEAN(label
, was_off_origin_resource_failure
);
104 if (!suffix
.empty()) {
105 base::BooleanHistogram::FactoryGet(
107 base::HistogramBase::kUmaTargetedHistogramFlag
)->Add(
108 was_off_origin_resource_failure
);
112 void AppCacheHistograms::AddTaskQueueTimeSample(
113 const base::TimeDelta
& duration
) {
114 UMA_HISTOGRAM_TIMES("appcache.TaskQueueTime", duration
);
117 void AppCacheHistograms::AddTaskRunTimeSample(
118 const base::TimeDelta
& duration
) {
119 UMA_HISTOGRAM_TIMES("appcache.TaskRunTime", duration
);
122 void AppCacheHistograms::AddCompletionQueueTimeSample(
123 const base::TimeDelta
& duration
) {
124 UMA_HISTOGRAM_TIMES("appcache.CompletionQueueTime", duration
);
127 void AppCacheHistograms::AddCompletionRunTimeSample(
128 const base::TimeDelta
& duration
) {
129 UMA_HISTOGRAM_TIMES("appcache.CompletionRunTime", duration
);
132 void AppCacheHistograms::AddNetworkJobStartDelaySample(
133 const base::TimeDelta
& duration
) {
134 UMA_HISTOGRAM_TIMES("appcache.JobStartDelay.Network", duration
);
137 void AppCacheHistograms::AddErrorJobStartDelaySample(
138 const base::TimeDelta
& duration
) {
139 UMA_HISTOGRAM_TIMES("appcache.JobStartDelay.Error", duration
);
142 void AppCacheHistograms::AddAppCacheJobStartDelaySample(
143 const base::TimeDelta
& duration
) {
144 UMA_HISTOGRAM_TIMES("appcache.JobStartDelay.AppCache", duration
);
147 void AppCacheHistograms::AddMissingManifestEntrySample() {
148 UMA_HISTOGRAM_BOOLEAN("appcache.MissingManifestEntry", true);
151 void AppCacheHistograms::AddMissingManifestDetectedAtCallsite(
152 MissingManifestCallsiteType callsite
) {
153 UMA_HISTOGRAM_ENUMERATION(
154 "appcache.MissingManifestDetectedAtCallsite",
155 callsite
, NUM_MISSING_MANIFEST_CALLSITE_TYPES
);
158 } // namespace content