| OLD | NEW |
| 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_HOST_H_ | 5 #ifndef CHROME_COMMON_CHILD_PROCESS_HOST_H_ |
| 6 #define CHROME_COMMON_CHILD_PROCESS_HOST_H_ | 6 #define CHROME_COMMON_CHILD_PROCESS_HOST_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/waitable_event_watcher.h" | |
| 14 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 13 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 15 #include "chrome/common/ipc_channel.h" | 14 #include "chrome/common/ipc_channel.h" |
| 16 | 15 |
| 17 class NotificationType; | 16 class NotificationType; |
| 18 | 17 |
| 19 // Plugins/workers and other child processes that live on the IO thread should | 18 // Plugins/workers and other child processes that live on the IO thread should |
| 20 // derive from this class. | 19 // derive from this class. |
| 21 class ChildProcessHost : public ResourceDispatcherHost::Receiver, | 20 class ChildProcessHost : public ResourceDispatcherHost::Receiver, |
| 22 public base::WaitableEventWatcher::Delegate, | |
| 23 public IPC::Channel::Listener { | 21 public IPC::Channel::Listener { |
| 24 public: | 22 public: |
| 25 virtual ~ChildProcessHost(); | 23 virtual ~ChildProcessHost(); |
| 26 | 24 |
| 27 // ResourceDispatcherHost::Receiver implementation: | 25 // ResourceDispatcherHost::Receiver implementation: |
| 28 virtual bool Send(IPC::Message* msg); | 26 virtual bool Send(IPC::Message* msg); |
| 29 | 27 |
| 30 // The Iterator class allows iteration through either all child processes, or | 28 // The Iterator class allows iteration through either all child processes, or |
| 31 // ones of a specific type, depending on which constructor is used. Note that | 29 // ones of a specific type, depending on which constructor is used. Note that |
| 32 // this should be done from the IO thread and that the iterator should not be | 30 // this should be done from the IO thread and that the iterator should not be |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 69 |
| 72 bool opening_channel() { return opening_channel_; } | 70 bool opening_channel() { return opening_channel_; } |
| 73 const std::string& channel_id() { return channel_id_; } | 71 const std::string& channel_id() { return channel_id_; } |
| 74 | 72 |
| 75 const IPC::Channel& channel() const { return *channel_; } | 73 const IPC::Channel& channel() const { return *channel_; } |
| 76 | 74 |
| 77 private: | 75 private: |
| 78 // Sends the given notification to the notification service on the UI thread. | 76 // Sends the given notification to the notification service on the UI thread. |
| 79 void Notify(NotificationType type); | 77 void Notify(NotificationType type); |
| 80 | 78 |
| 81 // WaitableEventWatcher::Delegate implementation: | 79 // Called when the child process goes away. |
| 82 virtual void OnWaitableEventSignaled(base::WaitableEvent *event); | 80 void OnChildDied(); |
| 83 | 81 |
| 84 // By using an internal class as the IPC::Channel::Listener, we can intercept | 82 // By using an internal class as the IPC::Channel::Listener, we can intercept |
| 85 // OnMessageReceived/OnChannelConnected and do our own processing before | 83 // OnMessageReceived/OnChannelConnected and do our own processing before |
| 86 // calling the subclass' implementation. | 84 // calling the subclass' implementation. |
| 87 class ListenerHook : public IPC::Channel::Listener { | 85 class ListenerHook : public IPC::Channel::Listener { |
| 88 public: | 86 public: |
| 89 ListenerHook(ChildProcessHost* host); | 87 ListenerHook(ChildProcessHost* host); |
| 90 virtual void OnMessageReceived(const IPC::Message& msg); | 88 virtual void OnMessageReceived(const IPC::Message& msg); |
| 91 virtual void OnChannelConnected(int32 peer_pid); | 89 virtual void OnChannelConnected(int32 peer_pid); |
| 92 virtual void OnChannelError(); | 90 virtual void OnChannelError(); |
| 93 private: | 91 private: |
| 94 ChildProcessHost* host_; | 92 ChildProcessHost* host_; |
| 95 }; | 93 }; |
| 96 | 94 |
| 97 ListenerHook listener_; | 95 ListenerHook listener_; |
| 98 | 96 |
| 99 ResourceDispatcherHost* resource_dispatcher_host_; | 97 ResourceDispatcherHost* resource_dispatcher_host_; |
| 100 | 98 |
| 101 // True while we're waiting the channel to be opened. | 99 // True while we're waiting the channel to be opened. |
| 102 bool opening_channel_; | 100 bool opening_channel_; |
| 103 | 101 |
| 104 // The IPC::Channel. | 102 // The IPC::Channel. |
| 105 scoped_ptr<IPC::Channel> channel_; | 103 scoped_ptr<IPC::Channel> channel_; |
| 106 | 104 |
| 107 // IPC Channel's id. | 105 // IPC Channel's id. |
| 108 std::string channel_id_; | 106 std::string channel_id_; |
| 109 | |
| 110 // Used to watch the child process handle. | |
| 111 base::WaitableEventWatcher watcher_; | |
| 112 | |
| 113 scoped_ptr<base::WaitableEvent> process_event_; | |
| 114 }; | 107 }; |
| 115 | 108 |
| 116 #endif // CHROME_COMMON_CHILD_PROCESS_HOST_H_ | 109 #endif // CHROME_COMMON_CHILD_PROCESS_HOST_H_ |
| OLD | NEW |