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. 4 5 #include "content/child/child_histogram_message_filter.h" 6 7 #include <ctype.h> 8 9 #include "base/bind.h" 10 #include "base/message_loop/message_loop.h" 11 #include "base/metrics/histogram_delta_serialization.h" 12 #include "content/child/child_process.h" 13 #include "content/child/child_thread.h" 14 #include "content/common/child_process_messages.h" 15 #include "ipc/ipc_sender.h" 16 17 namespace content { 18 ChildHistogramMessageFilter()19ChildHistogramMessageFilter::ChildHistogramMessageFilter() 20 : sender_(NULL), 21 io_message_loop_(ChildProcess::current()->io_message_loop_proxy()) { 22 } 23 ~ChildHistogramMessageFilter()24ChildHistogramMessageFilter::~ChildHistogramMessageFilter() { 25 } 26 OnFilterAdded(IPC::Sender * sender)27void ChildHistogramMessageFilter::OnFilterAdded(IPC::Sender* sender) { 28 sender_ = sender; 29 } 30 OnFilterRemoved()31void ChildHistogramMessageFilter::OnFilterRemoved() { 32 } 33 OnMessageReceived(const IPC::Message & message)34bool ChildHistogramMessageFilter::OnMessageReceived( 35 const IPC::Message& message) { 36 bool handled = true; 37 IPC_BEGIN_MESSAGE_MAP(ChildHistogramMessageFilter, message) 38 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildHistogramData, 39 OnGetChildHistogramData) 40 IPC_MESSAGE_UNHANDLED(handled = false) 41 IPC_END_MESSAGE_MAP() 42 return handled; 43 } 44 SendHistograms(int sequence_number)45void ChildHistogramMessageFilter::SendHistograms(int sequence_number) { 46 io_message_loop_->PostTask( 47 FROM_HERE, base::Bind(&ChildHistogramMessageFilter::UploadAllHistograms, 48 this, sequence_number)); 49 } 50 OnGetChildHistogramData(int sequence_number)51void ChildHistogramMessageFilter::OnGetChildHistogramData(int sequence_number) { 52 UploadAllHistograms(sequence_number); 53 } 54 UploadAllHistograms(int sequence_number)55void ChildHistogramMessageFilter::UploadAllHistograms(int sequence_number) { 56 if (!histogram_delta_serialization_) { 57 histogram_delta_serialization_.reset( 58 new base::HistogramDeltaSerialization("ChildProcess")); 59 } 60 61 std::vector<std::string> deltas; 62 histogram_delta_serialization_->PrepareAndSerializeDeltas(&deltas); 63 sender_->Send( 64 new ChildProcessHostMsg_ChildHistogramData(sequence_number, deltas)); 65 66 #ifndef NDEBUG 67 static int count = 0; 68 count++; 69 LOCAL_HISTOGRAM_COUNTS("Histogram.ChildProcessHistogramSentCount", count); 70 #endif 71 } 72 73 } // namespace content 74