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/histogram.h" | 10 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
12 #include "chrome/common/extensions/api/metrics_private.h" | 13 #include "chrome/common/extensions/api/metrics_private.h" |
13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
15 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
16 | 17 |
17 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
19 #endif // OS_CHROMEOS | 20 #endif // OS_CHROMEOS |
20 | 21 |
21 namespace extensions { | 22 namespace extensions { |
22 | 23 |
23 namespace GetIsCrashReportingEnabled = | 24 namespace GetIsCrashReportingEnabled = |
24 api::metrics_private::GetIsCrashReportingEnabled; | 25 api::metrics_private::GetIsCrashReportingEnabled; |
| 26 namespace GetFieldTrial = api::metrics_private::GetFieldTrial; |
25 namespace RecordUserAction = api::metrics_private::RecordUserAction; | 27 namespace RecordUserAction = api::metrics_private::RecordUserAction; |
26 namespace RecordValue = api::metrics_private::RecordValue; | 28 namespace RecordValue = api::metrics_private::RecordValue; |
27 namespace RecordPercentage = api::metrics_private::RecordPercentage; | 29 namespace RecordPercentage = api::metrics_private::RecordPercentage; |
28 namespace RecordCount = api::metrics_private::RecordCount; | 30 namespace RecordCount = api::metrics_private::RecordCount; |
29 namespace RecordSmallCount = api::metrics_private::RecordSmallCount; | 31 namespace RecordSmallCount = api::metrics_private::RecordSmallCount; |
30 namespace RecordMediumCount = api::metrics_private::RecordMediumCount; | 32 namespace RecordMediumCount = api::metrics_private::RecordMediumCount; |
31 namespace RecordTime = api::metrics_private::RecordTime; | 33 namespace RecordTime = api::metrics_private::RecordTime; |
32 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; | 34 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; |
33 namespace RecordLongTime = api::metrics_private::RecordLongTime; | 35 namespace RecordLongTime = api::metrics_private::RecordLongTime; |
34 | 36 |
(...skipping 24 matching lines...) Expand all Loading... |
59 #else | 61 #else |
60 return false; | 62 return false; |
61 #endif | 63 #endif |
62 } | 64 } |
63 | 65 |
64 bool MetricsPrivateGetIsCrashReportingEnabledFunction::RunImpl() { | 66 bool MetricsPrivateGetIsCrashReportingEnabledFunction::RunImpl() { |
65 SetResult(new base::FundamentalValue(IsCrashReportingEnabled())); | 67 SetResult(new base::FundamentalValue(IsCrashReportingEnabled())); |
66 return true; | 68 return true; |
67 } | 69 } |
68 | 70 |
| 71 bool MetricsPrivateGetFieldTrialFunction::RunImpl() { |
| 72 std::string name; |
| 73 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); |
| 74 |
| 75 SetResult(new base::StringValue(base::FieldTrialList::FindFullName(name))); |
| 76 return true; |
| 77 } |
| 78 |
69 bool MetricsPrivateRecordUserActionFunction::RunImpl() { | 79 bool MetricsPrivateRecordUserActionFunction::RunImpl() { |
70 scoped_ptr<RecordUserAction::Params> params( | 80 scoped_ptr<RecordUserAction::Params> params( |
71 RecordUserAction::Params::Create(*args_)); | 81 RecordUserAction::Params::Create(*args_)); |
72 EXTENSION_FUNCTION_VALIDATE(params.get()); | 82 EXTENSION_FUNCTION_VALIDATE(params.get()); |
73 | 83 |
74 content::RecordComputedAction(params->name); | 84 content::RecordComputedAction(params->name); |
75 return true; | 85 return true; |
76 } | 86 } |
77 | 87 |
78 bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name, | 88 bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 bool MetricsPrivateRecordLongTimeFunction::RunImpl() { | 191 bool MetricsPrivateRecordLongTimeFunction::RunImpl() { |
182 scoped_ptr<RecordLongTime::Params> params( | 192 scoped_ptr<RecordLongTime::Params> params( |
183 RecordLongTime::Params::Create(*args_)); | 193 RecordLongTime::Params::Create(*args_)); |
184 EXTENSION_FUNCTION_VALIDATE(params.get()); | 194 EXTENSION_FUNCTION_VALIDATE(params.get()); |
185 static const int kOneHourMs = 60 * 60 * 1000; | 195 static const int kOneHourMs = 60 * 60 * 1000; |
186 return RecordValue(params->metric_name, base::HISTOGRAM, | 196 return RecordValue(params->metric_name, base::HISTOGRAM, |
187 1, kOneHourMs, 50, params->value); | 197 1, kOneHourMs, 50, params->value); |
188 } | 198 } |
189 | 199 |
190 } // namespace extensions | 200 } // namespace extensions |
OLD | NEW |