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

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

Issue 24017: More refactoring of PluginProcessHost (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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/browser/task_manager_resource_providers.cc ('k') | chrome/common/child_process_info.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_ 5 #ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_
6 #define CHROME_COMMON_CHILD_PROCESS_INFO_H_ 6 #define CHROME_COMMON_CHILD_PROCESS_INFO_H_
7 7
8 #include <list>
8 #include <string> 9 #include <string>
10
9 #include "base/basictypes.h" 11 #include "base/basictypes.h"
10 #include "base/process.h" 12 #include "base/process.h"
11 13
12 // Holds information about a child process. 14 class ChildProcessInfo;
15
16 // Holds information about a child process. Plugins/workers and other child
17 // processes that live on the IO thread derive from this.
13 class ChildProcessInfo { 18 class ChildProcessInfo {
14 public: 19 public:
15 enum ProcessType { 20 enum ProcessType {
16 BROWSER_PROCESS, 21 BROWSER_PROCESS,
17 RENDER_PROCESS, 22 RENDER_PROCESS,
18 PLUGIN_PROCESS, 23 PLUGIN_PROCESS,
19 WORKER_PROCESS, 24 WORKER_PROCESS,
20 UNKNOWN_PROCESS, 25 UNKNOWN_PROCESS,
21 }; 26 };
22 27
23 // Returns the type of the process. 28 // Returns the type of the process.
24 ProcessType type() const { return type_; } 29 ProcessType type() const { return type_; }
25 30
26 // Returns the name of the process. i.e. for plugins it might be Flash, while 31 // 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. 32 // for workers it might be the domain that it's from.
28 std::wstring name() const { return name_; } 33 std::wstring name() const { return name_; }
29 34
30 // Getter to the process. 35 // Getter to the process.
31 base::Process& process() { return process_; } 36 base::Process& process() { return process_; }
32 37
33 // Returns an English name of the process type, should only be used for non 38 // Returns an English name of the process type, should only be used for non
34 // user-visible strings, or debugging pages like about:memory. 39 // user-visible strings, or debugging pages like about:memory.
35 static std::wstring GetTypeNameInEnglish(ProcessType type); 40 static std::wstring GetTypeNameInEnglish(ProcessType type);
36 41
37 // Returns a localized title for the child process. For example, a plugin 42 // Returns a localized title for the child process. For example, a plugin
38 // process would be "Plug-in: Flash" when name is "Flash". 43 // process would be "Plug-in: Flash" when name is "Flash".
39 std::wstring GetLocalizedTitle() const; 44 std::wstring GetLocalizedTitle() const;
40 45
46 ChildProcessInfo(const ChildProcessInfo& original) {
47 type_ = original.type_;
48 name_ = original.name_;
49 process_ = original.process_;
50 }
51
52 ChildProcessInfo& operator=(const ChildProcessInfo& original) {
53 if (&original != this) {
54 type_ = original.type_;
55 name_ = original.name_;
56 process_ = original.process_;
57 }
58 return *this;
59 }
60
61 ~ChildProcessInfo();
62
41 // We define the < operator so that the ChildProcessInfo can be used as a key 63 // We define the < operator so that the ChildProcessInfo can be used as a key
42 // in a std::map. 64 // in a std::map.
43 bool operator <(const ChildProcessInfo& rhs) const { 65 bool operator <(const ChildProcessInfo& rhs) const {
44 if (process_.handle() != rhs.process_.handle()) 66 if (process_.handle() != rhs.process_.handle())
45 return process_ .handle() < rhs.process_.handle(); 67 return process_ .handle() < rhs.process_.handle();
46 return name_ < rhs.name_; 68 return name_ < rhs.name_;
47 } 69 }
48 70
49 bool operator ==(const ChildProcessInfo& rhs) const { 71 bool operator ==(const ChildProcessInfo& rhs) const {
50 return (process_.handle() == rhs.process_.handle()) && (name_ == rhs.name_); 72 return (process_.handle() == rhs.process_.handle()) && (name_ == rhs.name_);
51 } 73 }
52 74
75 // The Iterator class allows iteration through either all child processes, or
76 // ones of a specific type, depending on which constructor is used. Note that
77 // this should be done from the IO thread and that the iterator should not be
78 // kept around as it may be invalidated on subsequent event processing in the
79 // event loop.
80 class Iterator {
81 public:
82 Iterator();
83 Iterator(ProcessType type);
84 ChildProcessInfo* operator->() { return *iterator_; }
85 ChildProcessInfo* operator*() { return *iterator_; }
86 ChildProcessInfo* operator++();
87 bool Done();
88
89 private:
90 bool all_;
91 ProcessType type_;
92 std::list<ChildProcessInfo*>::iterator iterator_;
93 };
94
53 protected: 95 protected:
54 void set_type(ProcessType type) { type_ = type; } 96 void set_type(ProcessType type) { type_ = type; }
55 void set_name(const std::wstring& name) { name_ = name; } 97 void set_name(const std::wstring& name) { name_ = name; }
56 98
99 // Derived objects need to use this constructor so we know what type we are.
100 ChildProcessInfo(ProcessType type);
101
57 private: 102 private:
103 // By making the constructor private, we can ensure that ChildProcessInfo
104 // objects can only be created by creating objects derived from them (i.e.
105 // PluginProcessHost) or by using the copy constructor or assignment operator
106 // to create an object from the former.
107 ChildProcessInfo() { }
108
58 ProcessType type_; 109 ProcessType type_;
59 std::wstring name_; 110 std::wstring name_;
60 111
61 // The handle to the process. 112 // The handle to the process.
62 base::Process process_; 113 base::Process process_;
63 }; 114 };
64 115
65 #endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_ 116 #endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_
66
OLDNEW
« no previous file with comments | « chrome/browser/task_manager_resource_providers.cc ('k') | chrome/common/child_process_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698