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

Side by Side Diff: content/browser/browser_child_process_host.h

Issue 8774040: Don't make classes derive from ChildProcessHost, and instead have them use it through composition... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix linker errors on posix Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ 5 #ifndef CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_
6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ 6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_
7 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 10
11 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/process.h" 13 #include "base/process.h"
13 #include "base/synchronization/waitable_event_watcher.h" 14 #include "base/synchronization/waitable_event_watcher.h"
14 #include "content/browser/child_process_launcher.h" 15 #include "content/browser/child_process_launcher.h"
15 #include "content/common/child_process_host.h"
16 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 #include "content/public/browser/child_process_data.h" 17 #include "content/public/browser/child_process_data.h"
18 #include "content/public/common/child_process_host_delegate.h"
19 #include "ipc/ipc_message.h"
20
21 class ChildProcessHost;
18 22
19 namespace base { 23 namespace base {
20 class WaitableEvent; 24 class WaitableEvent;
21 } 25 }
22 26
23 // Plugins/workers and other child processes that live on the IO thread should 27 // Plugins/workers and other child processes that live on the IO thread should
24 // derive from this class. 28 // derive from this class.
25 // 29 //
26 // [Browser]RenderProcessHost is the main exception that doesn't derive from 30 // [Browser]RenderProcessHost is the main exception that doesn't derive from
27 // this class. That project lives on the UI thread. 31 // this class. That project lives on the UI thread.
28 class CONTENT_EXPORT BrowserChildProcessHost : 32 class CONTENT_EXPORT BrowserChildProcessHost :
29 public ChildProcessHost, 33 public content::ChildProcessHostDelegate,
30 public ChildProcessLauncher::Client, 34 public ChildProcessLauncher::Client,
31 public base::WaitableEventWatcher::Delegate { 35 public base::WaitableEventWatcher::Delegate,
36 public IPC::Message::Sender {
32 public: 37 public:
33 virtual ~BrowserChildProcessHost(); 38 virtual ~BrowserChildProcessHost();
34 39
35 virtual void OnWaitableEventSignaled( 40 virtual void OnWaitableEventSignaled(
36 base::WaitableEvent* waitable_event) OVERRIDE; 41 base::WaitableEvent* waitable_event) OVERRIDE;
37 42
38 // Terminates all child processes and deletes each ChildProcessHost instance. 43 // Terminates all child processes and deletes each ChildProcessHost instance.
39 static void TerminateAll(); 44 static void TerminateAll();
40 45
41 // The Iterator class allows iteration through either all child processes, or 46 // The Iterator class allows iteration through either all child processes, or
42 // ones of a specific type, depending on which constructor is used. Note that 47 // ones of a specific type, depending on which constructor is used. Note that
43 // this should be done from the IO thread and that the iterator should not be 48 // this should be done from the IO thread and that the iterator should not be
44 // kept around as it may be invalidated on subsequent event processing in the 49 // kept around as it may be invalidated on subsequent event processing in the
45 // event loop. 50 // event loop.
46 class CONTENT_EXPORT Iterator { 51 class CONTENT_EXPORT Iterator {
47 public: 52 public:
48 Iterator(); 53 Iterator();
49 explicit Iterator(content::ProcessType type); 54 explicit Iterator(content::ProcessType type);
50 BrowserChildProcessHost* operator->() { return *iterator_; } 55 BrowserChildProcessHost* operator->() { return *iterator_; }
51 BrowserChildProcessHost* operator*() { return *iterator_; } 56 BrowserChildProcessHost* operator*() { return *iterator_; }
52 BrowserChildProcessHost* operator++(); 57 BrowserChildProcessHost* operator++();
53 bool Done(); 58 bool Done();
54 59
55 private: 60 private:
56 bool all_; 61 bool all_;
57 content::ProcessType type_; 62 content::ProcessType type_;
58 std::list<BrowserChildProcessHost*>::iterator iterator_; 63 std::list<BrowserChildProcessHost*>::iterator iterator_;
59 }; 64 };
60 65
66 // IPC::Message::Sender override
67 virtual bool Send(IPC::Message* message) OVERRIDE;
68
61 const content::ChildProcessData& data() const { return data_; } 69 const content::ChildProcessData& data() const { return data_; }
62 content::ProcessType type() const { return data_.type; } 70 content::ProcessType type() const { return data_.type; }
63 const string16& name() const { return data_.name; } 71 const string16& name() const { return data_.name; }
64 base::ProcessHandle handle() const { return data_.handle; } 72 base::ProcessHandle handle() const { return data_.handle; }
65 int id() const { return data_.id; } 73 int id() const { return data_.id; }
66 74
67 protected: 75 protected:
68 explicit BrowserChildProcessHost(content::ProcessType type); 76 explicit BrowserChildProcessHost(content::ProcessType type);
69 77
70 // Derived classes call this to launch the child process asynchronously. 78 // Derived classes call this to launch the child process asynchronously.
(...skipping 24 matching lines...) Expand all
95 // was killed (for posix, as returned from waitpid(), for Windows, 103 // was killed (for posix, as returned from waitpid(), for Windows,
96 // as returned from GetExitCodeProcess()). 104 // as returned from GetExitCodeProcess()).
97 virtual void OnProcessWasKilled(int exit_code) {} 105 virtual void OnProcessWasKilled(int exit_code) {}
98 106
99 // Returns the termination status of a child. |exit_code| is the 107 // Returns the termination status of a child. |exit_code| is the
100 // status returned when the process exited (for posix, as returned 108 // status returned when the process exited (for posix, as returned
101 // from waitpid(), for Windows, as returned from 109 // from waitpid(), for Windows, as returned from
102 // GetExitCodeProcess()). |exit_code| may be NULL. 110 // GetExitCodeProcess()). |exit_code| may be NULL.
103 virtual base::TerminationStatus GetChildTerminationStatus(int* exit_code); 111 virtual base::TerminationStatus GetChildTerminationStatus(int* exit_code);
104 112
105 // Overrides from ChildProcessHost 113 // ChildProcessHostDelegate implementation:
106 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; 114 virtual bool CanShutdown() OVERRIDE;
107 virtual void OnChildDisconnected() OVERRIDE; 115 virtual void OnChildDisconnected() OVERRIDE;
108 virtual void ShutdownStarted() OVERRIDE; 116 virtual void ShutdownStarted() OVERRIDE;
109 // Extends the base class implementation and removes this host from 117 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
110 // the host list. Calls ChildProcessHost::ForceShutdown 118 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
111 virtual void ForceShutdown() OVERRIDE; 119
120 // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown
121 void ForceShutdown();
112 122
113 // Controls whether the child process should be terminated on browser 123 // Controls whether the child process should be terminated on browser
114 // shutdown. Default is to always terminate. 124 // shutdown. Default is to always terminate.
115 void SetTerminateChildOnShutdown(bool terminate_on_shutdown); 125 void SetTerminateChildOnShutdown(bool terminate_on_shutdown);
116 126
117 // Sends the given notification on the UI thread. 127 // Sends the given notification on the UI thread.
118 void Notify(int type); 128 void Notify(int type);
119 129
130 ChildProcessHost* child_process_host() const {
131 return child_process_host_.get();
132 }
120 void set_name(const string16& name) { data_.name = name; } 133 void set_name(const string16& name) { data_.name = name; }
121 void set_handle(base::ProcessHandle handle) { data_.handle = handle; } 134 void set_handle(base::ProcessHandle handle) { data_.handle = handle; }
122 135
123 private: 136 private:
124 // By using an internal class as the ChildProcessLauncher::Client, we can 137 // By using an internal class as the ChildProcessLauncher::Client, we can
125 // intercept OnProcessLaunched and do our own processing before 138 // intercept OnProcessLaunched and do our own processing before
126 // calling the subclass' implementation. 139 // calling the subclass' implementation.
127 class ClientHook : public ChildProcessLauncher::Client { 140 class ClientHook : public ChildProcessLauncher::Client {
128 public: 141 public:
129 explicit ClientHook(BrowserChildProcessHost* host); 142 explicit ClientHook(BrowserChildProcessHost* host);
130 virtual void OnProcessLaunched() OVERRIDE; 143 virtual void OnProcessLaunched() OVERRIDE;
131 private: 144 private:
132 BrowserChildProcessHost* host_; 145 BrowserChildProcessHost* host_;
133 }; 146 };
134 147
135 content::ChildProcessData data_; 148 content::ChildProcessData data_;
149 scoped_ptr<ChildProcessHost> child_process_host_;
136 150
137 ClientHook client_; 151 ClientHook client_;
138 scoped_ptr<ChildProcessLauncher> child_process_; 152 scoped_ptr<ChildProcessLauncher> child_process_;
139 #if defined(OS_WIN) 153 #if defined(OS_WIN)
140 base::WaitableEventWatcher child_watcher_; 154 base::WaitableEventWatcher child_watcher_;
141 #else 155 #else
142 base::WeakPtrFactory<BrowserChildProcessHost> task_factory_; 156 base::WeakPtrFactory<BrowserChildProcessHost> task_factory_;
143 #endif 157 #endif
144 bool disconnect_was_alive_; 158 bool disconnect_was_alive_;
145 }; 159 };
146 160
147 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ 161 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_
OLDNEW
« no previous file with comments | « chrome/service/service_utility_process_host.cc ('k') | content/browser/browser_child_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698