| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 if (&original != this) { | 38 if (&original != this) { |
| 39 type_ = original.type_; | 39 type_ = original.type_; |
| 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 | |
| 49 std::string ChildProcessInfo::GetTypeNameInEnglish( | |
| 50 content::ProcessType type) { | |
| 51 switch (type) { | |
| 52 case content::PROCESS_TYPE_BROWSER: | |
| 53 return "Browser"; | |
| 54 case content::PROCESS_TYPE_RENDERER: | |
| 55 return "Tab"; | |
| 56 case content::PROCESS_TYPE_PLUGIN: | |
| 57 return "Plug-in"; | |
| 58 case content::PROCESS_TYPE_WORKER: | |
| 59 return "Web Worker"; | |
| 60 case content::PROCESS_TYPE_UTILITY: | |
| 61 return "Utility"; | |
| 62 case content::PROCESS_TYPE_PROFILE_IMPORT: | |
| 63 return "Profile Import helper"; | |
| 64 case content::PROCESS_TYPE_ZYGOTE: | |
| 65 return "Zygote"; | |
| 66 case content::PROCESS_TYPE_SANDBOX_HELPER: | |
| 67 return "Sandbox helper"; | |
| 68 case content::PROCESS_TYPE_NACL_LOADER: | |
| 69 return "Native Client module"; | |
| 70 case content::PROCESS_TYPE_NACL_BROKER: | |
| 71 return "Native Client broker"; | |
| 72 case content::PROCESS_TYPE_GPU: | |
| 73 return "GPU"; | |
| 74 case content::PROCESS_TYPE_PPAPI_PLUGIN: | |
| 75 return "Pepper Plugin"; | |
| 76 case content::PROCESS_TYPE_PPAPI_BROKER: | |
| 77 return "Pepper Plugin Broker"; | |
| 78 case content::PROCESS_TYPE_UNKNOWN: | |
| 79 default: | |
| 80 DCHECK(false) << "Unknown child process type!"; | |
| 81 return "Unknown"; | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { | 48 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { |
| 86 // Note: the string must start with the current process id, this is how | 49 // Note: the string must start with the current process id, this is how |
| 87 // child processes determine the pid of the parent. | 50 // child processes determine the pid of the parent. |
| 88 // Build the channel ID. This is composed of a unique identifier for the | 51 // 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 | 52 // 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 | 53 // 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. | 54 // cause denial of service by causing future named pipe creation to fail. |
| 92 return base::StringPrintf("%d.%p.%d", | 55 return base::StringPrintf("%d.%p.%d", |
| 93 base::GetCurrentProcId(), instance, | 56 base::GetCurrentProcId(), instance, |
| 94 base::RandInt(0, std::numeric_limits<int>::max())); | 57 base::RandInt(0, std::numeric_limits<int>::max())); |
| 95 } | 58 } |
| 96 | 59 |
| 97 // static | 60 // static |
| 98 int ChildProcessInfo::GenerateChildProcessUniqueId() { | 61 int ChildProcessInfo::GenerateChildProcessUniqueId() { |
| 99 // This function must be threadsafe. | 62 // This function must be threadsafe. |
| 100 static base::subtle::Atomic32 last_unique_child_id = 0; | 63 static base::subtle::Atomic32 last_unique_child_id = 0; |
| 101 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); | 64 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); |
| 102 } | 65 } |
| OLD | NEW |