Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/browser/extensions/api/metrics_private/metrics_private_api.cc

Issue 2331343012: Create MetricsPrivateDelegate for metricsPrivate behavior (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/lazy_instance.h"
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
13 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
14 #include "base/metrics/sparse_histogram.h" 15 #include "base/metrics/sparse_histogram.h"
15 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 16 #include "chrome/browser/extensions/api/chrome_extensions_api_client.h"
16 #include "chrome/common/extensions/api/metrics_private.h" 17 #include "chrome/common/extensions/api/metrics_private.h"
17 #include "components/variations/variations_associated_data.h" 18 #include "components/variations/variations_associated_data.h"
19 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/user_metrics.h" 20 #include "content/public/browser/user_metrics.h"
21 #include "extensions/browser/api/metrics_private/metrics_private_delegate.h"
19 #include "extensions/common/extension.h" 22 #include "extensions/common/extension.h"
20 23
21 namespace extensions { 24 namespace extensions {
22 25
23 namespace GetIsCrashReportingEnabled =
24 api::metrics_private::GetIsCrashReportingEnabled;
25 namespace GetVariationParams = api::metrics_private::GetVariationParams; 26 namespace GetVariationParams = api::metrics_private::GetVariationParams;
26 namespace GetFieldTrial = api::metrics_private::GetFieldTrial;
27 namespace RecordUserAction = api::metrics_private::RecordUserAction; 27 namespace RecordUserAction = api::metrics_private::RecordUserAction;
28 namespace RecordValue = api::metrics_private::RecordValue; 28 namespace RecordValue = api::metrics_private::RecordValue;
29 namespace RecordSparseValue = api::metrics_private::RecordSparseValue; 29 namespace RecordSparseValue = api::metrics_private::RecordSparseValue;
30 namespace RecordPercentage = api::metrics_private::RecordPercentage; 30 namespace RecordPercentage = api::metrics_private::RecordPercentage;
31 namespace RecordCount = api::metrics_private::RecordCount; 31 namespace RecordCount = api::metrics_private::RecordCount;
32 namespace RecordSmallCount = api::metrics_private::RecordSmallCount; 32 namespace RecordSmallCount = api::metrics_private::RecordSmallCount;
33 namespace RecordMediumCount = api::metrics_private::RecordMediumCount; 33 namespace RecordMediumCount = api::metrics_private::RecordMediumCount;
34 namespace RecordTime = api::metrics_private::RecordTime; 34 namespace RecordTime = api::metrics_private::RecordTime;
35 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; 35 namespace RecordMediumTime = api::metrics_private::RecordMediumTime;
36 namespace RecordLongTime = api::metrics_private::RecordLongTime; 36 namespace RecordLongTime = api::metrics_private::RecordLongTime;
37 37
38 namespace { 38 namespace {
39 39
40 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
41 // buckets; there is no real need for them 41 // buckets; there is no real need for them
42 // and would cause crazy memory usage 42 // and would cause crazy memory usage
43 } // namespace 43 } // namespace
44 44
45 ExtensionFunction::ResponseAction 45 ExtensionFunction::ResponseAction
46 MetricsPrivateGetIsCrashReportingEnabledFunction::Run() { 46 MetricsPrivateGetIsCrashReportingEnabledFunction::Run() {
47 MetricsPrivateAPI* api =
48 BrowserContextKeyedAPIFactory<MetricsPrivateAPI>::Get(browser_context());
49 DCHECK(api);
50
47 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>( 51 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>(
48 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()))); 52 api->delegate()->IsCrashReportingEnabled())));
49 } 53 }
50 54
51 ExtensionFunction::ResponseAction MetricsPrivateGetFieldTrialFunction::Run() { 55 ExtensionFunction::ResponseAction MetricsPrivateGetFieldTrialFunction::Run() {
52 std::string name; 56 std::string name;
53 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); 57 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name));
54 58
55 return RespondNow(OneArgument(base::MakeUnique<base::StringValue>( 59 return RespondNow(OneArgument(base::MakeUnique<base::StringValue>(
56 base::FieldTrialList::FindFullName(name)))); 60 base::FieldTrialList::FindFullName(name))));
57 } 61 }
58 62
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 ExtensionFunction::ResponseAction MetricsPrivateRecordLongTimeFunction::Run() { 209 ExtensionFunction::ResponseAction MetricsPrivateRecordLongTimeFunction::Run() {
206 std::unique_ptr<RecordLongTime::Params> params( 210 std::unique_ptr<RecordLongTime::Params> params(
207 RecordLongTime::Params::Create(*args_)); 211 RecordLongTime::Params::Create(*args_));
208 EXTENSION_FUNCTION_VALIDATE(params.get()); 212 EXTENSION_FUNCTION_VALIDATE(params.get());
209 static const int kOneHourMs = 60 * 60 * 1000; 213 static const int kOneHourMs = 60 * 60 * 1000;
210 RecordValue(params->metric_name, base::HISTOGRAM, 1, kOneHourMs, 50, 214 RecordValue(params->metric_name, base::HISTOGRAM, 1, kOneHourMs, 50,
211 params->value); 215 params->value);
212 return RespondNow(NoArguments()); 216 return RespondNow(NoArguments());
213 } 217 }
214 218
219 MetricsPrivateAPI::MetricsPrivateAPI(content::BrowserContext* context) {
220 delegate_ = ExtensionsAPIClient::Get()->CreateMetricsPrivateDelegate();
221 }
222
223 MetricsPrivateAPI::~MetricsPrivateAPI() {}
224
225 static base::LazyInstance<BrowserContextKeyedAPIFactory<MetricsPrivateAPI>>
226 g_factory = LAZY_INSTANCE_INITIALIZER;
227
228 // static
229 BrowserContextKeyedAPIFactory<MetricsPrivateAPI>*
230 MetricsPrivateAPI::GetFactoryInstance() {
231 return g_factory.Pointer();
232 }
233
215 } // namespace extensions 234 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698