Cast: Skip receiver log messages with time delta that can't be encoded.
[chromium-blink-merge.git] / content / browser / histogram_controller.cc
blob240de2556b97c6f589b880b2a6fc5f2ae711863e
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_controller.h"
7 #include "base/bind.h"
8 #include "base/metrics/histogram.h"
9 #include "content/browser/histogram_subscriber.h"
10 #include "content/common/child_process_messages.h"
11 #include "content/public/browser/browser_child_process_host_iterator.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/child_process_data.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/common/process_type.h"
17 namespace content {
19 HistogramController* HistogramController::GetInstance() {
20 return Singleton<HistogramController>::get();
23 HistogramController::HistogramController() : subscriber_(NULL) {
26 HistogramController::~HistogramController() {
29 void HistogramController::OnPendingProcesses(int sequence_number,
30 int pending_processes,
31 bool end) {
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
33 if (subscriber_)
34 subscriber_->OnPendingProcesses(sequence_number, pending_processes, end);
37 void HistogramController::OnHistogramDataCollected(
38 int sequence_number,
39 const std::vector<std::string>& pickled_histograms) {
40 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
41 BrowserThread::PostTask(
42 BrowserThread::UI, FROM_HERE,
43 base::Bind(&HistogramController::OnHistogramDataCollected,
44 base::Unretained(this),
45 sequence_number,
46 pickled_histograms));
47 return;
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
51 if (subscriber_) {
52 subscriber_->OnHistogramDataCollected(sequence_number,
53 pickled_histograms);
57 void HistogramController::Register(HistogramSubscriber* subscriber) {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59 DCHECK(!subscriber_);
60 subscriber_ = subscriber;
63 void HistogramController::Unregister(
64 const HistogramSubscriber* subscriber) {
65 DCHECK_EQ(subscriber_, subscriber);
66 subscriber_ = NULL;
69 void HistogramController::GetHistogramDataFromChildProcesses(
70 int sequence_number) {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
73 int pending_processes = 0;
74 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) {
75 int type = iter.GetData().process_type;
76 if (type != PROCESS_TYPE_PLUGIN &&
77 type != PROCESS_TYPE_GPU &&
78 type != PROCESS_TYPE_PPAPI_PLUGIN &&
79 type != PROCESS_TYPE_PPAPI_BROKER) {
80 continue;
83 ++pending_processes;
84 if (!iter.Send(new ChildProcessMsg_GetChildHistogramData(sequence_number)))
85 --pending_processes;
88 BrowserThread::PostTask(
89 BrowserThread::UI,
90 FROM_HERE,
91 base::Bind(
92 &HistogramController::OnPendingProcesses,
93 base::Unretained(this),
94 sequence_number,
95 pending_processes,
96 true));
99 void HistogramController::GetHistogramData(int sequence_number) {
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
102 int pending_processes = 0;
103 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
104 !it.IsAtEnd(); it.Advance()) {
105 ++pending_processes;
106 if (!it.GetCurrentValue()->Send(
107 new ChildProcessMsg_GetChildHistogramData(sequence_number))) {
108 --pending_processes;
111 OnPendingProcesses(sequence_number, pending_processes, false);
113 BrowserThread::PostTask(
114 BrowserThread::IO,
115 FROM_HERE,
116 base::Bind(&HistogramController::GetHistogramDataFromChildProcesses,
117 base::Unretained(this),
118 sequence_number));
121 } // namespace content