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 0 : 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 0 : base::ProcessHandle handle() const { return process_.handle(); }
32 :
33 0 : virtual int GetProcessId() const {
34 0 : if (pid_ != -1)
35 0 : return pid_;
36 :
37 0 : pid_ = process_.pid();
38 0 : return pid_;
39 : }
40 : void SetProcessBackgrounded() const { process_.SetProcessBackgrounded(true); }
41 : void ReduceWorkingSet() const { process_.ReduceWorkingSet(); }
42 :
43 : // Returns an English name of the process type, should only be used for non
44 : // user-visible strings, or debugging pages like about:memory.
45 : static std::wstring GetTypeNameInEnglish(ProcessType type);
46 :
47 : // Returns a localized title for the child process. For example, a plugin
48 : // process would be "Plug-in: Flash" when name is "Flash".
49 : std::wstring GetLocalizedTitle() const;
50 :
51 0 : ChildProcessInfo(const ChildProcessInfo& original) {
52 0 : type_ = original.type_;
53 0 : name_ = original.name_;
54 0 : process_ = original.process_;
55 0 : pid_ = original.pid_;
56 0 : }
57 :
58 : ChildProcessInfo& operator=(const ChildProcessInfo& original) {
59 : if (&original != this) {
60 : type_ = original.type_;
61 : name_ = original.name_;
62 : process_ = original.process_;
63 : pid_ = original.pid_;
64 : }
65 : return *this;
66 : }
67 :
68 : virtual ~ChildProcessInfo();
69 :
70 : // We define the < operator so that the ChildProcessInfo can be used as a key
71 : // in a std::map.
72 : bool operator <(const ChildProcessInfo& rhs) const {
73 : if (process_.handle() != rhs.process_.handle())
74 : return process_ .handle() < rhs.process_.handle();
75 : return false;
76 : }
77 :
78 : bool operator ==(const ChildProcessInfo& rhs) const {
79 : return process_.handle() == rhs.process_.handle();
80 : }
81 :
82 : // Generates a unique channel name for a child renderer/plugin process.
83 : // The "instance" pointer value is baked into the channel id.
84 : static std::wstring GenerateRandomChannelID(void* instance);
85 :
86 : protected:
87 : void set_type(ProcessType type) { type_ = type; }
88 : void set_name(const std::wstring& name) { name_ = name; }
89 : void set_handle(base::ProcessHandle handle) {
90 : process_.set_handle(handle);
91 : pid_ = -1;
92 : }
93 :
94 : // Derived objects need to use this constructor so we know what type we are.
95 : ChildProcessInfo(ProcessType type);
96 :
97 : private:
98 : ProcessType type_;
99 : std::wstring name_;
100 : mutable int pid_; // Cache of the process id.
101 :
102 : // The handle to the process.
103 : mutable base::Process process_;
104 : };
105 :
106 : #endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_
|