Chromium Code Reviews| Index: content/browser/profiler_controller.cc |
| =================================================================== |
| --- content/browser/profiler_controller.cc (revision 0) |
| +++ content/browser/profiler_controller.cc (revision 0) |
| @@ -0,0 +1,100 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
jam
2011/11/30 00:22:25
this stuff should really be in profiler_controller
ramant (doing other things)
2011/11/30 19:37:21
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/public/browser/profiler_controller.h" |
| + |
| +#include "base/bind.h" |
| +#include "content/browser/browser_child_process_host.h" |
| +#include "content/browser/profiler_controller_impl.h" |
| +#include "content/common/child_process_info.h" |
| +#include "content/common/child_process_messages.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_process_host.h" |
| + |
| +namespace content { |
| + |
| +// static |
| +void GetProfilerDataFromChildProcesses(int sequence_number) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + |
| + int pending_processes = 0; |
| + for (BrowserChildProcessHost::Iterator child_process_host; |
| + !child_process_host.Done(); ++child_process_host) { |
| + const std::string process_type = |
| + ChildProcessInfo::GetTypeNameInEnglish(child_process_host->type()); |
| + |
| + ++pending_processes; |
| + if (!child_process_host->Send(new ChildProcessMsg_GetChildProfilerData( |
| + sequence_number, process_type))) { |
| + --pending_processes; |
| + } |
| + } |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind( |
| + &ProfilerControllerImpl::OnPendingProcesses, |
| + base::Unretained(content::ProfilerControllerImpl::GetInstance()), |
| + sequence_number, |
| + pending_processes)); |
| +} |
| + |
| +// static |
| +int GetProfilerData(int sequence_number) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&GetProfilerDataFromChildProcesses, sequence_number)); |
| + |
| + int pending_processes = 0; |
| + const std::string render_process_type = |
| + ChildProcessInfo::GetTypeNameInEnglish(ChildProcessInfo::RENDER_PROCESS); |
| + |
| + for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
| + !it.IsAtEnd(); it.Advance()) { |
| + ++pending_processes; |
| + if (!it.GetCurrentValue()->Send(new ChildProcessMsg_GetChildProfilerData( |
| + sequence_number, render_process_type))) { |
| + --pending_processes; |
| + } |
| + } |
| + |
| + content::ProfilerControllerImpl::GetInstance()->OnPendingProcesses( |
| + sequence_number, pending_processes); |
| + |
| + // Returns 2 to indicate that OnPendingProcesses will be called once for |
| + // renderer processes and another for browser child processes. |
| + return 2; |
| +} |
| + |
| +// static |
| +void SetProfilerStatusInChildProcesses(bool enable) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + |
| + for (BrowserChildProcessHost::Iterator child_process_host; |
| + !child_process_host.Done(); ++child_process_host) { |
| + child_process_host->Send(new ChildProcessMsg_SetProfilerStatus(enable)); |
| + } |
| +} |
| + |
| +// static |
| +void SetProfilerStatus(bool enable) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind( |
| + &SetProfilerStatusInChildProcesses, enable)); |
| + |
| + for (content::RenderProcessHost::iterator it( |
| + content::RenderProcessHost::AllHostsIterator()); |
| + !it.IsAtEnd(); it.Advance()) { |
| + it.GetCurrentValue()->Send(new ChildProcessMsg_SetProfilerStatus(enable)); |
| + } |
| +} |
| +} // content |
| Property changes on: content\browser\profiler_controller.cc |
| ___________________________________________________________________ |
| Added: svn:executable |
| + * |