| OLD | NEW |
| 1 // Copyright (c) 2011 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 "content/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/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 | 16 |
| 17 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : | 17 ChildProcessInfo::ChildProcessInfo(content::ProcessType type, int id) : |
| 18 type_(type) { | 18 type_(type) { |
| 19 if (id == -1) | 19 if (id == -1) |
| 20 id_ = GenerateChildProcessUniqueId(); | 20 id_ = GenerateChildProcessUniqueId(); |
| 21 else | 21 else |
| 22 id_ = id; | 22 id_ = id; |
| 23 } | 23 } |
| 24 | 24 |
| 25 ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original) | 25 ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original) |
| 26 : type_(original.type_), | 26 : type_(original.type_), |
| 27 name_(original.name_), | 27 name_(original.name_), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 40 name_ = original.name_; | 40 name_ = original.name_; |
| 41 version_ = original.version_; | 41 version_ = original.version_; |
| 42 id_ = original.id_; | 42 id_ = original.id_; |
| 43 process_ = original.process_; | 43 process_ = original.process_; |
| 44 } | 44 } |
| 45 return *this; | 45 return *this; |
| 46 } | 46 } |
| 47 | 47 |
| 48 // static | 48 // static |
| 49 std::string ChildProcessInfo::GetTypeNameInEnglish( | 49 std::string ChildProcessInfo::GetTypeNameInEnglish( |
| 50 ChildProcessInfo::ProcessType type) { | 50 content::ProcessType type) { |
| 51 switch (type) { | 51 switch (type) { |
| 52 case BROWSER_PROCESS: | 52 case content::PROCESS_TYPE_BROWSER: |
| 53 return "Browser"; | 53 return "Browser"; |
| 54 case RENDER_PROCESS: | 54 case content::PROCESS_TYPE_RENDERER: |
| 55 return "Tab"; | 55 return "Tab"; |
| 56 case PLUGIN_PROCESS: | 56 case content::PROCESS_TYPE_PLUGIN: |
| 57 return "Plug-in"; | 57 return "Plug-in"; |
| 58 case WORKER_PROCESS: | 58 case content::PROCESS_TYPE_WORKER: |
| 59 return "Web Worker"; | 59 return "Web Worker"; |
| 60 case UTILITY_PROCESS: | 60 case content::PROCESS_TYPE_UTILITY: |
| 61 return "Utility"; | 61 return "Utility"; |
| 62 case PROFILE_IMPORT_PROCESS: | 62 case content::PROCESS_TYPE_PROFILE_IMPORT: |
| 63 return "Profile Import helper"; | 63 return "Profile Import helper"; |
| 64 case ZYGOTE_PROCESS: | 64 case content::PROCESS_TYPE_ZYGOTE: |
| 65 return "Zygote"; | 65 return "Zygote"; |
| 66 case SANDBOX_HELPER_PROCESS: | 66 case content::PROCESS_TYPE_SANDBOX_HELPER: |
| 67 return "Sandbox helper"; | 67 return "Sandbox helper"; |
| 68 case NACL_LOADER_PROCESS: | 68 case content::PROCESS_TYPE_NACL_LOADER: |
| 69 return "Native Client module"; | 69 return "Native Client module"; |
| 70 case NACL_BROKER_PROCESS: | 70 case content::PROCESS_TYPE_NACL_BROKER: |
| 71 return "Native Client broker"; | 71 return "Native Client broker"; |
| 72 case GPU_PROCESS: | 72 case content::PROCESS_TYPE_GPU: |
| 73 return "GPU"; | 73 return "GPU"; |
| 74 case PPAPI_PLUGIN_PROCESS: | 74 case content::PROCESS_TYPE_PPAPI_PLUGIN: |
| 75 return "Pepper Plugin"; | 75 return "Pepper Plugin"; |
| 76 case PPAPI_BROKER_PROCESS: | 76 case content::PROCESS_TYPE_PPAPI_BROKER: |
| 77 return "Pepper Plugin Broker"; | 77 return "Pepper Plugin Broker"; |
| 78 case UNKNOWN_PROCESS: | 78 case content::PROCESS_TYPE_UNKNOWN: |
| 79 default: | 79 default: |
| 80 DCHECK(false) << "Unknown child process type!"; | 80 DCHECK(false) << "Unknown child process type!"; |
| 81 return "Unknown"; | 81 return "Unknown"; |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { | 85 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { |
| 86 // Note: the string must start with the current process id, this is how | 86 // Note: the string must start with the current process id, this is how |
| 87 // child processes determine the pid of the parent. | 87 // child processes determine the pid of the parent. |
| 88 // Build the channel ID. This is composed of a unique identifier for the | 88 // Build the channel ID. This is composed of a unique identifier for the |
| 89 // parent browser process, an identifier for the child instance, and a random | 89 // parent browser process, an identifier for the child instance, and a random |
| 90 // component. We use a random component so that a hacked child process can't | 90 // component. We use a random component so that a hacked child process can't |
| 91 // cause denial of service by causing future named pipe creation to fail. | 91 // cause denial of service by causing future named pipe creation to fail. |
| 92 return base::StringPrintf("%d.%p.%d", | 92 return base::StringPrintf("%d.%p.%d", |
| 93 base::GetCurrentProcId(), instance, | 93 base::GetCurrentProcId(), instance, |
| 94 base::RandInt(0, std::numeric_limits<int>::max())); | 94 base::RandInt(0, std::numeric_limits<int>::max())); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // static | 97 // static |
| 98 int ChildProcessInfo::GenerateChildProcessUniqueId() { | 98 int ChildProcessInfo::GenerateChildProcessUniqueId() { |
| 99 // This function must be threadsafe. | 99 // This function must be threadsafe. |
| 100 static base::subtle::Atomic32 last_unique_child_id = 0; | 100 static base::subtle::Atomic32 last_unique_child_id = 0; |
| 101 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); | 101 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); |
| 102 } | 102 } |
| OLD | NEW |