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_THREAD_H_ | 5 #ifndef CHROME_COMMON_CHILD_THREAD_H_ |
6 #define CHROME_COMMON_CHILD_THREAD_H_ | 6 #define CHROME_COMMON_CHILD_THREAD_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "chrome/common/message_router.h" | 10 #include "chrome/common/message_router.h" |
11 #include "chrome/common/resource_dispatcher.h" | 11 #include "chrome/common/resource_dispatcher.h" |
12 #include "ipc/ipc_sync_channel.h" | 12 #include "ipc/ipc_sync_channel.h" |
13 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
14 | 14 |
15 class NotificationService; | 15 class NotificationService; |
16 class SocketStreamDispatcher; | 16 class SocketStreamDispatcher; |
17 | 17 |
| 18 namespace IPC { |
| 19 class SyncMessageFilter; |
| 20 } |
| 21 |
18 // The main thread of a child process derives from this class. | 22 // The main thread of a child process derives from this class. |
19 class ChildThread : public IPC::Channel::Listener, | 23 class ChildThread : public IPC::Channel::Listener, |
20 public IPC::Message::Sender { | 24 public IPC::Message::Sender { |
21 public: | 25 public: |
22 // Creates the thread. | 26 // Creates the thread. |
23 ChildThread(); | 27 ChildThread(); |
24 // Used for single-process mode. | 28 // Used for single-process mode. |
25 explicit ChildThread(const std::string& channel_name); | 29 explicit ChildThread(const std::string& channel_name); |
26 virtual ~ChildThread(); | 30 virtual ~ChildThread(); |
27 | 31 |
(...skipping 14 matching lines...) Expand all Loading... |
42 int host_render_view_id); | 46 int host_render_view_id); |
43 | 47 |
44 ResourceDispatcher* resource_dispatcher() { | 48 ResourceDispatcher* resource_dispatcher() { |
45 return resource_dispatcher_.get(); | 49 return resource_dispatcher_.get(); |
46 } | 50 } |
47 | 51 |
48 SocketStreamDispatcher* socket_stream_dispatcher() { | 52 SocketStreamDispatcher* socket_stream_dispatcher() { |
49 return socket_stream_dispatcher_.get(); | 53 return socket_stream_dispatcher_.get(); |
50 } | 54 } |
51 | 55 |
| 56 // Safe to call on any thread, as long as it's guaranteed that the thread's |
| 57 // lifetime is less than the main thread. |
| 58 IPC::SyncMessageFilter* sync_message_filter() { return sync_message_filter_; } |
| 59 |
52 MessageLoop* message_loop() { return message_loop_; } | 60 MessageLoop* message_loop() { return message_loop_; } |
53 | 61 |
54 // Returns the one child thread. | 62 // Returns the one child thread. |
55 static ChildThread* current(); | 63 static ChildThread* current(); |
56 | 64 |
57 protected: | 65 protected: |
58 friend class ChildProcess; | 66 friend class ChildProcess; |
59 | 67 |
60 // Called when the process refcount is 0. | 68 // Called when the process refcount is 0. |
61 void OnProcessFinalRelease(); | 69 void OnProcessFinalRelease(); |
(...skipping 15 matching lines...) Expand all Loading... |
77 private: | 85 private: |
78 void Init(); | 86 void Init(); |
79 | 87 |
80 // IPC::Channel::Listener implementation: | 88 // IPC::Channel::Listener implementation: |
81 virtual void OnMessageReceived(const IPC::Message& msg); | 89 virtual void OnMessageReceived(const IPC::Message& msg); |
82 virtual void OnChannelError(); | 90 virtual void OnChannelError(); |
83 | 91 |
84 std::string channel_name_; | 92 std::string channel_name_; |
85 scoped_ptr<IPC::SyncChannel> channel_; | 93 scoped_ptr<IPC::SyncChannel> channel_; |
86 | 94 |
| 95 // Allows threads other than the main thread to send sync messages. |
| 96 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; |
| 97 |
87 // Implements message routing functionality to the consumers of ChildThread. | 98 // Implements message routing functionality to the consumers of ChildThread. |
88 MessageRouter router_; | 99 MessageRouter router_; |
89 | 100 |
90 // Handles resource loads for this process. | 101 // Handles resource loads for this process. |
91 scoped_ptr<ResourceDispatcher> resource_dispatcher_; | 102 scoped_ptr<ResourceDispatcher> resource_dispatcher_; |
92 | 103 |
93 // Handles SocketStream for this process. | 104 // Handles SocketStream for this process. |
94 scoped_ptr<SocketStreamDispatcher> socket_stream_dispatcher_; | 105 scoped_ptr<SocketStreamDispatcher> socket_stream_dispatcher_; |
95 | 106 |
96 // If true, checks with the browser process before shutdown. This avoids race | 107 // If true, checks with the browser process before shutdown. This avoids race |
97 // conditions if the process refcount is 0 but there's an IPC message inflight | 108 // conditions if the process refcount is 0 but there's an IPC message inflight |
98 // that would addref it. | 109 // that would addref it. |
99 bool check_with_browser_before_shutdown_; | 110 bool check_with_browser_before_shutdown_; |
100 | 111 |
101 // The OnChannelError() callback was invoked - the channel is dead, don't | 112 // The OnChannelError() callback was invoked - the channel is dead, don't |
102 // attempt to communicate. | 113 // attempt to communicate. |
103 bool on_channel_error_called_; | 114 bool on_channel_error_called_; |
104 | 115 |
105 MessageLoop* message_loop_; | 116 MessageLoop* message_loop_; |
106 | 117 |
107 scoped_ptr<NotificationService> notification_service_; | 118 scoped_ptr<NotificationService> notification_service_; |
108 | 119 |
109 DISALLOW_COPY_AND_ASSIGN(ChildThread); | 120 DISALLOW_COPY_AND_ASSIGN(ChildThread); |
110 }; | 121 }; |
111 | 122 |
112 #endif // CHROME_COMMON_CHILD_THREAD_H_ | 123 #endif // CHROME_COMMON_CHILD_THREAD_H_ |
OLD | NEW |