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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/common/extensions/api/metrics_private.h" | 13 #include "chrome/common/extensions/api/metrics_private.h" |
14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "chrome/common/metrics/variations/variations_associated_data.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 #include "content/public/browser/user_metrics.h" | 17 #include "content/public/browser/user_metrics.h" |
17 | 18 |
18 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
19 #include "chrome/browser/chromeos/settings/cros_settings.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings.h" |
20 #endif // OS_CHROMEOS | 21 #endif // OS_CHROMEOS |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 | 24 |
24 namespace GetIsCrashReportingEnabled = | 25 namespace GetIsCrashReportingEnabled = |
25 api::metrics_private::GetIsCrashReportingEnabled; | 26 api::metrics_private::GetIsCrashReportingEnabled; |
| 27 namespace GetVariationParams = api::metrics_private::GetVariationParams; |
26 namespace GetFieldTrial = api::metrics_private::GetFieldTrial; | 28 namespace GetFieldTrial = api::metrics_private::GetFieldTrial; |
27 namespace RecordUserAction = api::metrics_private::RecordUserAction; | 29 namespace RecordUserAction = api::metrics_private::RecordUserAction; |
28 namespace RecordValue = api::metrics_private::RecordValue; | 30 namespace RecordValue = api::metrics_private::RecordValue; |
29 namespace RecordPercentage = api::metrics_private::RecordPercentage; | 31 namespace RecordPercentage = api::metrics_private::RecordPercentage; |
30 namespace RecordCount = api::metrics_private::RecordCount; | 32 namespace RecordCount = api::metrics_private::RecordCount; |
31 namespace RecordSmallCount = api::metrics_private::RecordSmallCount; | 33 namespace RecordSmallCount = api::metrics_private::RecordSmallCount; |
32 namespace RecordMediumCount = api::metrics_private::RecordMediumCount; | 34 namespace RecordMediumCount = api::metrics_private::RecordMediumCount; |
33 namespace RecordTime = api::metrics_private::RecordTime; | 35 namespace RecordTime = api::metrics_private::RecordTime; |
34 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; | 36 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; |
35 namespace RecordLongTime = api::metrics_private::RecordLongTime; | 37 namespace RecordLongTime = api::metrics_private::RecordLongTime; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 71 } |
70 | 72 |
71 bool MetricsPrivateGetFieldTrialFunction::RunImpl() { | 73 bool MetricsPrivateGetFieldTrialFunction::RunImpl() { |
72 std::string name; | 74 std::string name; |
73 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); | 75 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); |
74 | 76 |
75 SetResult(new base::StringValue(base::FieldTrialList::FindFullName(name))); | 77 SetResult(new base::StringValue(base::FieldTrialList::FindFullName(name))); |
76 return true; | 78 return true; |
77 } | 79 } |
78 | 80 |
| 81 bool MetricsPrivateGetVariationParamsFunction::RunImpl() { |
| 82 scoped_ptr<GetVariationParams::Params> params( |
| 83 GetVariationParams::Params::Create(*args_)); |
| 84 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 85 |
| 86 GetVariationParams::Results::Params result; |
| 87 if (!chrome_variations::GetVariationParams( |
| 88 params->name, &result.additional_properties)) { |
| 89 SetError("Variation parameters are unavailable."); |
| 90 return false; |
| 91 } |
| 92 |
| 93 SetResult(result.ToValue().release()); |
| 94 return true; |
| 95 } |
| 96 |
79 bool MetricsPrivateRecordUserActionFunction::RunImpl() { | 97 bool MetricsPrivateRecordUserActionFunction::RunImpl() { |
80 scoped_ptr<RecordUserAction::Params> params( | 98 scoped_ptr<RecordUserAction::Params> params( |
81 RecordUserAction::Params::Create(*args_)); | 99 RecordUserAction::Params::Create(*args_)); |
82 EXTENSION_FUNCTION_VALIDATE(params.get()); | 100 EXTENSION_FUNCTION_VALIDATE(params.get()); |
83 | 101 |
84 content::RecordComputedAction(params->name); | 102 content::RecordComputedAction(params->name); |
85 return true; | 103 return true; |
86 } | 104 } |
87 | 105 |
88 bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name, | 106 bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 bool MetricsPrivateRecordLongTimeFunction::RunImpl() { | 209 bool MetricsPrivateRecordLongTimeFunction::RunImpl() { |
192 scoped_ptr<RecordLongTime::Params> params( | 210 scoped_ptr<RecordLongTime::Params> params( |
193 RecordLongTime::Params::Create(*args_)); | 211 RecordLongTime::Params::Create(*args_)); |
194 EXTENSION_FUNCTION_VALIDATE(params.get()); | 212 EXTENSION_FUNCTION_VALIDATE(params.get()); |
195 static const int kOneHourMs = 60 * 60 * 1000; | 213 static const int kOneHourMs = 60 * 60 * 1000; |
196 return RecordValue(params->metric_name, base::HISTOGRAM, | 214 return RecordValue(params->metric_name, base::HISTOGRAM, |
197 1, kOneHourMs, 50, params->value); | 215 1, kOneHourMs, 50, params->value); |
198 } | 216 } |
199 | 217 |
200 } // namespace extensions | 218 } // namespace extensions |
OLD | NEW |