|
1 // Copyright (c) 2009 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/logging.h" |
|
10 #include "base/process_util.h" |
|
11 #include "base/rand_util.h" |
|
12 #include "base/string_util.h" |
|
13 |
|
14 std::wstring ChildProcessInfo::GetTypeNameInEnglish( |
|
15 ChildProcessInfo::ProcessType type) { |
|
16 switch (type) { |
|
17 case BROWSER_PROCESS: |
|
18 return L"Browser"; |
|
19 case RENDER_PROCESS: |
|
20 return L"Tab"; |
|
21 case PLUGIN_PROCESS: |
|
22 return L"Plug-in"; |
|
23 case WORKER_PROCESS: |
|
24 return L"Web Worker"; |
|
25 case UNKNOWN_PROCESS: |
|
26 default: |
|
27 DCHECK(false) << "Unknown child process type!"; |
|
28 return L"Unknown"; |
|
29 } |
|
30 } |
|
31 |
|
32 std::wstring ChildProcessInfo::GetLocalizedTitle() const { |
|
33 return name_; |
|
34 } |
|
35 |
|
36 ChildProcessInfo::ChildProcessInfo(ProcessType type) { |
|
37 // This constructor is only used by objects which derive from this class, |
|
38 // which means *this* is a real object that refers to a child process, and not |
|
39 // just a simple object that contains information about it. So add it to our |
|
40 // list of running processes. |
|
41 type_ = type; |
|
42 pid_ = -1; |
|
43 } |
|
44 |
|
45 |
|
46 ChildProcessInfo::~ChildProcessInfo() { |
|
47 } |
|
48 |
|
49 std::wstring ChildProcessInfo::GenerateRandomChannelID(void* instance) { |
|
50 // Note: the string must start with the current process id, this is how |
|
51 // child processes determine the pid of the parent. |
|
52 // Build the channel ID. This is composed of a unique identifier for the |
|
53 // parent browser process, an identifier for the child instance, and a random |
|
54 // component. We use a random component so that a hacked child process can't |
|
55 // cause denial of service by causing future named pipe creation to fail. |
|
56 return StringPrintf(L"%d.%x.%d", |
|
57 base::GetCurrentProcId(), instance, |
|
58 base::RandInt(0, std::numeric_limits<int>::max())); |
|
59 } |