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 "base/process_util.h"
11 #include "content/browser/histogram_controller.h"
12 #include "content/browser/tcmalloc_internals_request_job.h"
13 #include "content/common/child_process_messages.h"
14 #include "content/public/common/content_switches.h"
18 HistogramMessageFilter::HistogramMessageFilter() {}
20 void HistogramMessageFilter::OnChannelConnected(int32 peer_pid
) {
21 BrowserMessageFilter::OnChannelConnected(peer_pid
);
24 bool HistogramMessageFilter::OnMessageReceived(const IPC::Message
& message
,
25 bool* message_was_ok
) {
27 IPC_BEGIN_MESSAGE_MAP_EX(HistogramMessageFilter
, message
, *message_was_ok
)
28 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ChildHistogramData
,
30 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_GetBrowserHistogram
,
31 OnGetBrowserHistogram
)
32 IPC_MESSAGE_UNHANDLED(handled
= false)
33 IPC_END_MESSAGE_MAP_EX()
37 HistogramMessageFilter::~HistogramMessageFilter() {}
39 void HistogramMessageFilter::OnChildHistogramData(
41 const std::vector
<std::string
>& pickled_histograms
) {
42 HistogramController::GetInstance()->OnHistogramDataCollected(
43 sequence_number
, pickled_histograms
);
46 void HistogramMessageFilter::OnGetBrowserHistogram(
47 const std::string
& name
,
48 std::string
* histogram_json
) {
49 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO
));
50 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMemoryMetrics
))
52 if (name
!= "Memory.BrowserUsed")
54 base::Histogram
* histogram
= base::StatisticsRecorder::FindHistogram(name
);
56 *histogram_json
= "{}";
58 histogram
->WriteJSON(histogram_json
);
62 } // namespace content