OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CHILD_CHILD_THREAD_H_ | 5 #ifndef CONTENT_CHILD_CHILD_THREAD_H_ |
6 #define CONTENT_CHILD_CHILD_THREAD_H_ | 6 #define CONTENT_CHILD_CHILD_THREAD_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/power_monitor/power_monitor.h" | 14 #include "base/power_monitor/power_monitor.h" |
15 #include "base/tracked_objects.h" | 15 #include "base/tracked_objects.h" |
16 #include "content/child/mojo/mojo_application.h" | 16 #include "content/child/mojo/mojo_application.h" |
17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
18 #include "content/common/message_router.h" | 18 #include "content/common/message_router.h" |
19 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. | 19 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 class MessageLoop; | 22 class MessageLoop; |
23 | 23 |
24 namespace debug { | 24 namespace debug { |
25 class TraceMemoryController; | 25 class TraceMemoryController; |
26 } // namespace debug | 26 } // namespace debug |
27 } // namespace base | 27 } // namespace base |
28 | 28 |
29 namespace IPC { | 29 namespace IPC { |
| 30 class MessageFilter; |
30 class SyncChannel; | 31 class SyncChannel; |
31 class SyncMessageFilter; | 32 class SyncMessageFilter; |
32 } // namespace IPC | 33 } // namespace IPC |
33 | 34 |
34 namespace blink { | 35 namespace blink { |
35 class WebFrame; | 36 class WebFrame; |
36 } // namespace blink | 37 } // namespace blink |
37 | 38 |
38 namespace content { | 39 namespace content { |
39 class BluetoothMessageFilter; | 40 class BluetoothMessageFilter; |
(...skipping 14 matching lines...) Expand all Loading... |
54 class ThreadSafeSender; | 55 class ThreadSafeSender; |
55 class WebSocketDispatcher; | 56 class WebSocketDispatcher; |
56 struct RequestInfo; | 57 struct RequestInfo; |
57 | 58 |
58 // The main thread of a child process derives from this class. | 59 // The main thread of a child process derives from this class. |
59 class CONTENT_EXPORT ChildThread : public IPC::Listener, public IPC::Sender { | 60 class CONTENT_EXPORT ChildThread : public IPC::Listener, public IPC::Sender { |
60 public: | 61 public: |
61 struct CONTENT_EXPORT Options { | 62 struct CONTENT_EXPORT Options { |
62 Options(); | 63 Options(); |
63 explicit Options(bool mojo); | 64 explicit Options(bool mojo); |
64 Options(std::string name, bool mojo) | 65 Options(std::string name, bool mojo); |
65 : channel_name(name), use_mojo_channel(mojo) {} | 66 ~Options(); |
66 | 67 |
67 std::string channel_name; | 68 std::string channel_name; |
68 bool use_mojo_channel; | 69 bool use_mojo_channel; |
| 70 bool in_browser_process; |
| 71 std::vector<IPC::MessageFilter*> startup_filters; |
69 }; | 72 }; |
70 | 73 |
71 // Creates the thread. | 74 // Creates the thread. |
72 ChildThread(); | 75 ChildThread(); |
73 // Used for single-process mode and for in process gpu mode. | 76 // Allow to be used for single-process mode and for in process gpu mode via |
| 77 // options. |
74 explicit ChildThread(const Options& options); | 78 explicit ChildThread(const Options& options); |
75 // ChildProcess::main_thread() is reset after Shutdown(), and before the | 79 // ChildProcess::main_thread() is reset after Shutdown(), and before the |
76 // destructor, so any subsystem that relies on ChildProcess::main_thread() | 80 // destructor, so any subsystem that relies on ChildProcess::main_thread() |
77 // must be terminated before Shutdown returns. In particular, if a subsystem | 81 // must be terminated before Shutdown returns. In particular, if a subsystem |
78 // has a thread that post tasks to ChildProcess::main_thread(), that thread | 82 // has a thread that post tasks to ChildProcess::main_thread(), that thread |
79 // should be joined in Shutdown(). | 83 // should be joined in Shutdown(). |
80 ~ChildThread() override; | 84 ~ChildThread() override; |
81 virtual void Shutdown(); | 85 virtual void Shutdown(); |
82 | 86 |
83 // IPC::Sender implementation: | 87 // IPC::Sender implementation: |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 public: | 204 public: |
201 // |sender| must outlive this object. | 205 // |sender| must outlive this object. |
202 explicit ChildThreadMessageRouter(IPC::Sender* sender); | 206 explicit ChildThreadMessageRouter(IPC::Sender* sender); |
203 bool Send(IPC::Message* msg) override; | 207 bool Send(IPC::Message* msg) override; |
204 | 208 |
205 private: | 209 private: |
206 IPC::Sender* const sender_; | 210 IPC::Sender* const sender_; |
207 }; | 211 }; |
208 | 212 |
209 void Init(const Options& options); | 213 void Init(const Options& options); |
210 scoped_ptr<IPC::SyncChannel> CreateChannel(bool use_mojo_channel); | 214 |
| 215 // We create the channel first without connecting it so we can add filters |
| 216 // prior to any messages being received, then connect it afterwards. |
| 217 void ConnectChannel(bool use_mojo_channel); |
211 | 218 |
212 // IPC message handlers. | 219 // IPC message handlers. |
213 void OnShutdown(); | 220 void OnShutdown(); |
214 void OnSetProfilerStatus(tracked_objects::ThreadData::Status status); | 221 void OnSetProfilerStatus(tracked_objects::ThreadData::Status status); |
215 void OnGetChildProfilerData(int sequence_number); | 222 void OnGetChildProfilerData(int sequence_number); |
216 void OnDumpHandles(); | 223 void OnDumpHandles(); |
217 void OnProcessBackgrounded(bool background); | 224 void OnProcessBackgrounded(bool background); |
218 #ifdef IPC_MESSAGE_LOG_ENABLED | 225 #ifdef IPC_MESSAGE_LOG_ENABLED |
219 void OnSetIPCLoggingEnabled(bool enable); | 226 void OnSetIPCLoggingEnabled(bool enable); |
220 #endif | 227 #endif |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 bool in_browser_process_; | 293 bool in_browser_process_; |
287 | 294 |
288 base::WeakPtrFactory<ChildThread> channel_connected_factory_; | 295 base::WeakPtrFactory<ChildThread> channel_connected_factory_; |
289 | 296 |
290 DISALLOW_COPY_AND_ASSIGN(ChildThread); | 297 DISALLOW_COPY_AND_ASSIGN(ChildThread); |
291 }; | 298 }; |
292 | 299 |
293 } // namespace content | 300 } // namespace content |
294 | 301 |
295 #endif // CONTENT_CHILD_CHILD_THREAD_H_ | 302 #endif // CONTENT_CHILD_CHILD_THREAD_H_ |
OLD | NEW |