OLD | NEW |
(Empty) | |
| 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/browser/histogram_controller_impl.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" |
| 9 #include "content/common/child_process_messages.h" |
| 10 #include "content/public/browser/browser_child_process_host_iterator.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/child_process_data.h" |
| 13 #include "content/public/browser/histogram_subscriber.h" |
| 14 #include "content/public/browser/render_process_host.h" |
| 15 |
| 16 using content::BrowserChildProcessHostIterator; |
| 17 using content::BrowserThread; |
| 18 |
| 19 namespace content { |
| 20 |
| 21 content::HistogramController* content::HistogramController::GetInstance() { |
| 22 return HistogramControllerImpl::GetInstance(); |
| 23 } |
| 24 |
| 25 HistogramControllerImpl* HistogramControllerImpl::GetInstance() { |
| 26 return Singleton<HistogramControllerImpl>::get(); |
| 27 } |
| 28 |
| 29 HistogramControllerImpl::HistogramControllerImpl() : subscriber_(NULL) { |
| 30 } |
| 31 |
| 32 HistogramControllerImpl::~HistogramControllerImpl() { |
| 33 } |
| 34 |
| 35 void HistogramControllerImpl::OnPendingProcesses(int sequence_number, |
| 36 int pending_processes, |
| 37 bool end) { |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 39 if (subscriber_) |
| 40 subscriber_->OnPendingProcesses(sequence_number, pending_processes, end); |
| 41 } |
| 42 |
| 43 void HistogramControllerImpl::OnHistogramDataCollected( |
| 44 int sequence_number, |
| 45 const std::vector<std::string>& pickled_histograms, |
| 46 content::ProcessType process_type) { |
| 47 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 48 BrowserThread::PostTask( |
| 49 BrowserThread::UI, FROM_HERE, |
| 50 base::Bind(&HistogramControllerImpl::OnHistogramDataCollected, |
| 51 base::Unretained(this), |
| 52 sequence_number, |
| 53 pickled_histograms, |
| 54 process_type)); |
| 55 return; |
| 56 } |
| 57 |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 59 if (subscriber_) { |
| 60 subscriber_->OnHistogramDataCollected(sequence_number, |
| 61 pickled_histograms, |
| 62 process_type); |
| 63 } |
| 64 } |
| 65 |
| 66 void HistogramControllerImpl::Register(HistogramSubscriber* subscriber) { |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 68 DCHECK(!subscriber_); |
| 69 subscriber_ = subscriber; |
| 70 } |
| 71 |
| 72 void HistogramControllerImpl::Unregister( |
| 73 const HistogramSubscriber* subscriber) { |
| 74 DCHECK_EQ(subscriber_, subscriber); |
| 75 subscriber_ = NULL; |
| 76 } |
| 77 |
| 78 void HistogramControllerImpl::GetHistogramDataFromChildProcesses( |
| 79 int sequence_number) { |
| 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 81 |
| 82 int pending_processes = 0; |
| 83 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { |
| 84 ++pending_processes; |
| 85 if (!iter.Send(new ChildProcessMsg_GetChildHistogramData(sequence_number))) |
| 86 --pending_processes; |
| 87 } |
| 88 |
| 89 BrowserThread::PostTask( |
| 90 BrowserThread::UI, |
| 91 FROM_HERE, |
| 92 base::Bind( |
| 93 &HistogramControllerImpl::OnPendingProcesses, |
| 94 base::Unretained(this), |
| 95 sequence_number, |
| 96 pending_processes, |
| 97 true)); |
| 98 } |
| 99 |
| 100 void HistogramControllerImpl::GetHistogramData(int sequence_number) { |
| 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 102 |
| 103 int pending_processes = 0; |
| 104 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
| 105 !it.IsAtEnd(); it.Advance()) { |
| 106 ++pending_processes; |
| 107 if (!it.GetCurrentValue()->Send( |
| 108 new ChildProcessMsg_GetChildHistogramData(sequence_number))) { |
| 109 --pending_processes; |
| 110 } |
| 111 } |
| 112 OnPendingProcesses(sequence_number, pending_processes, false); |
| 113 |
| 114 BrowserThread::PostTask( |
| 115 BrowserThread::IO, |
| 116 FROM_HERE, |
| 117 base::Bind(&HistogramControllerImpl::GetHistogramDataFromChildProcesses, |
| 118 base::Unretained(this), |
| 119 sequence_number)); |
| 120 } |
| 121 |
| 122 } // namespace content |
OLD | NEW |