summaryrefslogtreecommitdiffstats
path: root/chrome/common/child_process_info.cc
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.cc
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.cc')
-rw-r--r--chrome/common/child_process_info.cc45
1 files changed, 34 insertions, 11 deletions
diff --git a/chrome/common/child_process_info.cc b/chrome/common/child_process_info.cc
index 819b7fc..770c9866 100644
--- a/chrome/common/child_process_info.cc
+++ b/chrome/common/child_process_info.cc
@@ -7,12 +7,34 @@
#include <limits>
#include "app/l10n_util.h"
+#include "base/atomicops.h"
#include "base/logging.h"
#include "base/process_util.h"
#include "base/rand_util.h"
#include "base/string_util.h"
#include "grit/generated_resources.h"
+ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original)
+ : type_(original.type_),
+ name_(original.name_),
+ id_(original.id_),
+ process_(original.process_) {
+}
+
+ChildProcessInfo::~ChildProcessInfo() {
+}
+
+ChildProcessInfo& ChildProcessInfo::operator=(
+ const ChildProcessInfo& original) {
+ if (&original != this) {
+ type_ = original.type_;
+ name_ = original.name_;
+ id_ = original.id_;
+ process_ = original.process_;
+ }
+ return *this;
+}
+
std::wstring ChildProcessInfo::GetTypeNameInEnglish(
ChildProcessInfo::ProcessType type) {
switch (type) {
@@ -56,17 +78,11 @@ std::wstring ChildProcessInfo::GetLocalizedTitle() const {
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;
- pid_ = -1;
-}
-
-
-ChildProcessInfo::~ChildProcessInfo() {
+ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : type_(type) {
+ if (id == -1)
+ id_ = GenerateChildProcessUniqueId();
+ else
+ id_ = id;
}
std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) {
@@ -80,3 +96,10 @@ std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) {
base::GetCurrentProcId(), instance,
base::RandInt(0, std::numeric_limits<int>::max()));
}
+
+// static
+int ChildProcessInfo::GenerateChildProcessUniqueId() {
+ // This function must be threadsafe.
+ static base::subtle::Atomic32 last_unique_child_id = 0;
+ return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1);
+}