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

Side by Side Diff: chrome/browser/chromeos/external_metrics.cc

Issue 10917080: Histogram - add check for external LinearHistogram data with mismatching range. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error. Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 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/chromeos/external_metrics.h" 5 #include "chrome/browser/chromeos/external_metrics.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 #include <sys/file.h> 11 #include <sys/file.h>
12 #include <sys/stat.h> 12 #include <sys/stat.h>
13 #include <sys/types.h> 13 #include <sys/types.h>
14 #include <unistd.h> 14 #include <unistd.h>
15 15
16 #include <string> 16 #include <string>
17 17
18 #include "base/basictypes.h" 18 #include "base/basictypes.h"
19 #include "base/bind.h" 19 #include "base/bind.h"
20 #include "base/eintr_wrapper.h" 20 #include "base/eintr_wrapper.h"
21 #include "base/metrics/histogram.h" 21 #include "base/metrics/histogram.h"
22 #include "base/metrics/statistics_recorder.h"
22 #include "base/perftimer.h" 23 #include "base/perftimer.h"
23 #include "base/time.h" 24 #include "base/time.h"
24 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/metrics/metrics_service.h" 26 #include "chrome/browser/metrics/metrics_service.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/user_metrics.h" 28 #include "content/public/browser/user_metrics.h"
28 29
29 using content::BrowserThread; 30 using content::BrowserThread;
30 using content::UserMetricsAction; 31 using content::UserMetricsAction;
31 32
32 namespace chromeos { 33 namespace chromeos {
33 34
34 // The interval between external metrics collections in seconds 35 // The interval between external metrics collections in seconds
35 static const int kExternalMetricsCollectionIntervalSeconds = 30; 36 static const int kExternalMetricsCollectionIntervalSeconds = 30;
36 37
37 class SystemHistogram : public base::Histogram { 38 class SystemHistogram : public base::Histogram {
38 public: 39 public:
39 static bool CheckValues(const std::string& name, 40 static bool CheckValues(const std::string& name,
40 int minimum, 41 int minimum,
41 int maximum, 42 int maximum,
42 size_t bucket_count) { 43 size_t bucket_count) {
43 return base::Histogram::InspectConstructionArguments( 44 return base::Histogram::InspectConstructionArguments(
44 name, &minimum, &maximum, &bucket_count); 45 name, &minimum, &maximum, &bucket_count);
45 } 46 }
47 static bool CheckLinearValues(const std::string& name, int maximum) {
48 if (!CheckValues(name, 1, maximum, maximum + 1))
49 return false;
50 Histogram* histogram = base::StatisticsRecorder::FindHistogram(name);
51 if (!histogram)
52 return true;
53 return histogram->HasConstructionArguments(1, maximum, maximum + 1);
54 }
46 }; 55 };
47 56
48 ExternalMetrics::ExternalMetrics() 57 ExternalMetrics::ExternalMetrics()
49 : test_recorder_(NULL) { 58 : test_recorder_(NULL) {
50 } 59 }
51 60
52 ExternalMetrics::~ExternalMetrics() {} 61 ExternalMetrics::~ExternalMetrics() {}
53 62
54 void ExternalMetrics::Start() { 63 void ExternalMetrics::Start() {
55 // Register user actions external to the browser. 64 // Register user actions external to the browser.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 126
118 void ExternalMetrics::RecordLinearHistogram(const char* histogram_data) { 127 void ExternalMetrics::RecordLinearHistogram(const char* histogram_data) {
119 int sample, max; 128 int sample, max;
120 char name[128]; // length must be consistent with sscanf format below. 129 char name[128]; // length must be consistent with sscanf format below.
121 int n = sscanf(histogram_data, "%127s %d %d", name, &sample, &max); 130 int n = sscanf(histogram_data, "%127s %d %d", name, &sample, &max);
122 if (n != 3) { 131 if (n != 3) {
123 LOG(ERROR) << "bad linear histogram request: " << histogram_data; 132 LOG(ERROR) << "bad linear histogram request: " << histogram_data;
124 return; 133 return;
125 } 134 }
126 135
127 if (!SystemHistogram::CheckValues(name, 1, max, max + 1)) { 136 if (!SystemHistogram::CheckLinearValues(name, max)) {
128 LOG(ERROR) << "Invalid linear histogram " << name 137 LOG(ERROR) << "Invalid linear histogram " << name
129 << ", max=" << max; 138 << ", max=" << max;
130 return; 139 return;
131 } 140 }
132 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram 141 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram
133 // instance and thus only work if |name| is constant. 142 // instance and thus only work if |name| is constant.
134 base::Histogram* counter = base::LinearHistogram::FactoryGet( 143 base::Histogram* counter = base::LinearHistogram::FactoryGet(
135 name, 1, max, max + 1, base::Histogram::kUmaTargetedHistogramFlag); 144 name, 1, max, max + 1, base::Histogram::kUmaTargetedHistogramFlag);
136 counter->Add(sample); 145 counter->Add(sample);
137 } 146 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 void ExternalMetrics::ScheduleCollector() { 266 void ExternalMetrics::ScheduleCollector() {
258 bool result; 267 bool result;
259 result = BrowserThread::PostDelayedTask( 268 result = BrowserThread::PostDelayedTask(
260 BrowserThread::FILE, FROM_HERE, 269 BrowserThread::FILE, FROM_HERE,
261 base::Bind(&chromeos::ExternalMetrics::CollectEventsAndReschedule, this), 270 base::Bind(&chromeos::ExternalMetrics::CollectEventsAndReschedule, this),
262 base::TimeDelta::FromSeconds(kExternalMetricsCollectionIntervalSeconds)); 271 base::TimeDelta::FromSeconds(kExternalMetricsCollectionIntervalSeconds));
263 DCHECK(result); 272 DCHECK(result);
264 } 273 }
265 274
266 } // namespace chromeos 275 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698