| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/i18n/rtl.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 | 18 |
| 19 ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original) | 19 ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original) |
| 20 : type_(original.type_), | 20 : type_(original.type_), |
| 21 renderer_type_(original.renderer_type_), |
| 21 name_(original.name_), | 22 name_(original.name_), |
| 22 version_(original.version_), | 23 version_(original.version_), |
| 23 id_(original.id_), | 24 id_(original.id_), |
| 24 process_(original.process_) { | 25 process_(original.process_) { |
| 25 } | 26 } |
| 26 | 27 |
| 27 ChildProcessInfo::~ChildProcessInfo() { | 28 ChildProcessInfo::~ChildProcessInfo() { |
| 28 } | 29 } |
| 29 | 30 |
| 30 ChildProcessInfo& ChildProcessInfo::operator=( | 31 ChildProcessInfo& ChildProcessInfo::operator=( |
| 31 const ChildProcessInfo& original) { | 32 const ChildProcessInfo& original) { |
| 32 if (&original != this) { | 33 if (&original != this) { |
| 33 type_ = original.type_; | 34 type_ = original.type_; |
| 35 renderer_type_ = original.renderer_type_; |
| 34 name_ = original.name_; | 36 name_ = original.name_; |
| 35 version_ = original.version_; | 37 version_ = original.version_; |
| 36 id_ = original.id_; | 38 id_ = original.id_; |
| 37 process_ = original.process_; | 39 process_ = original.process_; |
| 38 } | 40 } |
| 39 return *this; | 41 return *this; |
| 40 } | 42 } |
| 41 | 43 |
| 44 // static |
| 42 std::string ChildProcessInfo::GetTypeNameInEnglish( | 45 std::string ChildProcessInfo::GetTypeNameInEnglish( |
| 43 ChildProcessInfo::ProcessType type) { | 46 ChildProcessInfo::ProcessType type) { |
| 44 switch (type) { | 47 switch (type) { |
| 45 case BROWSER_PROCESS: | 48 case BROWSER_PROCESS: |
| 46 return "Browser"; | 49 return "Browser"; |
| 47 case RENDER_PROCESS: | 50 case RENDER_PROCESS: |
| 48 return "Tab"; | 51 return "Tab"; |
| 49 case PLUGIN_PROCESS: | 52 case PLUGIN_PROCESS: |
| 50 return "Plug-in"; | 53 return "Plug-in"; |
| 51 case WORKER_PROCESS: | 54 case WORKER_PROCESS: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 66 return "GPU"; | 69 return "GPU"; |
| 67 case PPAPI_PLUGIN_PROCESS: | 70 case PPAPI_PLUGIN_PROCESS: |
| 68 return "Pepper Plugin"; | 71 return "Pepper Plugin"; |
| 69 case UNKNOWN_PROCESS: | 72 case UNKNOWN_PROCESS: |
| 70 default: | 73 default: |
| 71 DCHECK(false) << "Unknown child process type!"; | 74 DCHECK(false) << "Unknown child process type!"; |
| 72 return "Unknown"; | 75 return "Unknown"; |
| 73 } | 76 } |
| 74 } | 77 } |
| 75 | 78 |
| 79 // static |
| 80 std::string ChildProcessInfo::GetRendererTypeNameInEnglish( |
| 81 ChildProcessInfo::RendererProcessType type) { |
| 82 switch (type) { |
| 83 case RENDERER_NORMAL: |
| 84 return "Tab"; |
| 85 case RENDERER_CHROME: |
| 86 return "Tab (Chrome)"; |
| 87 case RENDERER_EXTENSION: |
| 88 return "Extension"; |
| 89 case RENDERER_DEVTOOLS: |
| 90 return "Devtools"; |
| 91 case RENDERER_INTERSTITIAL: |
| 92 return "Interstitial"; |
| 93 case RENDERER_NOTIFICATION: |
| 94 return "Notification"; |
| 95 case RENDERER_BACKGROUND_APP: |
| 96 return "Background App"; |
| 97 case RENDERER_UNKNOWN: |
| 98 default: |
| 99 NOTREACHED() << "Unknown renderer process type!"; |
| 100 return "Unknown"; |
| 101 } |
| 102 } |
| 103 |
| 104 // static |
| 105 std::string ChildProcessInfo::GetFullTypeNameInEnglish( |
| 106 ChildProcessInfo::ProcessType type, |
| 107 ChildProcessInfo::RendererProcessType rtype) { |
| 108 if (type == RENDER_PROCESS) |
| 109 return GetRendererTypeNameInEnglish(rtype); |
| 110 return GetTypeNameInEnglish(type); |
| 111 } |
| 112 |
| 113 |
| 76 string16 ChildProcessInfo::GetLocalizedTitle() const { | 114 string16 ChildProcessInfo::GetLocalizedTitle() const { |
| 77 string16 title = WideToUTF16Hack(name_); | 115 string16 title = WideToUTF16Hack(name_); |
| 78 if (type_ == ChildProcessInfo::PLUGIN_PROCESS && title.empty()) | 116 if (type_ == ChildProcessInfo::PLUGIN_PROCESS && title.empty()) |
| 79 title = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME); | 117 title = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME); |
| 80 | 118 |
| 81 // Explicitly mark name as LTR if there is no strong RTL character, | 119 // Explicitly mark name as LTR if there is no strong RTL character, |
| 82 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the | 120 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the |
| 83 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew | 121 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew |
| 84 // or Arabic word for "plugin". | 122 // or Arabic word for "plugin". |
| 85 base::i18n::AdjustStringForLocaleDirection(&title); | 123 base::i18n::AdjustStringForLocaleDirection(&title); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 break; | 156 break; |
| 119 | 157 |
| 120 case UNKNOWN_PROCESS: | 158 case UNKNOWN_PROCESS: |
| 121 NOTREACHED() << "Need localized name for child process type."; | 159 NOTREACHED() << "Need localized name for child process type."; |
| 122 } | 160 } |
| 123 | 161 |
| 124 return title; | 162 return title; |
| 125 } | 163 } |
| 126 | 164 |
| 127 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : type_(type) { | 165 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : type_(type) { |
| 166 renderer_type_ = RENDERER_UNKNOWN; |
| 128 if (id == -1) | 167 if (id == -1) |
| 129 id_ = GenerateChildProcessUniqueId(); | 168 id_ = GenerateChildProcessUniqueId(); |
| 130 else | 169 else |
| 131 id_ = id; | 170 id_ = id; |
| 132 } | 171 } |
| 133 | 172 |
| 134 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { | 173 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { |
| 135 // Note: the string must start with the current process id, this is how | 174 // Note: the string must start with the current process id, this is how |
| 136 // child processes determine the pid of the parent. | 175 // child processes determine the pid of the parent. |
| 137 // Build the channel ID. This is composed of a unique identifier for the | 176 // Build the channel ID. This is composed of a unique identifier for the |
| 138 // parent browser process, an identifier for the child instance, and a random | 177 // parent browser process, an identifier for the child instance, and a random |
| 139 // component. We use a random component so that a hacked child process can't | 178 // component. We use a random component so that a hacked child process can't |
| 140 // cause denial of service by causing future named pipe creation to fail. | 179 // cause denial of service by causing future named pipe creation to fail. |
| 141 return base::StringPrintf("%d.%p.%d", | 180 return base::StringPrintf("%d.%p.%d", |
| 142 base::GetCurrentProcId(), instance, | 181 base::GetCurrentProcId(), instance, |
| 143 base::RandInt(0, std::numeric_limits<int>::max())); | 182 base::RandInt(0, std::numeric_limits<int>::max())); |
| 144 } | 183 } |
| 145 | 184 |
| 146 // static | 185 // static |
| 147 int ChildProcessInfo::GenerateChildProcessUniqueId() { | 186 int ChildProcessInfo::GenerateChildProcessUniqueId() { |
| 148 // This function must be threadsafe. | 187 // This function must be threadsafe. |
| 149 static base::subtle::Atomic32 last_unique_child_id = 0; | 188 static base::subtle::Atomic32 last_unique_child_id = 0; |
| 150 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); | 189 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); |
| 151 } | 190 } |
| OLD | NEW |