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/ipc_sync_channel.h" | 10 #include "chrome/common/ipc_sync_channel.h" |
11 #include "chrome/common/message_router.h" | 11 #include "chrome/common/message_router.h" |
12 #include "chrome/common/resource_dispatcher.h" | 12 #include "chrome/common/resource_dispatcher.h" |
13 | 13 |
14 class NotificationService; | 14 class NotificationService; |
15 | 15 |
16 // The main thread of a child process derives from this class. | 16 // The main thread of a child process derives from this class. |
17 class ChildThread : public IPC::Channel::Listener, | 17 class ChildThread : public IPC::Channel::Listener, |
18 public IPC::Message::Sender { | 18 public IPC::Message::Sender { |
19 public: | 19 public: |
20 // Creates the thread. | 20 // Creates the thread. |
21 ChildThread(); | 21 ChildThread(); |
| 22 // Used for single-process mode. |
| 23 ChildThread(const std::string channel_name); |
22 virtual ~ChildThread(); | 24 virtual ~ChildThread(); |
23 | 25 |
24 // IPC::Message::Sender implementation: | 26 // IPC::Message::Sender implementation: |
25 virtual bool Send(IPC::Message* msg); | 27 virtual bool Send(IPC::Message* msg); |
26 | 28 |
27 // See documentation on MessageRouter for AddRoute and RemoveRoute | 29 // See documentation on MessageRouter for AddRoute and RemoveRoute |
28 void AddRoute(int32 routing_id, IPC::Channel::Listener* listener); | 30 void AddRoute(int32 routing_id, IPC::Channel::Listener* listener); |
29 void RemoveRoute(int32 routing_id); | 31 void RemoveRoute(int32 routing_id); |
30 | 32 |
31 ResourceDispatcher* resource_dispatcher() { | 33 ResourceDispatcher* resource_dispatcher() { |
32 return resource_dispatcher_.get(); | 34 return resource_dispatcher_.get(); |
33 } | 35 } |
34 | 36 |
35 MessageLoop* message_loop() { return message_loop_; } | 37 MessageLoop* message_loop() { return message_loop_; } |
36 | 38 |
37 // Returns the one child thread. | 39 // Returns the one child thread. |
38 static ChildThread* current(); | 40 static ChildThread* current(); |
39 | 41 |
40 protected: | 42 protected: |
41 friend class ChildProcess; | 43 friend class ChildProcess; |
42 | 44 |
43 // Overrides the channel name. Used for --single-process mode. | |
44 void SetChannelName(const std::string& name) { channel_name_ = name; } | |
45 | |
46 // Called when the process refcount is 0. | 45 // Called when the process refcount is 0. |
47 void OnProcessFinalRelease(); | 46 void OnProcessFinalRelease(); |
48 | 47 |
49 virtual void OnControlMessageReceived(const IPC::Message& msg) { } | 48 virtual void OnControlMessageReceived(const IPC::Message& msg) { } |
50 | 49 |
51 IPC::SyncChannel* channel() { return channel_.get(); } | 50 IPC::SyncChannel* channel() { return channel_.get(); } |
52 | 51 |
53 private: | 52 private: |
| 53 void Init(); |
| 54 |
54 // IPC::Channel::Listener implementation: | 55 // IPC::Channel::Listener implementation: |
55 virtual void OnMessageReceived(const IPC::Message& msg); | 56 virtual void OnMessageReceived(const IPC::Message& msg); |
56 virtual void OnChannelError(); | 57 virtual void OnChannelError(); |
57 | 58 |
58 std::string channel_name_; | 59 std::string channel_name_; |
59 scoped_ptr<IPC::SyncChannel> channel_; | 60 scoped_ptr<IPC::SyncChannel> channel_; |
60 | 61 |
61 // Implements message routing functionality to the consumers of ChildThread. | 62 // Implements message routing functionality to the consumers of ChildThread. |
62 MessageRouter router_; | 63 MessageRouter router_; |
63 | 64 |
64 // Handles resource loads for this process. | 65 // Handles resource loads for this process. |
65 scoped_ptr<ResourceDispatcher> resource_dispatcher_; | 66 scoped_ptr<ResourceDispatcher> resource_dispatcher_; |
66 | 67 |
67 // If true, checks with the browser process before shutdown. This avoids race | 68 // If true, checks with the browser process before shutdown. This avoids race |
68 // conditions if the process refcount is 0 but there's an IPC message inflight | 69 // conditions if the process refcount is 0 but there's an IPC message inflight |
69 // that would addref it. | 70 // that would addref it. |
70 bool check_with_browser_before_shutdown_; | 71 bool check_with_browser_before_shutdown_; |
71 | 72 |
72 MessageLoop* message_loop_; | 73 MessageLoop* message_loop_; |
73 | 74 |
74 scoped_ptr<NotificationService> notification_service_; | 75 scoped_ptr<NotificationService> notification_service_; |
75 | 76 |
76 DISALLOW_COPY_AND_ASSIGN(ChildThread); | 77 DISALLOW_COPY_AND_ASSIGN(ChildThread); |
77 }; | 78 }; |
78 | 79 |
79 #endif // CHROME_COMMON_CHILD_THREAD_H_ | 80 #endif // CHROME_COMMON_CHILD_THREAD_H_ |
OLD | NEW |