summaryrefslogtreecommitdiffstats
path: root/chrome/common/child_process_info.h
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-31 17:27:45 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-31 17:27:45 +0000
commit76543b9c43515c8c68413b25d682b7c15a151905 (patch)
tree3fa26b07a2de8102561d5ded5828797fa9a375ab /chrome/common/child_process_info.h
parentf341f8f58ceeae4efe38daf3c26ad4581f98fd2d (diff)
downloadchromium_src-76543b9c43515c8c68413b25d682b7c15a151905.zip
chromium_src-76543b9c43515c8c68413b25d682b7c15a151905.tar.gz
chromium_src-76543b9c43515c8c68413b25d682b7c15a151905.tar.bz2
Replace the RenderProcessHost.PID function that returns the OS-generated
process ID with an internally-generated id() function. This allows us the guarantee that the IDs are unique over the entire run of the application. This also cleans up some code associated with managing the PID. The main potentially interesting change is now the PID is set uniquely for every creation of RenderProcessHost. It used to be set cleared if the process went away, and re-set if the process was re-created. The ID generation is in ChildProcesInfo so it is also unique between workers and plugins. I had to change some significant things in resource_dispatcher_host_unittest to take into account this new generation of IDs. BUG=17828 TEST=none Review URL: http://codereview.chromium.org/160203 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24899 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/child_process_info.h')
-rw-r--r--chrome/common/child_process_info.h59
1 files changed, 26 insertions, 33 deletions
diff --git a/chrome/common/child_process_info.h b/chrome/common/child_process_info.h
index d79435f..3d80a1d 100644
--- a/chrome/common/child_process_info.h
+++ b/chrome/common/child_process_info.h
@@ -21,6 +21,11 @@ class ChildProcessInfo {
UNKNOWN_PROCESS,
};
+ ChildProcessInfo(const ChildProcessInfo& original);
+ virtual ~ChildProcessInfo();
+
+ ChildProcessInfo& operator=(const ChildProcessInfo& original);
+
// Returns the type of the process.
ProcessType type() const { return type_; }
@@ -31,13 +36,11 @@ class ChildProcessInfo {
// Getter to the process handle.
base::ProcessHandle handle() const { return process_.handle(); }
- virtual int GetProcessId() const {
- if (pid_ != -1)
- return pid_;
+ // The unique identifier for this child process. This identifier is NOT a
+ // process ID, and will be unique for all types of child process for
+ // one run of the browser.
+ int id() const { return id_; }
- pid_ = process_.pid();
- return pid_;
- }
void SetProcessBackgrounded() const { process_.SetProcessBackgrounded(true); }
void ReduceWorkingSet() const { process_.ReduceWorkingSet(); }
@@ -49,25 +52,6 @@ class ChildProcessInfo {
// 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_;
- pid_ = original.pid_;
- }
-
- ChildProcessInfo& operator=(const ChildProcessInfo& original) {
- if (&original != this) {
- type_ = original.type_;
- name_ = original.name_;
- process_ = original.process_;
- pid_ = original.pid_;
- }
- return *this;
- }
-
- virtual ~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 {
@@ -84,21 +68,30 @@ class ChildProcessInfo {
// The "instance" pointer value is baked into the channel id.
static std::string GenerateRandomChannelID(void* instance);
+ // Returns a unique ID to identify a child process. On construction, this
+ // function will be used to generate the id_, but it is also used to generate
+ // IDs for the RenderProcessHost, which doesn't inherit from us, and whose IDs
+ // must be unique for all child processes.
+ //
+ // This function is threadsafe since RenderProcessHost is on the UI thread,
+ // but normally this will be used on the IO thread.
+ static int GenerateChildProcessUniqueId();
+
protected:
+ // Derived objects need to use this constructor so we know what type we are.
+ // If the caller has already generated a unique ID for this child process,
+ // it should pass it as the second argument. Otherwise, -1 should be passed
+ // and a unique ID will be automatically generated.
+ ChildProcessInfo(ProcessType type, int id);
+
void set_type(ProcessType type) { type_ = type; }
void set_name(const std::wstring& name) { name_ = name; }
- void set_handle(base::ProcessHandle handle) {
- process_.set_handle(handle);
- pid_ = -1;
- }
-
- // Derived objects need to use this constructor so we know what type we are.
- ChildProcessInfo(ProcessType type);
+ void set_handle(base::ProcessHandle handle) { process_.set_handle(handle); }
private:
ProcessType type_;
std::wstring name_;
- mutable int pid_; // Cache of the process id.
+ int id_;
// The handle to the process.
mutable base::Process process_;