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" | |
8 #include "base/metrics/histogram.h" | |
9 #include "base/metrics/statistics_recorder.h" | |
7 #include "base/process_util.h" | 10 #include "base/process_util.h" |
8 #include "content/browser/histogram_controller.h" | 11 #include "content/browser/histogram_controller.h" |
9 #include "content/browser/tcmalloc_internals_request_job.h" | 12 #include "content/browser/tcmalloc_internals_request_job.h" |
10 #include "content/common/child_process_messages.h" | 13 #include "content/common/child_process_messages.h" |
14 #include "content/public/common/content_switches.h" | |
11 | 15 |
12 namespace content { | 16 namespace content { |
13 | 17 |
14 HistogramMessageFilter::HistogramMessageFilter() {} | 18 HistogramMessageFilter::HistogramMessageFilter() {} |
15 | 19 |
16 void HistogramMessageFilter::OnChannelConnected(int32 peer_pid) { | 20 void HistogramMessageFilter::OnChannelConnected(int32 peer_pid) { |
17 BrowserMessageFilter::OnChannelConnected(peer_pid); | 21 BrowserMessageFilter::OnChannelConnected(peer_pid); |
18 } | 22 } |
19 | 23 |
20 bool HistogramMessageFilter::OnMessageReceived(const IPC::Message& message, | 24 bool HistogramMessageFilter::OnMessageReceived(const IPC::Message& message, |
21 bool* message_was_ok) { | 25 bool* message_was_ok) { |
22 bool handled = true; | 26 bool handled = true; |
23 IPC_BEGIN_MESSAGE_MAP_EX(HistogramMessageFilter, message, *message_was_ok) | 27 IPC_BEGIN_MESSAGE_MAP_EX(HistogramMessageFilter, message, *message_was_ok) |
24 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ChildHistogramData, | 28 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ChildHistogramData, |
25 OnChildHistogramData) | 29 OnChildHistogramData) |
30 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_GetBrowserHistogram, | |
31 OnGetBrowserHistogram) | |
jochen (gone - plz use gerrit)
2013/01/18 14:03:11
you need to make sure that this is on the IO threa
marja
2013/01/18 15:00:08
Added a dcheck in the handler func; it's run in th
| |
26 IPC_MESSAGE_UNHANDLED(handled = false) | 32 IPC_MESSAGE_UNHANDLED(handled = false) |
27 IPC_END_MESSAGE_MAP_EX() | 33 IPC_END_MESSAGE_MAP_EX() |
28 return handled; | 34 return handled; |
29 } | 35 } |
30 | 36 |
31 HistogramMessageFilter::~HistogramMessageFilter() {} | 37 HistogramMessageFilter::~HistogramMessageFilter() {} |
32 | 38 |
33 void HistogramMessageFilter::OnChildHistogramData( | 39 void HistogramMessageFilter::OnChildHistogramData( |
34 int sequence_number, | 40 int sequence_number, |
35 const std::vector<std::string>& pickled_histograms) { | 41 const std::vector<std::string>& pickled_histograms) { |
36 HistogramController::GetInstance()->OnHistogramDataCollected( | 42 HistogramController::GetInstance()->OnHistogramDataCollected( |
37 sequence_number, pickled_histograms); | 43 sequence_number, pickled_histograms); |
38 } | 44 } |
45 | |
46 void HistogramMessageFilter::OnGetBrowserHistogram( | |
47 const std::string& name, | |
48 std::string* histogram_json) { | |
49 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMemoryMetrics)) | |
50 return; | |
51 base::Histogram* histogram = | |
52 base::StatisticsRecorder::FindHistogram(name); | |
jochen (gone - plz use gerrit)
2013/01/18 14:03:11
maybe even add a whitelist?
marja
2013/01/18 15:00:08
Done.
| |
53 if (!histogram) { | |
54 *histogram_json = "{}"; | |
55 } else { | |
56 histogram->WriteJSON(histogram_json); | |
57 } | |
39 } | 58 } |
59 | |
60 } | |
jochen (gone - plz use gerrit)
2013/01/18 14:03:11
// namespace content
marja
2013/01/18 15:00:08
Done.
| |
OLD | NEW |