summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-13 23:16:42 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-13 23:16:42 +0000
commita436d92d5121ebfc9996682cfed4c3ad33313138 (patch)
tree55c32ef45ccc9e808e98074b5a26565239ed06fc /chrome/common
parentb2ca508afc56d4b7f6d5b036dd721604440210b3 (diff)
downloadchromium_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')
-rw-r--r--chrome/common/child_process_info.cc80
-rw-r--r--chrome/common/child_process_info.h182
-rw-r--r--chrome/common/debug_flags.cc14
-rw-r--r--chrome/common/debug_flags.h4
4 files changed, 195 insertions, 85 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();
+}
diff --git a/chrome/common/child_process_info.h b/chrome/common/child_process_info.h
index 2007bcb..d95eac4 100644
--- a/chrome/common/child_process_info.h
+++ b/chrome/common/child_process_info.h
@@ -1,66 +1,116 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_
-#define CHROME_COMMON_CHILD_PROCESS_INFO_H_
-
-#include <string>
-#include "base/basictypes.h"
-#include "base/process.h"
-
-// Holds information about a child process.
-class ChildProcessInfo {
- public:
- enum ProcessType {
- BROWSER_PROCESS,
- RENDER_PROCESS,
- PLUGIN_PROCESS,
- WORKER_PROCESS,
- UNKNOWN_PROCESS,
- };
-
- // Returns the type of the process.
- ProcessType type() const { return type_; }
-
- // Returns the name of the process. i.e. for plugins it might be Flash, while
- // for workers it might be the domain that it's from.
- std::wstring name() const { return name_; }
-
- // Getter to the process.
- base::Process& process() { return process_; }
-
- // Returns an English name of the process type, should only be used for non
- // user-visible strings, or debugging pages like about:memory.
- static std::wstring GetTypeNameInEnglish(ProcessType type);
-
- // Returns a localized title for the child process. For example, a plugin
- // process would be "Plug-in: Flash" when name is "Flash".
- std::wstring GetLocalizedTitle() const;
-
- // We define the < operator so that the ChildProcessInfo can be used as a key
- // in a std::map.
- bool operator <(const ChildProcessInfo& rhs) const {
- if (process_.handle() != rhs.process_.handle())
- return process_ .handle() < rhs.process_.handle();
- return name_ < rhs.name_;
- }
-
- bool operator ==(const ChildProcessInfo& rhs) const {
- return (process_.handle() == rhs.process_.handle()) && (name_ == rhs.name_);
- }
-
- protected:
- void set_type(ProcessType type) { type_ = type; }
- void set_name(const std::wstring& name) { name_ = name; }
-
- private:
- ProcessType type_;
- std::wstring name_;
-
- // The handle to the process.
- base::Process process_;
-};
-
-#endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_
-
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_
+#define CHROME_COMMON_CHILD_PROCESS_INFO_H_
+
+#include <list>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/process.h"
+
+class ChildProcessInfo;
+
+// Holds information about a child process. Plugins/workers and other child
+// processes that live on the IO thread derive from this.
+class ChildProcessInfo {
+ public:
+ enum ProcessType {
+ BROWSER_PROCESS,
+ RENDER_PROCESS,
+ PLUGIN_PROCESS,
+ WORKER_PROCESS,
+ UNKNOWN_PROCESS,
+ };
+
+ // Returns the type of the process.
+ ProcessType type() const { return type_; }
+
+ // Returns the name of the process. i.e. for plugins it might be Flash, while
+ // for workers it might be the domain that it's from.
+ std::wstring name() const { return name_; }
+
+ // Getter to the process.
+ base::Process& process() { return process_; }
+
+ // Returns an English name of the process type, should only be used for non
+ // user-visible strings, or debugging pages like about:memory.
+ static std::wstring GetTypeNameInEnglish(ProcessType type);
+
+ // Returns a localized title for the child process. For example, a plugin
+ // process would be "Plug-in: Flash" when name is "Flash".
+ std::wstring GetLocalizedTitle() const;
+
+ ChildProcessInfo(const ChildProcessInfo& original) {
+ type_ = original.type_;
+ name_ = original.name_;
+ process_ = original.process_;
+ }
+
+ ChildProcessInfo& operator=(const ChildProcessInfo& original) {
+ if (&original != this) {
+ type_ = original.type_;
+ name_ = original.name_;
+ process_ = original.process_;
+ }
+ return *this;
+ }
+
+ ~ChildProcessInfo();
+
+ // We define the < operator so that the ChildProcessInfo can be used as a key
+ // in a std::map.
+ bool operator <(const ChildProcessInfo& rhs) const {
+ if (process_.handle() != rhs.process_.handle())
+ return process_ .handle() < rhs.process_.handle();
+ return name_ < rhs.name_;
+ }
+
+ bool operator ==(const ChildProcessInfo& rhs) const {
+ return (process_.handle() == rhs.process_.handle()) && (name_ == rhs.name_);
+ }
+
+ // The Iterator class allows iteration through either all child processes, or
+ // ones of a specific type, depending on which constructor is used. Note that
+ // this should be done from the IO thread and that the iterator should not be
+ // kept around as it may be invalidated on subsequent event processing in the
+ // event loop.
+ class Iterator {
+ public:
+ Iterator();
+ Iterator(ProcessType type);
+ ChildProcessInfo* operator->() { return *iterator_; }
+ ChildProcessInfo* operator*() { return *iterator_; }
+ ChildProcessInfo* operator++();
+ bool Done();
+
+ private:
+ bool all_;
+ ProcessType type_;
+ std::list<ChildProcessInfo*>::iterator iterator_;
+ };
+
+ protected:
+ void set_type(ProcessType type) { type_ = type; }
+ void set_name(const std::wstring& name) { name_ = name; }
+
+ // Derived objects need to use this constructor so we know what type we are.
+ ChildProcessInfo(ProcessType type);
+
+ private:
+ // By making the constructor private, we can ensure that ChildProcessInfo
+ // objects can only be created by creating objects derived from them (i.e.
+ // PluginProcessHost) or by using the copy constructor or assignment operator
+ // to create an object from the former.
+ ChildProcessInfo() { }
+
+ ProcessType type_;
+ std::wstring name_;
+
+ // The handle to the process.
+ base::Process process_;
+};
+
+#endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_
diff --git a/chrome/common/debug_flags.cc b/chrome/common/debug_flags.cc
index 9f62cbe..97c2725 100644
--- a/chrome/common/debug_flags.cc
+++ b/chrome/common/debug_flags.cc
@@ -9,7 +9,7 @@
#include "chrome/common/chrome_switches.h"
bool DebugFlags::ProcessDebugFlags(CommandLine* command_line,
- ChildProcessType type,
+ ChildProcessInfo::ProcessType type,
bool is_in_sandbox) {
bool should_help_child = false;
const CommandLine& current_cmd_line = *CommandLine::ForCurrentProcess();
@@ -18,8 +18,10 @@ bool DebugFlags::ProcessDebugFlags(CommandLine* command_line,
std::wstring value;
value = current_cmd_line.GetSwitchValue(switches::kDebugChildren);
if (value.empty() ||
- (type == RENDERER && value == switches::kRendererProcess) ||
- (type == PLUGIN && value == switches::kPluginProcess)) {
+ (type == ChildProcessInfo::RENDER_PROCESS &&
+ value == switches::kRendererProcess) ||
+ (type == ChildProcessInfo::PLUGIN_PROCESS &&
+ value == switches::kPluginProcess)) {
command_line->AppendSwitch(switches::kDebugOnStart);
should_help_child = true;
}
@@ -29,8 +31,10 @@ bool DebugFlags::ProcessDebugFlags(CommandLine* command_line,
std::wstring value;
value = current_cmd_line.GetSwitchValue(switches::kWaitForDebuggerChildren);
if (value.empty() ||
- (type == RENDERER && value == switches::kRendererProcess) ||
- (type == PLUGIN && value == switches::kPluginProcess)) {
+ (type == ChildProcessInfo::RENDER_PROCESS &&
+ value == switches::kRendererProcess) ||
+ (type == ChildProcessInfo::PLUGIN_PROCESS &&
+ value == switches::kPluginProcess)) {
command_line->AppendSwitch(switches::kWaitForDebugger);
}
command_line->AppendSwitchWithValue(switches::kWaitForDebuggerChildren,
diff --git a/chrome/common/debug_flags.h b/chrome/common/debug_flags.h
index c2115a9..1a6d813 100644
--- a/chrome/common/debug_flags.h
+++ b/chrome/common/debug_flags.h
@@ -5,6 +5,8 @@
#ifndef CHROME_COMMON_DEBUG_FLAGS_H__
#define CHROME_COMMON_DEBUG_FLAGS_H__
+#include "chrome/common/child_process_info.h"
+
class CommandLine;
class DebugFlags {
@@ -24,7 +26,7 @@ class DebugFlags {
// calling the JIT debugger on it. It may only happen if
// is_in_sandbox is true.
static bool ProcessDebugFlags(CommandLine* command_line,
- ChildProcessType type,
+ ChildProcessInfo::ProcessType type,
bool is_in_sandbox);
};