Home | History | Annotate | Download | only in appcache
      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.
      4 
      5 #include "content/browser/appcache/appcache_histograms.h"
      6 
      7 #include "base/metrics/histogram.h"
      8 
      9 namespace content {
     10 
     11 static std::string OriginToCustomHistogramSuffix(const GURL& origin_url) {
     12   if (origin_url.host() == "docs.google.com")
     13     return ".Docs";
     14   return std::string();
     15 }
     16 
     17 void AppCacheHistograms::CountInitResult(InitResultType init_result) {
     18   UMA_HISTOGRAM_ENUMERATION(
     19        "appcache.InitResult",
     20        init_result, NUM_INIT_RESULT_TYPES);
     21 }
     22 
     23 void AppCacheHistograms::CountReinitAttempt(bool repeated_attempt) {
     24   UMA_HISTOGRAM_BOOLEAN("appcache.ReinitAttempt", repeated_attempt);
     25 }
     26 
     27 void AppCacheHistograms::CountCorruptionDetected() {
     28   UMA_HISTOGRAM_BOOLEAN("appcache.CorruptionDetected", true);
     29 }
     30 
     31 void AppCacheHistograms::CountUpdateJobResult(
     32     AppCacheUpdateJob::ResultType result,
     33     const GURL& origin_url) {
     34   UMA_HISTOGRAM_ENUMERATION(
     35        "appcache.UpdateJobResult",
     36        result, AppCacheUpdateJob::NUM_UPDATE_JOB_RESULT_TYPES);
     37 
     38   const std::string suffix = OriginToCustomHistogramSuffix(origin_url);
     39   if (!suffix.empty()) {
     40     base::LinearHistogram::FactoryGet(
     41         "appcache.UpdateJobResult" + suffix,
     42         1,
     43         AppCacheUpdateJob::NUM_UPDATE_JOB_RESULT_TYPES,
     44         AppCacheUpdateJob::NUM_UPDATE_JOB_RESULT_TYPES + 1,
     45         base::HistogramBase::kUmaTargetedHistogramFlag)->Add(result);
     46   }
     47 }
     48 
     49 void AppCacheHistograms::CountCheckResponseResult(
     50     CheckResponseResultType result) {
     51   UMA_HISTOGRAM_ENUMERATION(
     52        "appcache.CheckResponseResult",
     53        result, NUM_CHECK_RESPONSE_RESULT_TYPES);
     54 }
     55 
     56 void AppCacheHistograms::CountResponseRetrieval(
     57     bool success, bool is_main_resource, const GURL& origin_url) {
     58   std::string label;
     59   if (is_main_resource) {
     60     label = "appcache.MainResourceResponseRetrieval";
     61     UMA_HISTOGRAM_BOOLEAN(label, success);
     62   } else {
     63     label = "appcache.SubResourceResponseRetrieval";
     64     UMA_HISTOGRAM_BOOLEAN(label, success);
     65   }
     66   const std::string suffix = OriginToCustomHistogramSuffix(origin_url);
     67   if (!suffix.empty()) {
     68     base::BooleanHistogram::FactoryGet(
     69         label + suffix,
     70         base::HistogramBase::kUmaTargetedHistogramFlag)->Add(success);
     71   }
     72 }
     73 
     74 void AppCacheHistograms::LogUpdateFailureStats(
     75       const GURL& origin_url,
     76       int percent_complete,
     77       bool was_stalled,
     78       bool was_off_origin_resource_failure) {
     79   const std::string suffix = OriginToCustomHistogramSuffix(origin_url);
     80 
     81   std::string label = "appcache.UpdateProgressAtPointOfFaliure";
     82   UMA_HISTOGRAM_PERCENTAGE(label, percent_complete);
     83   if (!suffix.empty()) {
     84     base::LinearHistogram::FactoryGet(
     85         label + suffix,
     86         1, 101, 102,
     87         base::HistogramBase::kUmaTargetedHistogramFlag)->Add(percent_complete);
     88   }
     89 
     90   label = "appcache.UpdateWasStalledAtPointOfFailure";
     91   UMA_HISTOGRAM_BOOLEAN(label, was_stalled);
     92   if (!suffix.empty()) {
     93     base::BooleanHistogram::FactoryGet(
     94         label + suffix,
     95         base::HistogramBase::kUmaTargetedHistogramFlag)->Add(was_stalled);
     96   }
     97 
     98   label = "appcache.UpdateWasOffOriginAtPointOfFailure";
     99   UMA_HISTOGRAM_BOOLEAN(label, was_off_origin_resource_failure);
    100   if (!suffix.empty()) {
    101     base::BooleanHistogram::FactoryGet(
    102         label + suffix,
    103         base::HistogramBase::kUmaTargetedHistogramFlag)->Add(
    104             was_off_origin_resource_failure);
    105   }
    106 }
    107 
    108 void AppCacheHistograms::AddTaskQueueTimeSample(
    109     const base::TimeDelta& duration) {
    110   UMA_HISTOGRAM_TIMES("appcache.TaskQueueTime", duration);
    111 }
    112 
    113 void AppCacheHistograms::AddTaskRunTimeSample(
    114     const base::TimeDelta& duration) {
    115   UMA_HISTOGRAM_TIMES("appcache.TaskRunTime", duration);
    116 }
    117 
    118 void AppCacheHistograms::AddCompletionQueueTimeSample(
    119     const base::TimeDelta& duration) {
    120   UMA_HISTOGRAM_TIMES("appcache.CompletionQueueTime", duration);
    121 }
    122 
    123 void AppCacheHistograms::AddCompletionRunTimeSample(
    124     const base::TimeDelta& duration) {
    125   UMA_HISTOGRAM_TIMES("appcache.CompletionRunTime", duration);
    126 }
    127 
    128 void AppCacheHistograms::AddNetworkJobStartDelaySample(
    129     const base::TimeDelta& duration) {
    130   UMA_HISTOGRAM_TIMES("appcache.JobStartDelay.Network", duration);
    131 }
    132 
    133 void AppCacheHistograms::AddErrorJobStartDelaySample(
    134     const base::TimeDelta& duration) {
    135   UMA_HISTOGRAM_TIMES("appcache.JobStartDelay.Error", duration);
    136 }
    137 
    138 void AppCacheHistograms::AddAppCacheJobStartDelaySample(
    139     const base::TimeDelta& duration) {
    140   UMA_HISTOGRAM_TIMES("appcache.JobStartDelay.AppCache", duration);
    141 }
    142 
    143 void AppCacheHistograms::AddMissingManifestEntrySample() {
    144   UMA_HISTOGRAM_BOOLEAN("appcache.MissingManifestEntry", true);
    145 }
    146 
    147 void AppCacheHistograms::AddMissingManifestDetectedAtCallsite(
    148     MissingManifestCallsiteType callsite) {
    149   UMA_HISTOGRAM_ENUMERATION(
    150        "appcache.MissingManifestDetectedAtCallsite",
    151        callsite, NUM_MISSING_MANIFEST_CALLSITE_TYPES);
    152 }
    153 
    154 }  // namespace content
    155