Broke ContentSettingBubbleModelTest.Plugins on Android.
[chromium-blink-merge.git] / content / browser / histogram_message_filter.cc
blob733ee87931143434fec6dfd96ad9945308c8caae
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"
16 namespace content {
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) {
26 bool handled = true;
27 IPC_BEGIN_MESSAGE_MAP_EX(HistogramMessageFilter, message, *message_was_ok)
28 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ChildHistogramData,
29 OnChildHistogramData)
30 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_GetBrowserHistogram,
31 OnGetBrowserHistogram)
32 IPC_MESSAGE_UNHANDLED(handled = false)
33 IPC_END_MESSAGE_MAP_EX()
34 return handled;
37 HistogramMessageFilter::~HistogramMessageFilter() {}
39 void HistogramMessageFilter::OnChildHistogramData(
40 int sequence_number,
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))
51 return;
52 if (name != "Memory.BrowserUsed")
53 return;
54 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name);
55 if (!histogram) {
56 *histogram_json = "{}";
57 } else {
58 histogram->WriteJSON(histogram_json);
62 } // namespace content