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

Side by Side Diff: chrome/browser/extensions/extension_metrics_module.cc

Issue 9113002: Prevent calling internal metrics code with invalid values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 2011 -> 2012 Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « base/metrics/histogram.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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/extension_metrics_module.h" 5 #include "chrome/browser/extensions/extension_metrics_module.h"
6 6
7 #include <algorithm>
8
7 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
8 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
9 #include "content/public/browser/user_metrics.h" 11 #include "content/public/browser/user_metrics.h"
10 12
11 using base::Histogram; 13 using base::Histogram;
12 using base::LinearHistogram; 14 using base::LinearHistogram;
13 using content::UserMetricsAction; 15 using content::UserMetricsAction;
14 16
17 const size_t kMaxBuckets = 10000; // We don't ever want more than these many
18 // buckets; there is no real need for them
19 // and would cause crazy memory usage
20
15 bool MetricsRecordUserActionFunction::RunImpl() { 21 bool MetricsRecordUserActionFunction::RunImpl() {
16 std::string name; 22 std::string name;
17 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name)); 23 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name));
18 24
19 content::RecordComputedAction(name); 25 content::RecordComputedAction(name);
20 return true; 26 return true;
21 } 27 }
22 28
23 bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name, 29 bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name,
24 int* sample) { 30 int* sample) {
25 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, name)); 31 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, name));
26 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, sample)); 32 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, sample));
27 return true; 33 return true;
28 } 34 }
29 35
30 bool MetricsHistogramHelperFunction::RecordValue(const std::string& name, 36 bool MetricsHistogramHelperFunction::RecordValue(const std::string& name,
31 Histogram::ClassType type, 37 Histogram::ClassType type,
32 int min, 38 int min,
33 int max, 39 int max,
34 size_t buckets, 40 size_t buckets,
35 int sample) { 41 int sample) {
42 // Make sure toxic values don't get to internal code.
43 // Fix for maximums
44 min = std::min(min, INT_MAX - 3);
45 max = std::min(max, INT_MAX - 3);
46 buckets = std::min(buckets, kMaxBuckets);
47 // Fix for minimums.
48 min = std::max(min, 1);
49 max = std::max(max, min + 1);
50 buckets = std::max(buckets, static_cast<size_t>(3));
51 // Trim buckets down to a maximum of the given range + over/underflow buckets
52 if (buckets > static_cast<size_t>(max - min + 2))
53 buckets = max - min + 2;
54
36 Histogram* counter; 55 Histogram* counter;
37 if (type == Histogram::LINEAR_HISTOGRAM) { 56 if (type == Histogram::LINEAR_HISTOGRAM) {
38 counter = LinearHistogram::FactoryGet(name, 57 counter = LinearHistogram::FactoryGet(name,
39 min, 58 min,
40 max, 59 max,
41 buckets, 60 buckets,
42 Histogram::kUmaTargetedHistogramFlag); 61 Histogram::kUmaTargetedHistogramFlag);
43 } else { 62 } else {
44 counter = Histogram::FactoryGet(name, 63 counter = Histogram::FactoryGet(name,
45 min, 64 min,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return RecordValue(name, Histogram::HISTOGRAM, 1, kThreeMinMs, 50, sample); 139 return RecordValue(name, Histogram::HISTOGRAM, 1, kThreeMinMs, 50, sample);
121 } 140 }
122 141
123 bool MetricsRecordLongTimeFunction::RunImpl() { 142 bool MetricsRecordLongTimeFunction::RunImpl() {
124 std::string name; 143 std::string name;
125 int sample; 144 int sample;
126 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample)); 145 EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample));
127 static const int kOneHourMs = 60 * 60 * 1000; 146 static const int kOneHourMs = 60 * 60 * 1000;
128 return RecordValue(name, Histogram::HISTOGRAM, 1, kOneHourMs, 50, sample); 147 return RecordValue(name, Histogram::HISTOGRAM, 1, kOneHourMs, 50, sample);
129 } 148 }
OLDNEW
« no previous file with comments | « base/metrics/histogram.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698