OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/browser/api/metrics_private/metrics_private_api.h" | 5 #include "chrome/browser/extensions/api/metrics_private/metrics_private_api.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 16 #include "chrome/common/extensions/api/metrics_private.h" |
15 #include "components/variations/variations_associated_data.h" | 17 #include "components/variations/variations_associated_data.h" |
16 #include "content/public/browser/user_metrics.h" | 18 #include "content/public/browser/user_metrics.h" |
17 #include "extensions/browser/api/extensions_api_client.h" | 19 #include "extensions/common/extension.h" |
18 #include "extensions/browser/api/metrics_private/metrics_private_delegate.h" | |
19 #include "extensions/common/api/metrics_private.h" | |
20 | 20 |
21 namespace extensions { | 21 namespace extensions { |
22 | 22 |
| 23 namespace GetIsCrashReportingEnabled = |
| 24 api::metrics_private::GetIsCrashReportingEnabled; |
23 namespace GetVariationParams = api::metrics_private::GetVariationParams; | 25 namespace GetVariationParams = api::metrics_private::GetVariationParams; |
| 26 namespace GetFieldTrial = api::metrics_private::GetFieldTrial; |
24 namespace RecordUserAction = api::metrics_private::RecordUserAction; | 27 namespace RecordUserAction = api::metrics_private::RecordUserAction; |
25 namespace RecordValue = api::metrics_private::RecordValue; | 28 namespace RecordValue = api::metrics_private::RecordValue; |
26 namespace RecordSparseValue = api::metrics_private::RecordSparseValue; | 29 namespace RecordSparseValue = api::metrics_private::RecordSparseValue; |
27 namespace RecordPercentage = api::metrics_private::RecordPercentage; | 30 namespace RecordPercentage = api::metrics_private::RecordPercentage; |
28 namespace RecordCount = api::metrics_private::RecordCount; | 31 namespace RecordCount = api::metrics_private::RecordCount; |
29 namespace RecordSmallCount = api::metrics_private::RecordSmallCount; | 32 namespace RecordSmallCount = api::metrics_private::RecordSmallCount; |
30 namespace RecordMediumCount = api::metrics_private::RecordMediumCount; | 33 namespace RecordMediumCount = api::metrics_private::RecordMediumCount; |
31 namespace RecordTime = api::metrics_private::RecordTime; | 34 namespace RecordTime = api::metrics_private::RecordTime; |
32 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; | 35 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; |
33 namespace RecordLongTime = api::metrics_private::RecordLongTime; | 36 namespace RecordLongTime = api::metrics_private::RecordLongTime; |
34 | 37 |
35 namespace { | 38 namespace { |
36 | 39 |
37 const size_t kMaxBuckets = 10000; // We don't ever want more than these many | 40 const size_t kMaxBuckets = 10000; // We don't ever want more than these many |
38 // buckets; there is no real need for them | 41 // buckets; there is no real need for them |
39 // and would cause crazy memory usage | 42 // and would cause crazy memory usage |
40 } // namespace | 43 } // namespace |
41 | 44 |
42 ExtensionFunction::ResponseAction | 45 ExtensionFunction::ResponseAction |
43 MetricsPrivateGetIsCrashReportingEnabledFunction::Run() { | 46 MetricsPrivateGetIsCrashReportingEnabledFunction::Run() { |
44 MetricsPrivateDelegate* delegate = | 47 return RespondNow(OneArgument(base::MakeUnique<base::Value>( |
45 ExtensionsAPIClient::Get()->GetMetricsPrivateDelegate(); | 48 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()))); |
46 | |
47 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>( | |
48 delegate && delegate->IsCrashReportingEnabled()))); | |
49 } | 49 } |
50 | 50 |
51 ExtensionFunction::ResponseAction MetricsPrivateGetFieldTrialFunction::Run() { | 51 ExtensionFunction::ResponseAction MetricsPrivateGetFieldTrialFunction::Run() { |
52 std::string name; | 52 std::string name; |
53 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); | 53 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); |
54 | 54 |
55 return RespondNow(OneArgument(base::MakeUnique<base::StringValue>( | 55 return RespondNow(OneArgument(base::MakeUnique<base::StringValue>( |
56 base::FieldTrialList::FindFullName(name)))); | 56 base::FieldTrialList::FindFullName(name)))); |
57 } | 57 } |
58 | 58 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 ExtensionFunction::ResponseAction MetricsPrivateRecordValueFunction::Run() { | 120 ExtensionFunction::ResponseAction MetricsPrivateRecordValueFunction::Run() { |
121 std::unique_ptr<RecordValue::Params> params( | 121 std::unique_ptr<RecordValue::Params> params( |
122 RecordValue::Params::Create(*args_)); | 122 RecordValue::Params::Create(*args_)); |
123 EXTENSION_FUNCTION_VALIDATE(params.get()); | 123 EXTENSION_FUNCTION_VALIDATE(params.get()); |
124 | 124 |
125 // Get the histogram parameters from the metric type object. | 125 // Get the histogram parameters from the metric type object. |
126 std::string type = api::metrics_private::ToString(params->metric.type); | 126 std::string type = api::metrics_private::ToString(params->metric.type); |
127 | 127 |
128 base::HistogramType histogram_type( | 128 base::HistogramType histogram_type(type == "histogram-linear" ? |
129 type == "histogram-linear" ? base::LINEAR_HISTOGRAM : base::HISTOGRAM); | 129 base::LINEAR_HISTOGRAM : base::HISTOGRAM); |
130 RecordValue(params->metric.metric_name, histogram_type, params->metric.min, | 130 RecordValue(params->metric.metric_name, histogram_type, params->metric.min, |
131 params->metric.max, params->metric.buckets, params->value); | 131 params->metric.max, params->metric.buckets, params->value); |
132 return RespondNow(NoArguments()); | 132 return RespondNow(NoArguments()); |
133 } | 133 } |
134 | 134 |
135 ExtensionFunction::ResponseAction | 135 ExtensionFunction::ResponseAction |
136 MetricsPrivateRecordSparseValueFunction::Run() { | 136 MetricsPrivateRecordSparseValueFunction::Run() { |
137 std::unique_ptr<RecordSparseValue::Params> params( | 137 std::unique_ptr<RecordSparseValue::Params> params( |
138 RecordSparseValue::Params::Create(*args_)); | 138 RecordSparseValue::Params::Create(*args_)); |
139 EXTENSION_FUNCTION_VALIDATE(params.get()); | 139 EXTENSION_FUNCTION_VALIDATE(params.get()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 ExtensionFunction::ResponseAction MetricsPrivateRecordLongTimeFunction::Run() { | 205 ExtensionFunction::ResponseAction MetricsPrivateRecordLongTimeFunction::Run() { |
206 std::unique_ptr<RecordLongTime::Params> params( | 206 std::unique_ptr<RecordLongTime::Params> params( |
207 RecordLongTime::Params::Create(*args_)); | 207 RecordLongTime::Params::Create(*args_)); |
208 EXTENSION_FUNCTION_VALIDATE(params.get()); | 208 EXTENSION_FUNCTION_VALIDATE(params.get()); |
209 static const int kOneHourMs = 60 * 60 * 1000; | 209 static const int kOneHourMs = 60 * 60 * 1000; |
210 RecordValue(params->metric_name, base::HISTOGRAM, 1, kOneHourMs, 50, | 210 RecordValue(params->metric_name, base::HISTOGRAM, 1, kOneHourMs, 50, |
211 params->value); | 211 params->value); |
212 return RespondNow(NoArguments()); | 212 return RespondNow(NoArguments()); |
213 } | 213 } |
214 | 214 |
215 } // namespace extensions | 215 } // namespace extensions |
OLD | NEW |