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_UNKNOWN: | |
90 default: | |
91 NOTREACHED() << "Unknown renderer process type!"; | |
92 return "Unknown"; | |
93 } | |
94 } | |
95 | |
96 // static | |
97 std::string ChildProcessInfo::GetFullTypeNameInEnglish( | |
98 ChildProcessInfo::ProcessType type, | |
99 ChildProcessInfo::RendererProcessType rtype) { | |
100 if (type == RENDER_PROCESS) | |
101 return GetRendererTypeNameInEnglish(rtype); | |
102 return GetTypeNameInEnglish(type); | |
103 } | |
104 | |
105 | |
76 string16 ChildProcessInfo::GetLocalizedTitle() const { | 106 string16 ChildProcessInfo::GetLocalizedTitle() const { |
77 string16 title = WideToUTF16Hack(name_); | 107 string16 title = WideToUTF16Hack(name_); |
78 if (type_ == ChildProcessInfo::PLUGIN_PROCESS && title.empty()) | 108 if (type_ == ChildProcessInfo::PLUGIN_PROCESS && title.empty()) |
79 title = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME); | 109 title = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME); |
80 | 110 |
81 // Explicitly mark name as LTR if there is no strong RTL character, | 111 // Explicitly mark name as LTR if there is no strong RTL character, |
82 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the | 112 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the |
83 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew | 113 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew |
84 // or Arabic word for "plugin". | 114 // or Arabic word for "plugin". |
85 base::i18n::AdjustStringForLocaleDirection(&title); | 115 base::i18n::AdjustStringForLocaleDirection(&title); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 break; | 148 break; |
119 | 149 |
120 case UNKNOWN_PROCESS: | 150 case UNKNOWN_PROCESS: |
121 NOTREACHED() << "Need localized name for child process type."; | 151 NOTREACHED() << "Need localized name for child process type."; |
122 } | 152 } |
123 | 153 |
124 return title; | 154 return title; |
125 } | 155 } |
126 | 156 |
127 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : type_(type) { | 157 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : type_(type) { |
158 renderer_type_ = RENDERER_UNKNOWN; | |
Mike Belshe
2010/12/24 00:50:53
Is it expected that type_ != RENDER_PROCESS if we
Erik does not do reviews
2010/12/28 16:59:18
This is the constructor, so it's expected to be un
| |
128 if (id == -1) | 159 if (id == -1) |
129 id_ = GenerateChildProcessUniqueId(); | 160 id_ = GenerateChildProcessUniqueId(); |
130 else | 161 else |
131 id_ = id; | 162 id_ = id; |
132 } | 163 } |
133 | 164 |
134 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { | 165 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { |
135 // Note: the string must start with the current process id, this is how | 166 // Note: the string must start with the current process id, this is how |
136 // child processes determine the pid of the parent. | 167 // child processes determine the pid of the parent. |
137 // Build the channel ID. This is composed of a unique identifier for the | 168 // 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 | 169 // 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 | 170 // 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. | 171 // cause denial of service by causing future named pipe creation to fail. |
141 return base::StringPrintf("%d.%p.%d", | 172 return base::StringPrintf("%d.%p.%d", |
142 base::GetCurrentProcId(), instance, | 173 base::GetCurrentProcId(), instance, |
143 base::RandInt(0, std::numeric_limits<int>::max())); | 174 base::RandInt(0, std::numeric_limits<int>::max())); |
144 } | 175 } |
145 | 176 |
146 // static | 177 // static |
147 int ChildProcessInfo::GenerateChildProcessUniqueId() { | 178 int ChildProcessInfo::GenerateChildProcessUniqueId() { |
148 // This function must be threadsafe. | 179 // This function must be threadsafe. |
149 static base::subtle::Atomic32 last_unique_child_id = 0; | 180 static base::subtle::Atomic32 last_unique_child_id = 0; |
150 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); | 181 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); |
151 } | 182 } |
OLD | NEW |