| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/child_process_info.h" | 5 #include "chrome/common/child_process_info.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
| 11 #include "base/i18n/rtl.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 13 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 16 | 17 |
| 17 ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original) | 18 ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original) |
| 18 : type_(original.type_), | 19 : type_(original.type_), |
| 19 name_(original.name_), | 20 name_(original.name_), |
| 20 id_(original.id_), | 21 id_(original.id_), |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 message_id = IDS_TASK_MANAGER_NACL_BROKER_PREFIX; | 86 message_id = IDS_TASK_MANAGER_NACL_BROKER_PREFIX; |
| 86 } else { | 87 } else { |
| 87 DCHECK(false) << "Need localized name for child process type."; | 88 DCHECK(false) << "Need localized name for child process type."; |
| 88 return title; | 89 return title; |
| 89 } | 90 } |
| 90 | 91 |
| 91 // Explicitly mark name as LTR if there is no strong RTL character, | 92 // Explicitly mark name as LTR if there is no strong RTL character, |
| 92 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the | 93 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the |
| 93 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew | 94 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew |
| 94 // or Arabic word for "plugin". | 95 // or Arabic word for "plugin". |
| 95 l10n_util::AdjustStringForLocaleDirection(title, &title); | 96 base::i18n::AdjustStringForLocaleDirection(title, &title); |
| 96 return l10n_util::GetStringF(message_id, title); | 97 return l10n_util::GetStringF(message_id, title); |
| 97 } | 98 } |
| 98 | 99 |
| 99 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : type_(type) { | 100 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : type_(type) { |
| 100 if (id == -1) | 101 if (id == -1) |
| 101 id_ = GenerateChildProcessUniqueId(); | 102 id_ = GenerateChildProcessUniqueId(); |
| 102 else | 103 else |
| 103 id_ = id; | 104 id_ = id; |
| 104 } | 105 } |
| 105 | 106 |
| 106 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { | 107 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { |
| 107 // Note: the string must start with the current process id, this is how | 108 // Note: the string must start with the current process id, this is how |
| 108 // child processes determine the pid of the parent. | 109 // child processes determine the pid of the parent. |
| 109 // Build the channel ID. This is composed of a unique identifier for the | 110 // Build the channel ID. This is composed of a unique identifier for the |
| 110 // parent browser process, an identifier for the child instance, and a random | 111 // parent browser process, an identifier for the child instance, and a random |
| 111 // component. We use a random component so that a hacked child process can't | 112 // component. We use a random component so that a hacked child process can't |
| 112 // cause denial of service by causing future named pipe creation to fail. | 113 // cause denial of service by causing future named pipe creation to fail. |
| 113 return StringPrintf("%d.%p.%d", | 114 return StringPrintf("%d.%p.%d", |
| 114 base::GetCurrentProcId(), instance, | 115 base::GetCurrentProcId(), instance, |
| 115 base::RandInt(0, std::numeric_limits<int>::max())); | 116 base::RandInt(0, std::numeric_limits<int>::max())); |
| 116 } | 117 } |
| 117 | 118 |
| 118 // static | 119 // static |
| 119 int ChildProcessInfo::GenerateChildProcessUniqueId() { | 120 int ChildProcessInfo::GenerateChildProcessUniqueId() { |
| 120 // This function must be threadsafe. | 121 // This function must be threadsafe. |
| 121 static base::subtle::Atomic32 last_unique_child_id = 0; | 122 static base::subtle::Atomic32 last_unique_child_id = 0; |
| 122 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); | 123 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); |
| 123 } | 124 } |
| OLD | NEW |