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

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

Issue 2331343012: Create MetricsPrivateDelegate for metricsPrivate behavior (Closed)
Patch Set: nit & rebase Created 4 years, 2 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/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 "chrome/common/extensions/api/metrics_private.h"
17 #include "components/variations/variations_associated_data.h" 16 #include "components/variations/variations_associated_data.h"
18 #include "content/public/browser/user_metrics.h" 17 #include "content/public/browser/user_metrics.h"
18 #include "extensions/browser/api/extensions_api_client.h"
19 #include "extensions/browser/api/metrics_private/metrics_private_delegate.h"
19 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
20 21
21 namespace extensions { 22 namespace extensions {
22 23
23 namespace GetIsCrashReportingEnabled =
24 api::metrics_private::GetIsCrashReportingEnabled;
25 namespace GetVariationParams = api::metrics_private::GetVariationParams; 24 namespace GetVariationParams = api::metrics_private::GetVariationParams;
26 namespace GetFieldTrial = api::metrics_private::GetFieldTrial;
27 namespace RecordUserAction = api::metrics_private::RecordUserAction; 25 namespace RecordUserAction = api::metrics_private::RecordUserAction;
28 namespace RecordValue = api::metrics_private::RecordValue; 26 namespace RecordValue = api::metrics_private::RecordValue;
29 namespace RecordSparseValue = api::metrics_private::RecordSparseValue; 27 namespace RecordSparseValue = api::metrics_private::RecordSparseValue;
30 namespace RecordPercentage = api::metrics_private::RecordPercentage; 28 namespace RecordPercentage = api::metrics_private::RecordPercentage;
31 namespace RecordCount = api::metrics_private::RecordCount; 29 namespace RecordCount = api::metrics_private::RecordCount;
32 namespace RecordSmallCount = api::metrics_private::RecordSmallCount; 30 namespace RecordSmallCount = api::metrics_private::RecordSmallCount;
33 namespace RecordMediumCount = api::metrics_private::RecordMediumCount; 31 namespace RecordMediumCount = api::metrics_private::RecordMediumCount;
34 namespace RecordTime = api::metrics_private::RecordTime; 32 namespace RecordTime = api::metrics_private::RecordTime;
35 namespace RecordMediumTime = api::metrics_private::RecordMediumTime; 33 namespace RecordMediumTime = api::metrics_private::RecordMediumTime;
36 namespace RecordLongTime = api::metrics_private::RecordLongTime; 34 namespace RecordLongTime = api::metrics_private::RecordLongTime;
37 35
38 namespace { 36 namespace {
39 37
40 const size_t kMaxBuckets = 10000; // We don't ever want more than these many 38 const size_t kMaxBuckets = 10000; // We don't ever want more than these many
41 // buckets; there is no real need for them 39 // buckets; there is no real need for them
42 // and would cause crazy memory usage 40 // and would cause crazy memory usage
43 } // namespace 41 } // namespace
44 42
45 ExtensionFunction::ResponseAction 43 ExtensionFunction::ResponseAction
46 MetricsPrivateGetIsCrashReportingEnabledFunction::Run() { 44 MetricsPrivateGetIsCrashReportingEnabledFunction::Run() {
45 MetricsPrivateDelegate* delegate =
46 ExtensionsAPIClient::Get()->GetMetricsPrivateDelegate();
47 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>( 47 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>(
48 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()))); 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698