By moving the call to Load() up in SearchProvider::Start(), we are giving a chance...
[chromium-blink-merge.git] / content / browser / profiler_controller_impl.cc
blobfcf61ea94684277630ae8a657b1e3532ac148ed6
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/profiler_controller_impl.h"
7 #include "base/bind.h"
8 #include "base/tracked_objects.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/profiler_subscriber.h"
14 #include "content/public/browser/render_process_host.h"
16 namespace content {
18 ProfilerController* ProfilerController::GetInstance() {
19 return ProfilerControllerImpl::GetInstance();
22 ProfilerControllerImpl* ProfilerControllerImpl::GetInstance() {
23 return Singleton<ProfilerControllerImpl>::get();
26 ProfilerControllerImpl::ProfilerControllerImpl() : subscriber_(NULL) {
29 ProfilerControllerImpl::~ProfilerControllerImpl() {
32 void ProfilerControllerImpl::OnPendingProcesses(int sequence_number,
33 int pending_processes,
34 bool end) {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
36 if (subscriber_)
37 subscriber_->OnPendingProcesses(sequence_number, pending_processes, end);
40 void ProfilerControllerImpl::OnProfilerDataCollected(
41 int sequence_number,
42 const tracked_objects::ProcessDataSnapshot& profiler_data,
43 ProcessType process_type) {
44 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
45 BrowserThread::PostTask(
46 BrowserThread::UI, FROM_HERE,
47 base::Bind(&ProfilerControllerImpl::OnProfilerDataCollected,
48 base::Unretained(this),
49 sequence_number,
50 profiler_data,
51 process_type));
52 return;
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 if (subscriber_) {
57 subscriber_->OnProfilerDataCollected(sequence_number, profiler_data,
58 process_type);
62 void ProfilerControllerImpl::Register(ProfilerSubscriber* subscriber) {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
64 DCHECK(!subscriber_);
65 subscriber_ = subscriber;
68 void ProfilerControllerImpl::Unregister(const ProfilerSubscriber* subscriber) {
69 DCHECK_EQ(subscriber_, subscriber);
70 subscriber_ = NULL;
73 void ProfilerControllerImpl::GetProfilerDataFromChildProcesses(
74 int sequence_number) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
77 int pending_processes = 0;
78 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) {
79 ++pending_processes;
80 if (!iter.Send(new ChildProcessMsg_GetChildProfilerData(sequence_number)))
81 --pending_processes;
84 BrowserThread::PostTask(
85 BrowserThread::UI,
86 FROM_HERE,
87 base::Bind(
88 &ProfilerControllerImpl::OnPendingProcesses,
89 base::Unretained(this),
90 sequence_number,
91 pending_processes,
92 true));
95 void ProfilerControllerImpl::GetProfilerData(int sequence_number) {
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
98 int pending_processes = 0;
99 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
100 !it.IsAtEnd(); it.Advance()) {
101 ++pending_processes;
102 if (!it.GetCurrentValue()->Send(
103 new ChildProcessMsg_GetChildProfilerData(sequence_number))) {
104 --pending_processes;
107 OnPendingProcesses(sequence_number, pending_processes, false);
109 BrowserThread::PostTask(
110 BrowserThread::IO,
111 FROM_HERE,
112 base::Bind(&ProfilerControllerImpl::GetProfilerDataFromChildProcesses,
113 base::Unretained(this),
114 sequence_number));
117 } // namespace content