summaryrefslogtreecommitdiffstats
path: root/chrome/common/child_process_info.cc
diff options
context:
space:
mode:
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);
+}