| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/extensions/extension_metrics_module.h" | 5 #include "chrome/browser/extensions/extension_metrics_module.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
| 10 #include "chrome/browser/ui/options/options_util.h" | 10 #include "chrome/browser/ui/options/options_util.h" |
| 11 #include "chrome/installer/util/google_update_settings.h" | 11 #include "chrome/installer/util/google_update_settings.h" |
| 12 #include "content/browser/user_metrics.h" | 12 #include "content/browser/user_metrics.h" |
| 13 | 13 |
| 14 using base::Histogram; | 14 using base::Histogram; |
| 15 using base::LinearHistogram; | 15 using base::LinearHistogram; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Build the full name of a metrics for the given extension. Each metric | 19 // Build the full name of a metrics for the given extension. |
| 20 // is made up of the unique name within the extension followed by the | 20 // For a non-component extension the metric name is made up of the unique name |
| 21 // extension's id. This keeps the metrics from one extension unique from | 21 // within the extension followed by the extension's id. This keeps the metrics |
| 22 // other extensions, as well as those metrics from chrome itself. | 22 // from one extension unique from other extensions, as well as those metrics |
| 23 // from chrome itself. |
| 24 // For a component extension the metric name is used as is. There are not so |
| 25 // many of them and it is easy enough to prevent name clashes. |
| 23 std::string BuildMetricName(const std::string& name, | 26 std::string BuildMetricName(const std::string& name, |
| 24 const Extension* extension) { | 27 const Extension* extension) { |
| 25 std::string full_name(name); | 28 std::string full_name(name); |
| 26 full_name += extension->id(); | 29 if (extension->location() != Extension::COMPONENT) |
| 30 full_name += extension->id(); |
| 27 return full_name; | 31 return full_name; |
| 28 } | 32 } |
| 29 | 33 |
| 30 } // anonymous namespace | 34 } // anonymous namespace |
| 31 | 35 |
| 32 // These extension function classes are enabled only if the | |
| 33 // enable-metrics-extension-api command line switch is used. Refer to | |
| 34 // extension_function_dispatcher.cc to see how they are enabled. | |
| 35 | |
| 36 bool MetricsSetEnabledFunction::RunImpl() { | 36 bool MetricsSetEnabledFunction::RunImpl() { |
| 37 bool enabled = false; | 37 bool enabled = false; |
| 38 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &enabled)); | 38 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &enabled)); |
| 39 | 39 |
| 40 // Using OptionsUtil is better because it actually ensures we reset all the | 40 // Using OptionsUtil is better because it actually ensures we reset all the |
| 41 // necessary threads. This is the main way for starting / stopping UMA and | 41 // necessary threads. This is the main way for starting / stopping UMA and |
| 42 // crash reporting. | 42 // crash reporting. |
| 43 // This method will return the resulting enabled, which we send to JS. | 43 // This method will return the resulting enabled, which we send to JS. |
| 44 bool result = OptionsUtil::ResolveMetricsReportingEnabled(enabled); | 44 bool result = OptionsUtil::ResolveMetricsReportingEnabled(enabled); |
| 45 result_.reset(Value::CreateBooleanValue(result)); | 45 result_.reset(Value::CreateBooleanValue(result)); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 return RecordValue(name, Histogram::HISTOGRAM, 1, kThreeMinMs, 50, sample); | 162 return RecordValue(name, Histogram::HISTOGRAM, 1, kThreeMinMs, 50, sample); |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool MetricsRecordLongTimeFunction::RunImpl() { | 165 bool MetricsRecordLongTimeFunction::RunImpl() { |
| 166 std::string name; | 166 std::string name; |
| 167 int sample; | 167 int sample; |
| 168 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample)); | 168 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample)); |
| 169 static const int kOneHourMs = 60 * 60 * 1000; | 169 static const int kOneHourMs = 60 * 60 * 1000; |
| 170 return RecordValue(name, Histogram::HISTOGRAM, 1, kOneHourMs, 50, sample); | 170 return RecordValue(name, Histogram::HISTOGRAM, 1, kOneHourMs, 50, sample); |
| 171 } | 171 } |
| OLD | NEW |