Cast: Skip receiver log messages with time delta that can't be encoded.
[chromium-blink-merge.git] / content / browser / histogram_message_filter.cc
blobeae1100c1227de4f78ff37ccbeaa63c964951836
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
3 // found in the LICENSE file.
5 #include "content/browser/histogram_message_filter.h"
7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h"
9 #include "base/metrics/statistics_recorder.h"
10 #include "content/browser/histogram_controller.h"
11 #include "content/browser/tcmalloc_internals_request_job.h"
12 #include "content/common/child_process_messages.h"
13 #include "content/public/common/content_switches.h"
15 namespace content {
17 HistogramMessageFilter::HistogramMessageFilter()
18 : BrowserMessageFilter(ChildProcessMsgStart) {}
20 bool HistogramMessageFilter::OnMessageReceived(const IPC::Message& message,
21 bool* message_was_ok) {
22 bool handled = true;
23 IPC_BEGIN_MESSAGE_MAP_EX(HistogramMessageFilter, message, *message_was_ok)
24 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ChildHistogramData,
25 OnChildHistogramData)
26 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_GetBrowserHistogram,
27 OnGetBrowserHistogram)
28 IPC_MESSAGE_UNHANDLED(handled = false)
29 IPC_END_MESSAGE_MAP_EX()
30 return handled;
33 HistogramMessageFilter::~HistogramMessageFilter() {}
35 void HistogramMessageFilter::OnChildHistogramData(
36 int sequence_number,
37 const std::vector<std::string>& pickled_histograms) {
38 HistogramController::GetInstance()->OnHistogramDataCollected(
39 sequence_number, pickled_histograms);
42 void HistogramMessageFilter::OnGetBrowserHistogram(
43 const std::string& name,
44 std::string* histogram_json) {
45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
46 // Security: Only allow access to browser histograms when running in the
47 // context of a test.
48 bool using_stats_collection_controller =
49 CommandLine::ForCurrentProcess()->HasSwitch(
50 switches::kStatsCollectionController);
51 if (!using_stats_collection_controller) {
52 LOG(ERROR) << "Attempt at reading browser histogram without specifying "
53 << "--" << switches::kStatsCollectionController << " switch.";
54 return;
56 base::HistogramBase* histogram =
57 base::StatisticsRecorder::FindHistogram(name);
58 if (!histogram) {
59 *histogram_json = "{}";
60 } else {
61 histogram->WriteJSON(histogram_json);
65 } // namespace content