OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiler_controller_impl.h" | 5 #include "content/browser/profiler_controller_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "content/browser/browser_child_process_host.h" | |
10 #include "content/common/child_process_messages.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" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/child_process_data.h" |
12 #include "content/public/browser/profiler_subscriber.h" | 13 #include "content/public/browser/profiler_subscriber.h" |
13 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
14 #include "content/public/common/process_type.h" | 15 #include "content/public/common/process_type.h" |
15 | 16 |
| 17 using content::BrowserChildProcessHostIterator; |
16 using content::BrowserThread; | 18 using content::BrowserThread; |
17 | 19 |
18 namespace content { | 20 namespace content { |
19 | 21 |
20 content::ProfilerController* content::ProfilerController::GetInstance() { | 22 content::ProfilerController* content::ProfilerController::GetInstance() { |
21 return ProfilerControllerImpl::GetInstance(); | 23 return ProfilerControllerImpl::GetInstance(); |
22 } | 24 } |
23 | 25 |
24 ProfilerControllerImpl* ProfilerControllerImpl::GetInstance() { | 26 ProfilerControllerImpl* ProfilerControllerImpl::GetInstance() { |
25 return Singleton<ProfilerControllerImpl>::get(); | 27 return Singleton<ProfilerControllerImpl>::get(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 void ProfilerControllerImpl::Unregister(ProfilerSubscriber* subscriber) { | 68 void ProfilerControllerImpl::Unregister(ProfilerSubscriber* subscriber) { |
67 if (subscriber == subscriber_) | 69 if (subscriber == subscriber_) |
68 subscriber_ = NULL; | 70 subscriber_ = NULL; |
69 } | 71 } |
70 | 72 |
71 void ProfilerControllerImpl::GetProfilerDataFromChildProcesses( | 73 void ProfilerControllerImpl::GetProfilerDataFromChildProcesses( |
72 int sequence_number) { | 74 int sequence_number) { |
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
74 | 76 |
75 int pending_processes = 0; | 77 int pending_processes = 0; |
76 for (BrowserChildProcessHost::Iterator child_process_host; | 78 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { |
77 !child_process_host.Done(); ++child_process_host) { | |
78 const std::string process_type = | 79 const std::string process_type = |
79 content::GetProcessTypeNameInEnglish(child_process_host->data().type); | 80 content::GetProcessTypeNameInEnglish(iter.GetData().type); |
80 ++pending_processes; | 81 ++pending_processes; |
81 if (!child_process_host->Send(new ChildProcessMsg_GetChildProfilerData( | 82 if (!iter.Send(new ChildProcessMsg_GetChildProfilerData( |
82 sequence_number, process_type))) { | 83 sequence_number, process_type))) { |
83 --pending_processes; | 84 --pending_processes; |
84 } | 85 } |
85 } | 86 } |
86 | 87 |
87 BrowserThread::PostTask( | 88 BrowserThread::PostTask( |
88 BrowserThread::UI, | 89 BrowserThread::UI, |
89 FROM_HERE, | 90 FROM_HERE, |
90 base::Bind( | 91 base::Bind( |
91 &ProfilerControllerImpl::OnPendingProcesses, | 92 &ProfilerControllerImpl::OnPendingProcesses, |
92 base::Unretained(this), | 93 base::Unretained(this), |
(...skipping 23 matching lines...) Expand all Loading... |
116 BrowserThread::IO, | 117 BrowserThread::IO, |
117 FROM_HERE, | 118 FROM_HERE, |
118 base::Bind(&ProfilerControllerImpl::GetProfilerDataFromChildProcesses, | 119 base::Bind(&ProfilerControllerImpl::GetProfilerDataFromChildProcesses, |
119 base::Unretained(this), | 120 base::Unretained(this), |
120 sequence_number)); | 121 sequence_number)); |
121 } | 122 } |
122 | 123 |
123 void ProfilerControllerImpl::SetProfilerStatusInChildProcesses(bool enable) { | 124 void ProfilerControllerImpl::SetProfilerStatusInChildProcesses(bool enable) { |
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
125 | 126 |
126 for (BrowserChildProcessHost::Iterator child_process_host; | 127 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) |
127 !child_process_host.Done(); ++child_process_host) { | 128 iter.Send(new ChildProcessMsg_SetProfilerStatus(enable)); |
128 child_process_host->Send(new ChildProcessMsg_SetProfilerStatus(enable)); | |
129 } | |
130 } | 129 } |
131 | 130 |
132 void ProfilerControllerImpl::SetProfilerStatus(bool enable) { | 131 void ProfilerControllerImpl::SetProfilerStatus(bool enable) { |
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
134 | 133 |
135 BrowserThread::PostTask( | 134 BrowserThread::PostTask( |
136 BrowserThread::IO, | 135 BrowserThread::IO, |
137 FROM_HERE, | 136 FROM_HERE, |
138 base::Bind(&ProfilerControllerImpl::SetProfilerStatusInChildProcesses, | 137 base::Bind(&ProfilerControllerImpl::SetProfilerStatusInChildProcesses, |
139 base::Unretained(this), | 138 base::Unretained(this), |
140 enable)); | 139 enable)); |
141 | 140 |
142 for (content::RenderProcessHost::iterator it( | 141 for (content::RenderProcessHost::iterator it( |
143 content::RenderProcessHost::AllHostsIterator()); | 142 content::RenderProcessHost::AllHostsIterator()); |
144 !it.IsAtEnd(); it.Advance()) { | 143 !it.IsAtEnd(); it.Advance()) { |
145 it.GetCurrentValue()->Send(new ChildProcessMsg_SetProfilerStatus(enable)); | 144 it.GetCurrentValue()->Send(new ChildProcessMsg_SetProfilerStatus(enable)); |
146 } | 145 } |
147 } | 146 } |
148 } // namespace content | 147 } // namespace content |
OLD | NEW |