| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/common/child_process_info.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "grit/generated_resources.h" | |
| 17 #include "ui/base/l10n/l10n_util.h" | |
| 18 | 16 |
| 19 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : | 17 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : |
| 20 type_(type), | 18 type_(type), |
| 21 renderer_type_(RENDERER_UNKNOWN) { | 19 renderer_type_(RENDERER_UNKNOWN) { |
| 22 if (id == -1) | 20 if (id == -1) |
| 23 id_ = GenerateChildProcessUniqueId(); | 21 id_ = GenerateChildProcessUniqueId(); |
| 24 else | 22 else |
| 25 id_ = id; | 23 id_ = id; |
| 26 } | 24 } |
| 27 | 25 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 110 |
| 113 // static | 111 // static |
| 114 std::string ChildProcessInfo::GetFullTypeNameInEnglish( | 112 std::string ChildProcessInfo::GetFullTypeNameInEnglish( |
| 115 ChildProcessInfo::ProcessType type, | 113 ChildProcessInfo::ProcessType type, |
| 116 ChildProcessInfo::RendererProcessType rtype) { | 114 ChildProcessInfo::RendererProcessType rtype) { |
| 117 if (type == RENDER_PROCESS) | 115 if (type == RENDER_PROCESS) |
| 118 return GetRendererTypeNameInEnglish(rtype); | 116 return GetRendererTypeNameInEnglish(rtype); |
| 119 return GetTypeNameInEnglish(type); | 117 return GetTypeNameInEnglish(type); |
| 120 } | 118 } |
| 121 | 119 |
| 122 | |
| 123 string16 ChildProcessInfo::GetLocalizedTitle() const { | |
| 124 string16 title = WideToUTF16Hack(name_); | |
| 125 if (type_ == ChildProcessInfo::PLUGIN_PROCESS && title.empty()) | |
| 126 title = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME); | |
| 127 | |
| 128 // Explicitly mark name as LTR if there is no strong RTL character, | |
| 129 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the | |
| 130 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew | |
| 131 // or Arabic word for "plugin". | |
| 132 base::i18n::AdjustStringForLocaleDirection(&title); | |
| 133 | |
| 134 switch (type_) { | |
| 135 case ChildProcessInfo::UTILITY_PROCESS: | |
| 136 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UTILITY_PREFIX); | |
| 137 | |
| 138 case ChildProcessInfo::PROFILE_IMPORT_PROCESS: | |
| 139 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UTILITY_PREFIX); | |
| 140 | |
| 141 case ChildProcessInfo::GPU_PROCESS: | |
| 142 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_GPU_PREFIX); | |
| 143 | |
| 144 case ChildProcessInfo::NACL_BROKER_PROCESS: | |
| 145 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NACL_BROKER_PREFIX); | |
| 146 | |
| 147 case ChildProcessInfo::PLUGIN_PROCESS: | |
| 148 case ChildProcessInfo::PPAPI_PLUGIN_PROCESS: | |
| 149 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PLUGIN_PREFIX, | |
| 150 title, | |
| 151 WideToUTF16Hack(version_)); | |
| 152 | |
| 153 case ChildProcessInfo::NACL_LOADER_PROCESS: | |
| 154 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NACL_PREFIX, title); | |
| 155 | |
| 156 case ChildProcessInfo::WORKER_PROCESS: | |
| 157 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_WORKER_PREFIX, title); | |
| 158 | |
| 159 // These types don't need display names or get them from elsewhere. | |
| 160 case BROWSER_PROCESS: | |
| 161 case RENDER_PROCESS: | |
| 162 case ZYGOTE_PROCESS: | |
| 163 case SANDBOX_HELPER_PROCESS: | |
| 164 NOTREACHED(); | |
| 165 break; | |
| 166 | |
| 167 case UNKNOWN_PROCESS: | |
| 168 NOTREACHED() << "Need localized name for child process type."; | |
| 169 } | |
| 170 | |
| 171 return title; | |
| 172 } | |
| 173 | |
| 174 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { | 120 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { |
| 175 // Note: the string must start with the current process id, this is how | 121 // Note: the string must start with the current process id, this is how |
| 176 // child processes determine the pid of the parent. | 122 // child processes determine the pid of the parent. |
| 177 // Build the channel ID. This is composed of a unique identifier for the | 123 // Build the channel ID. This is composed of a unique identifier for the |
| 178 // parent browser process, an identifier for the child instance, and a random | 124 // parent browser process, an identifier for the child instance, and a random |
| 179 // component. We use a random component so that a hacked child process can't | 125 // component. We use a random component so that a hacked child process can't |
| 180 // cause denial of service by causing future named pipe creation to fail. | 126 // cause denial of service by causing future named pipe creation to fail. |
| 181 return base::StringPrintf("%d.%p.%d", | 127 return base::StringPrintf("%d.%p.%d", |
| 182 base::GetCurrentProcId(), instance, | 128 base::GetCurrentProcId(), instance, |
| 183 base::RandInt(0, std::numeric_limits<int>::max())); | 129 base::RandInt(0, std::numeric_limits<int>::max())); |
| 184 } | 130 } |
| 185 | 131 |
| 186 // static | 132 // static |
| 187 int ChildProcessInfo::GenerateChildProcessUniqueId() { | 133 int ChildProcessInfo::GenerateChildProcessUniqueId() { |
| 188 // This function must be threadsafe. | 134 // This function must be threadsafe. |
| 189 static base::subtle::Atomic32 last_unique_child_id = 0; | 135 static base::subtle::Atomic32 last_unique_child_id = 0; |
| 190 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); | 136 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); |
| 191 } | 137 } |
| OLD | NEW |