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 "content/browser/histogram_message_filter.h" | 5 #include "content/browser/histogram_message_filter.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 void HistogramMessageFilter::OnGetBrowserHistogram( | 46 void HistogramMessageFilter::OnGetBrowserHistogram( |
47 const std::string& name, | 47 const std::string& name, |
48 std::string* histogram_json) { | 48 std::string* histogram_json) { |
49 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 49 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
50 // Security: Only allow access to browser histograms when running in the | 50 // Security: Only allow access to browser histograms when running in the |
51 // context of a test. | 51 // context of a test. |
52 bool using_stats_collection_controller = | 52 bool using_stats_collection_controller = |
53 CommandLine::ForCurrentProcess()->HasSwitch( | 53 CommandLine::ForCurrentProcess()->HasSwitch( |
54 switches::kStatsCollectionController); | 54 switches::kStatsCollectionController); |
55 bool reduced_security = | 55 if (!using_stats_collection_controller) { |
56 CommandLine::ForCurrentProcess()->HasSwitch( | |
57 switches::kReduceSecurityForStatsCollectionTests); | |
58 | |
59 if (!using_stats_collection_controller || !reduced_security) { | |
60 LOG(ERROR) << "Attempt at reading browser histogram without specifying " | 56 LOG(ERROR) << "Attempt at reading browser histogram without specifying " |
61 << "--" << switches::kStatsCollectionController << " and " | 57 << "--" << switches::kStatsCollectionController << " switch."; |
62 << "--" << switches::kReduceSecurityForStatsCollectionTests | |
63 << " switches."; | |
64 return; | 58 return; |
65 } | 59 } |
66 base::HistogramBase* histogram = | 60 base::HistogramBase* histogram = |
67 base::StatisticsRecorder::FindHistogram(name); | 61 base::StatisticsRecorder::FindHistogram(name); |
68 if (!histogram) { | 62 if (!histogram) { |
69 *histogram_json = "{}"; | 63 *histogram_json = "{}"; |
70 } else { | 64 } else { |
71 histogram->WriteJSON(histogram_json); | 65 histogram->WriteJSON(histogram_json); |
72 } | 66 } |
73 } | 67 } |
74 | 68 |
75 } // namespace content | 69 } // namespace content |
OLD | NEW |