Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/common/child_process_info.cc

Issue 6612040: Move ChildProcessHost and ChildProcessInfo to content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/child_process_info.h ('k') | chrome/common/debug_flags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/common/child_process_info.h"
6
7 #include <limits>
8
9 #include "base/atomicops.h"
10 #include "base/i18n/rtl.h"
11 #include "base/logging.h"
12 #include "base/process_util.h"
13 #include "base/rand_util.h"
14 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h"
16 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util.h"
18
19 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) :
20 type_(type),
21 renderer_type_(RENDERER_UNKNOWN) {
22 if (id == -1)
23 id_ = GenerateChildProcessUniqueId();
24 else
25 id_ = id;
26 }
27
28 ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original)
29 : type_(original.type_),
30 renderer_type_(original.renderer_type_),
31 name_(original.name_),
32 version_(original.version_),
33 id_(original.id_),
34 process_(original.process_) {
35 }
36
37 ChildProcessInfo::~ChildProcessInfo() {
38 }
39
40 ChildProcessInfo& ChildProcessInfo::operator=(
41 const ChildProcessInfo& original) {
42 if (&original != this) {
43 type_ = original.type_;
44 renderer_type_ = original.renderer_type_;
45 name_ = original.name_;
46 version_ = original.version_;
47 id_ = original.id_;
48 process_ = original.process_;
49 }
50 return *this;
51 }
52
53 // static
54 std::string ChildProcessInfo::GetTypeNameInEnglish(
55 ChildProcessInfo::ProcessType type) {
56 switch (type) {
57 case BROWSER_PROCESS:
58 return "Browser";
59 case RENDER_PROCESS:
60 return "Tab";
61 case PLUGIN_PROCESS:
62 return "Plug-in";
63 case WORKER_PROCESS:
64 return "Web Worker";
65 case UTILITY_PROCESS:
66 return "Utility";
67 case PROFILE_IMPORT_PROCESS:
68 return "Profile Import helper";
69 case ZYGOTE_PROCESS:
70 return "Zygote";
71 case SANDBOX_HELPER_PROCESS:
72 return "Sandbox helper";
73 case NACL_LOADER_PROCESS:
74 return "Native Client module";
75 case NACL_BROKER_PROCESS:
76 return "Native Client broker";
77 case GPU_PROCESS:
78 return "GPU";
79 case PPAPI_PLUGIN_PROCESS:
80 return "Pepper Plugin";
81 case UNKNOWN_PROCESS:
82 default:
83 DCHECK(false) << "Unknown child process type!";
84 return "Unknown";
85 }
86 }
87
88 // static
89 std::string ChildProcessInfo::GetRendererTypeNameInEnglish(
90 ChildProcessInfo::RendererProcessType type) {
91 switch (type) {
92 case RENDERER_NORMAL:
93 return "Tab";
94 case RENDERER_CHROME:
95 return "Tab (Chrome)";
96 case RENDERER_EXTENSION:
97 return "Extension";
98 case RENDERER_DEVTOOLS:
99 return "Devtools";
100 case RENDERER_INTERSTITIAL:
101 return "Interstitial";
102 case RENDERER_NOTIFICATION:
103 return "Notification";
104 case RENDERER_BACKGROUND_APP:
105 return "Background App";
106 case RENDERER_UNKNOWN:
107 default:
108 NOTREACHED() << "Unknown renderer process type!";
109 return "Unknown";
110 }
111 }
112
113 // static
114 std::string ChildProcessInfo::GetFullTypeNameInEnglish(
115 ChildProcessInfo::ProcessType type,
116 ChildProcessInfo::RendererProcessType rtype) {
117 if (type == RENDER_PROCESS)
118 return GetRendererTypeNameInEnglish(rtype);
119 return GetTypeNameInEnglish(type);
120 }
121
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) {
175 // Note: the string must start with the current process id, this is how
176 // child processes determine the pid of the parent.
177 // 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
179 // 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.
181 return base::StringPrintf("%d.%p.%d",
182 base::GetCurrentProcId(), instance,
183 base::RandInt(0, std::numeric_limits<int>::max()));
184 }
185
186 // static
187 int ChildProcessInfo::GenerateChildProcessUniqueId() {
188 // This function must be threadsafe.
189 static base::subtle::Atomic32 last_unique_child_id = 0;
190 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1);
191 }
OLDNEW
« no previous file with comments | « chrome/common/child_process_info.h ('k') | chrome/common/debug_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698