diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-13 23:16:42 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-13 23:16:42 +0000 |
commit | a436d92d5121ebfc9996682cfed4c3ad33313138 (patch) | |
tree | 55c32ef45ccc9e808e98074b5a26565239ed06fc /chrome/common/child_process_info.cc | |
parent | b2ca508afc56d4b7f6d5b036dd721604440210b3 (diff) | |
download | chromium_src-a436d92d5121ebfc9996682cfed4c3ad33313138.zip chromium_src-a436d92d5121ebfc9996682cfed4c3ad33313138.tar.gz chromium_src-a436d92d5121ebfc9996682cfed4c3ad33313138.tar.bz2 |
Have ChildProcessInfo contain a list of all running child processes (i.e. instead of Service and other child process service maintain it). In a future change I'll start moving some of the code from PluginProcessHost to ChildProcessInfo.
Review URL: http://codereview.chromium.org/24017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9804 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/child_process_info.cc')
-rw-r--r-- | chrome/common/child_process_info.cc | 80 |
1 files changed, 67 insertions, 13 deletions
diff --git a/chrome/common/child_process_info.cc b/chrome/common/child_process_info.cc index ca777bd..af69e10 100644 --- a/chrome/common/child_process_info.cc +++ b/chrome/common/child_process_info.cc @@ -5,26 +5,31 @@ #include "chrome/common/child_process_info.h" #include "base/logging.h" +#include "base/singleton.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/common/l10n_util.h" #include "generated_resources.h" +typedef std::list<ChildProcessInfo*> ChildProcessList; + + std::wstring ChildProcessInfo::GetTypeNameInEnglish( ChildProcessInfo::ProcessType type) { switch (type) { - case BROWSER_PROCESS: - return L"Browser"; - case RENDER_PROCESS: - return L"Tab"; - case PLUGIN_PROCESS: - return L"Plug-in"; - case WORKER_PROCESS: - return L"Web Worker"; - case UNKNOWN_PROCESS: - default: - DCHECK(false) << "Unknown child process type!"; - return L"Unknown"; - } + case BROWSER_PROCESS: + return L"Browser"; + case RENDER_PROCESS: + return L"Tab"; + case PLUGIN_PROCESS: + return L"Plug-in"; + case WORKER_PROCESS: + return L"Web Worker"; + case UNKNOWN_PROCESS: + default: + DCHECK(false) << "Unknown child process type!"; + return L"Unknown"; + } } std::wstring ChildProcessInfo::GetLocalizedTitle() const { @@ -49,3 +54,52 @@ std::wstring ChildProcessInfo::GetLocalizedTitle() const { l10n_util::AdjustStringForLocaleDirection(title, &title); return l10n_util::GetStringF(message_id, title); } + +ChildProcessInfo::ChildProcessInfo(ProcessType type) { + // This constructor is only used by objects which derive from this class, + // which means *this* is a real object that refers to a child process, and not + // just a simple object that contains information about it. So add it to our + // list of running processes. + type_ = type; + Singleton<ChildProcessList>::get()->push_back(this); +} + + +ChildProcessInfo::~ChildProcessInfo() { + Singleton<ChildProcessList>::get()->remove(this); +} + + +ChildProcessInfo::Iterator::Iterator() : all_(true) { + iterator_ = Singleton<ChildProcessList>::get()->begin(); + DCHECK(MessageLoop::current() == + ChromeThread::GetMessageLoop(ChromeThread::IO)) << + "ChildProcessInfo::Iterator must be used on the IO thread."; +} + +ChildProcessInfo::Iterator::Iterator(ProcessType type) + : all_(false), type_(type) { + iterator_ = Singleton<ChildProcessList>::get()->begin(); + DCHECK(MessageLoop::current() == + ChromeThread::GetMessageLoop(ChromeThread::IO)) << + "ChildProcessInfo::Iterator must be used on the IO thread."; +} + +ChildProcessInfo* ChildProcessInfo::Iterator::operator++() { + do { + ++iterator_; + if (Done()) + break; + + if (!all_ && (*iterator_)->type() != type_) + continue; + + return *iterator_; + } while (true); + + return NULL; +} + +bool ChildProcessInfo::Iterator::Done() { + return iterator_ == Singleton<ChildProcessList>::get()->end(); +} |