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 "chrome/browser/extensions/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/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
14 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 15 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
15 #include "chrome/common/extensions/api/metrics_private.h" | 16 #include "chrome/common/extensions/api/metrics_private.h" |
16 #include "components/variations/variations_associated_data.h" | 17 #include "components/variations/variations_associated_data.h" |
17 #include "content/public/browser/user_metrics.h" | 18 #include "content/public/browser/user_metrics.h" |
18 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
19 | 20 |
20 namespace extensions { | 21 namespace extensions { |
(...skipping 14 matching lines...) Expand all Loading... |
35 namespace RecordLongTime = api::metrics_private::RecordLongTime; | 36 namespace RecordLongTime = api::metrics_private::RecordLongTime; |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
39 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 |
40 // buckets; there is no real need for them | 41 // buckets; there is no real need for them |
41 // and would cause crazy memory usage | 42 // and would cause crazy memory usage |
42 } // namespace | 43 } // namespace |
43 | 44 |
44 bool MetricsPrivateGetIsCrashReportingEnabledFunction::RunSync() { | 45 bool MetricsPrivateGetIsCrashReportingEnabledFunction::RunSync() { |
45 SetResult(new base::FundamentalValue( | 46 SetResult(base::MakeUnique<base::FundamentalValue>( |
46 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled())); | 47 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled())); |
47 return true; | 48 return true; |
48 } | 49 } |
49 | 50 |
50 bool MetricsPrivateGetFieldTrialFunction::RunSync() { | 51 bool MetricsPrivateGetFieldTrialFunction::RunSync() { |
51 std::string name; | 52 std::string name; |
52 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); | 53 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); |
53 | 54 |
54 SetResult(new base::StringValue(base::FieldTrialList::FindFullName(name))); | 55 SetResult(base::MakeUnique<base::StringValue>( |
| 56 base::FieldTrialList::FindFullName(name))); |
55 return true; | 57 return true; |
56 } | 58 } |
57 | 59 |
58 bool MetricsPrivateGetVariationParamsFunction::RunSync() { | 60 bool MetricsPrivateGetVariationParamsFunction::RunSync() { |
59 std::unique_ptr<GetVariationParams::Params> params( | 61 std::unique_ptr<GetVariationParams::Params> params( |
60 GetVariationParams::Params::Create(*args_)); | 62 GetVariationParams::Params::Create(*args_)); |
61 EXTENSION_FUNCTION_VALIDATE(params.get()); | 63 EXTENSION_FUNCTION_VALIDATE(params.get()); |
62 | 64 |
63 GetVariationParams::Results::Params result; | 65 GetVariationParams::Results::Params result; |
64 if (variations::GetVariationParams(params->name, | 66 if (variations::GetVariationParams(params->name, |
65 &result.additional_properties)) { | 67 &result.additional_properties)) { |
66 SetResult(result.ToValue().release()); | 68 SetResult(result.ToValue()); |
67 } | 69 } |
68 return true; | 70 return true; |
69 } | 71 } |
70 | 72 |
71 bool MetricsPrivateRecordUserActionFunction::RunSync() { | 73 bool MetricsPrivateRecordUserActionFunction::RunSync() { |
72 std::unique_ptr<RecordUserAction::Params> params( | 74 std::unique_ptr<RecordUserAction::Params> params( |
73 RecordUserAction::Params::Create(*args_)); | 75 RecordUserAction::Params::Create(*args_)); |
74 EXTENSION_FUNCTION_VALIDATE(params.get()); | 76 EXTENSION_FUNCTION_VALIDATE(params.get()); |
75 | 77 |
76 content::RecordComputedAction(params->name); | 78 content::RecordComputedAction(params->name); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 bool MetricsPrivateRecordLongTimeFunction::RunSync() { | 193 bool MetricsPrivateRecordLongTimeFunction::RunSync() { |
192 std::unique_ptr<RecordLongTime::Params> params( | 194 std::unique_ptr<RecordLongTime::Params> params( |
193 RecordLongTime::Params::Create(*args_)); | 195 RecordLongTime::Params::Create(*args_)); |
194 EXTENSION_FUNCTION_VALIDATE(params.get()); | 196 EXTENSION_FUNCTION_VALIDATE(params.get()); |
195 static const int kOneHourMs = 60 * 60 * 1000; | 197 static const int kOneHourMs = 60 * 60 * 1000; |
196 return RecordValue(params->metric_name, base::HISTOGRAM, | 198 return RecordValue(params->metric_name, base::HISTOGRAM, |
197 1, kOneHourMs, 50, params->value); | 199 1, kOneHourMs, 50, params->value); |
198 } | 200 } |
199 | 201 |
200 } // namespace extensions | 202 } // namespace extensions |
OLD | NEW |