|
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 #ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_ |
|
6 #define CHROME_COMMON_CHILD_PROCESS_INFO_H_ |
|
7 |
|
8 #include <string> |
|
9 |
|
10 #include "base/process.h" |
|
11 |
|
12 // Holds information about a child process. |
|
13 class ChildProcessInfo { |
|
14 public: |
|
15 enum ProcessType { |
|
16 BROWSER_PROCESS, |
|
17 RENDER_PROCESS, |
|
18 PLUGIN_PROCESS, |
|
19 WORKER_PROCESS, |
|
20 UNKNOWN_PROCESS |
|
21 }; |
|
22 |
|
23 // Returns the type of the process. |
|
24 ProcessType type() const { return type_; } |
|
25 |
|
26 // Returns the name of the process. i.e. for plugins it might be Flash, while |
|
27 // for workers it might be the domain that it's from. |
|
28 std::wstring name() const { return name_; } |
|
29 |
|
30 // Getter to the process handle. |
|
31 base::ProcessHandle handle() const { return process_.handle(); } |
|
32 |
|
33 virtual int GetProcessId() const { |
|
34 if (pid_ != -1) |
|
35 return pid_; |
|
36 |
|
37 pid_ = process_.pid(); |
|
38 return pid_; |
|
39 } |
|
40 void SetProcessBackgrounded() const { process_.SetProcessBackgrounded(true); } |
|
41 |
|
42 // Returns an English name of the process type, should only be used for non |
|
43 // user-visible strings, or debugging pages like about:memory. |
|
44 static std::wstring GetTypeNameInEnglish(ProcessType type); |
|
45 |
|
46 // Returns a localized title for the child process. For example, a plugin |
|
47 // process would be "Plug-in: Flash" when name is "Flash". |
|
48 std::wstring GetLocalizedTitle() const; |
|
49 |
|
50 ChildProcessInfo(const ChildProcessInfo& original) { |
|
51 type_ = original.type_; |
|
52 name_ = original.name_; |
|
53 process_ = original.process_; |
|
54 pid_ = original.pid_; |
|
55 } |
|
56 |
|
57 ChildProcessInfo& operator=(const ChildProcessInfo& original) { |
|
58 if (&original != this) { |
|
59 type_ = original.type_; |
|
60 name_ = original.name_; |
|
61 process_ = original.process_; |
|
62 pid_ = original.pid_; |
|
63 } |
|
64 return *this; |
|
65 } |
|
66 |
|
67 virtual ~ChildProcessInfo(); |
|
68 |
|
69 // We define the < operator so that the ChildProcessInfo can be used as a key |
|
70 // in a std::map. |
|
71 bool operator <(const ChildProcessInfo& rhs) const { |
|
72 if (process_.handle() != rhs.process_.handle()) |
|
73 return process_ .handle() < rhs.process_.handle(); |
|
74 return false; |
|
75 } |
|
76 |
|
77 bool operator ==(const ChildProcessInfo& rhs) const { |
|
78 return process_.handle() == rhs.process_.handle(); |
|
79 } |
|
80 |
|
81 // Generates a unique channel name for a child renderer/plugin process. |
|
82 // The "instance" pointer value is baked into the channel id. |
|
83 static std::wstring GenerateRandomChannelID(void* instance); |
|
84 |
|
85 protected: |
|
86 void set_type(ProcessType type) { type_ = type; } |
|
87 void set_name(const std::wstring& name) { name_ = name; } |
|
88 void set_handle(base::ProcessHandle handle) { |
|
89 process_.set_handle(handle); |
|
90 pid_ = -1; |
|
91 } |
|
92 |
|
93 // Derived objects need to use this constructor so we know what type we are. |
|
94 ChildProcessInfo(ProcessType type); |
|
95 |
|
96 private: |
|
97 ProcessType type_; |
|
98 std::wstring name_; |
|
99 mutable int pid_; // Cache of the process id. |
|
100 |
|
101 // The handle to the process. |
|
102 mutable base::Process process_; |
|
103 }; |
|
104 |
|
105 #endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_ |