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_IMPL_H_ | 5 #ifndef CONTENT_CHILD_CHILD_THREAD_IMPL_H_ |
6 #define CONTENT_CHILD_CHILD_THREAD_IMPL_H_ | 6 #define CONTENT_CHILD_CHILD_THREAD_IMPL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/power_monitor/power_monitor.h" | 17 #include "base/power_monitor/power_monitor.h" |
18 #include "base/sequenced_task_runner.h" | 18 #include "base/sequenced_task_runner.h" |
19 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
22 #include "content/public/child/child_thread.h" | 22 #include "content/public/child/child_thread.h" |
23 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. | 23 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. |
24 #include "ipc/ipc_platform_file.h" | 24 #include "ipc/ipc_platform_file.h" |
25 #include "ipc/message_router.h" | 25 #include "ipc/message_router.h" |
26 #include "services/shell/public/cpp/service.h" | |
27 | 26 |
28 namespace base { | 27 namespace base { |
29 class MessageLoop; | 28 class MessageLoop; |
30 } // namespace base | 29 } // namespace base |
31 | 30 |
32 namespace IPC { | 31 namespace IPC { |
33 class MessageFilter; | 32 class MessageFilter; |
34 class SyncChannel; | 33 class SyncChannel; |
35 class SyncMessageFilter; | 34 class SyncMessageFilter; |
36 } // namespace IPC | 35 } // namespace IPC |
(...skipping 24 matching lines...) Expand all Loading... |
61 class QuotaMessageFilter; | 60 class QuotaMessageFilter; |
62 class ResourceDispatcher; | 61 class ResourceDispatcher; |
63 class ThreadSafeSender; | 62 class ThreadSafeSender; |
64 class WebSocketDispatcher; | 63 class WebSocketDispatcher; |
65 class WebSocketMessageFilter; | 64 class WebSocketMessageFilter; |
66 struct RequestInfo; | 65 struct RequestInfo; |
67 | 66 |
68 // The main thread of a child process derives from this class. | 67 // The main thread of a child process derives from this class. |
69 class CONTENT_EXPORT ChildThreadImpl | 68 class CONTENT_EXPORT ChildThreadImpl |
70 : public IPC::Listener, | 69 : public IPC::Listener, |
71 virtual public ChildThread, | 70 virtual public ChildThread { |
72 public NON_EXPORTED_BASE(shell::Service){ | |
73 public: | 71 public: |
74 struct CONTENT_EXPORT Options; | 72 struct CONTENT_EXPORT Options; |
75 | 73 |
76 // Creates the thread. | 74 // Creates the thread. |
77 ChildThreadImpl(); | 75 ChildThreadImpl(); |
78 // Allow to be used for single-process mode and for in process gpu mode via | 76 // Allow to be used for single-process mode and for in process gpu mode via |
79 // options. | 77 // options. |
80 explicit ChildThreadImpl(const Options& options); | 78 explicit ChildThreadImpl(const Options& options); |
81 // ChildProcess::main_thread() is reset after Shutdown(), and before the | 79 // ChildProcess::main_thread() is reset after Shutdown(), and before the |
82 // destructor, so any subsystem that relies on ChildProcess::main_thread() | 80 // destructor, so any subsystem that relies on ChildProcess::main_thread() |
(...skipping 11 matching lines...) Expand all Loading... |
94 #if defined(OS_WIN) | 92 #if defined(OS_WIN) |
95 void PreCacheFont(const LOGFONT& log_font) override; | 93 void PreCacheFont(const LOGFONT& log_font) override; |
96 void ReleaseCachedFonts() override; | 94 void ReleaseCachedFonts() override; |
97 #endif | 95 #endif |
98 void RecordAction(const base::UserMetricsAction& action) override; | 96 void RecordAction(const base::UserMetricsAction& action) override; |
99 void RecordComputedAction(const std::string& action) override; | 97 void RecordComputedAction(const std::string& action) override; |
100 MojoShellConnection* GetMojoShellConnection() override; | 98 MojoShellConnection* GetMojoShellConnection() override; |
101 shell::InterfaceRegistry* GetInterfaceRegistry() override; | 99 shell::InterfaceRegistry* GetInterfaceRegistry() override; |
102 shell::InterfaceProvider* GetRemoteInterfaces() override; | 100 shell::InterfaceProvider* GetRemoteInterfaces() override; |
103 | 101 |
104 // shell::Service: | |
105 shell::InterfaceRegistry* GetInterfaceRegistryForConnection() override; | |
106 shell::InterfaceProvider* GetInterfaceProviderForConnection() override; | |
107 | |
108 IPC::SyncChannel* channel() { return channel_.get(); } | 102 IPC::SyncChannel* channel() { return channel_.get(); } |
109 | 103 |
110 IPC::MessageRouter* GetRouter(); | 104 IPC::MessageRouter* GetRouter(); |
111 | 105 |
112 // Allocates a block of shared memory of the given size. Returns NULL on | 106 // Allocates a block of shared memory of the given size. Returns NULL on |
113 // failure. | 107 // failure. |
114 // Note: On posix, this requires a sync IPC to the browser process, | 108 // Note: On posix, this requires a sync IPC to the browser process, |
115 // but on windows the child process directly allocates the block. | 109 // but on windows the child process directly allocates the block. |
116 std::unique_ptr<base::SharedMemory> AllocateSharedMemory(size_t buf_size); | 110 std::unique_ptr<base::SharedMemory> AllocateSharedMemory(size_t buf_size); |
117 | 111 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // process. | 196 // process. |
203 static void ShutdownThread(); | 197 static void ShutdownThread(); |
204 #endif | 198 #endif |
205 | 199 |
206 protected: | 200 protected: |
207 friend class ChildProcess; | 201 friend class ChildProcess; |
208 | 202 |
209 // Called when the process refcount is 0. | 203 // Called when the process refcount is 0. |
210 void OnProcessFinalRelease(); | 204 void OnProcessFinalRelease(); |
211 | 205 |
| 206 // Called by subclasses to manually start the MojoShellConnection. Must only |
| 207 // be called if ChildThreadImpl::Options::auto_start_mojo_shell_connection |
| 208 // was set to |false| on ChildThreadImpl construction. |
| 209 void StartMojoShellConnection(); |
| 210 |
212 virtual bool OnControlMessageReceived(const IPC::Message& msg); | 211 virtual bool OnControlMessageReceived(const IPC::Message& msg); |
213 virtual void OnProcessBackgrounded(bool backgrounded); | 212 virtual void OnProcessBackgrounded(bool backgrounded); |
214 virtual void OnProcessPurgeAndSuspend(); | 213 virtual void OnProcessPurgeAndSuspend(); |
215 | 214 |
216 // IPC::Listener implementation: | 215 // IPC::Listener implementation: |
217 bool OnMessageReceived(const IPC::Message& msg) override; | 216 bool OnMessageReceived(const IPC::Message& msg) override; |
218 void OnChannelConnected(int32_t peer_pid) override; | 217 void OnChannelConnected(int32_t peer_pid) override; |
219 void OnChannelError() override; | 218 void OnChannelError() override; |
220 | 219 |
221 bool IsInBrowserProcess() const; | 220 bool IsInBrowserProcess() const; |
(...skipping 24 matching lines...) Expand all Loading... |
246 void OnSetProfilerStatus(tracked_objects::ThreadData::Status status); | 245 void OnSetProfilerStatus(tracked_objects::ThreadData::Status status); |
247 void OnGetChildProfilerData(int sequence_number, int current_profiling_phase); | 246 void OnGetChildProfilerData(int sequence_number, int current_profiling_phase); |
248 void OnProfilingPhaseCompleted(int profiling_phase); | 247 void OnProfilingPhaseCompleted(int profiling_phase); |
249 #ifdef IPC_MESSAGE_LOG_ENABLED | 248 #ifdef IPC_MESSAGE_LOG_ENABLED |
250 void OnSetIPCLoggingEnabled(bool enable); | 249 void OnSetIPCLoggingEnabled(bool enable); |
251 #endif | 250 #endif |
252 | 251 |
253 void EnsureConnected(); | 252 void EnsureConnected(); |
254 | 253 |
255 std::unique_ptr<mojo::edk::ScopedIPCSupport> mojo_ipc_support_; | 254 std::unique_ptr<mojo::edk::ScopedIPCSupport> mojo_ipc_support_; |
256 std::unique_ptr<MojoShellConnection> mojo_shell_connection_; | |
257 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; | 255 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; |
258 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; | 256 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; |
| 257 std::unique_ptr<MojoShellConnection> mojo_shell_connection_; |
259 | 258 |
260 std::string channel_name_; | 259 std::string channel_name_; |
261 std::unique_ptr<IPC::SyncChannel> channel_; | 260 std::unique_ptr<IPC::SyncChannel> channel_; |
262 | 261 |
263 // Allows threads other than the main thread to send sync messages. | 262 // Allows threads other than the main thread to send sync messages. |
264 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; | 263 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; |
265 | 264 |
266 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 265 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
267 | 266 |
268 // Implements message routing functionality to the consumers of | 267 // Implements message routing functionality to the consumers of |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 301 |
303 std::unique_ptr<ChildGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 302 std::unique_ptr<ChildGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
304 | 303 |
305 std::unique_ptr<ChildDiscardableSharedMemoryManager> | 304 std::unique_ptr<ChildDiscardableSharedMemoryManager> |
306 discardable_shared_memory_manager_; | 305 discardable_shared_memory_manager_; |
307 | 306 |
308 std::unique_ptr<base::PowerMonitor> power_monitor_; | 307 std::unique_ptr<base::PowerMonitor> power_monitor_; |
309 | 308 |
310 scoped_refptr<base::SequencedTaskRunner> browser_process_io_runner_; | 309 scoped_refptr<base::SequencedTaskRunner> browser_process_io_runner_; |
311 | 310 |
312 base::WeakPtrFactory<ChildThreadImpl> channel_connected_factory_; | 311 std::unique_ptr<base::WeakPtrFactory<ChildThreadImpl>> |
| 312 channel_connected_factory_; |
| 313 |
| 314 base::WeakPtrFactory<ChildThreadImpl> weak_factory_; |
313 | 315 |
314 DISALLOW_COPY_AND_ASSIGN(ChildThreadImpl); | 316 DISALLOW_COPY_AND_ASSIGN(ChildThreadImpl); |
315 }; | 317 }; |
316 | 318 |
317 struct ChildThreadImpl::Options { | 319 struct ChildThreadImpl::Options { |
318 Options(const Options& other); | 320 Options(const Options& other); |
319 ~Options(); | 321 ~Options(); |
320 | 322 |
321 class Builder; | 323 class Builder; |
322 | 324 |
323 std::string channel_name; | 325 std::string channel_name; |
324 bool use_mojo_channel; | 326 bool use_mojo_channel; |
| 327 bool auto_start_mojo_shell_connection; |
325 scoped_refptr<base::SequencedTaskRunner> browser_process_io_runner; | 328 scoped_refptr<base::SequencedTaskRunner> browser_process_io_runner; |
326 std::vector<IPC::MessageFilter*> startup_filters; | 329 std::vector<IPC::MessageFilter*> startup_filters; |
327 std::string in_process_ipc_token; | 330 std::string in_process_ipc_token; |
328 std::string in_process_application_token; | 331 std::string in_process_application_token; |
329 | 332 |
330 private: | 333 private: |
331 Options(); | 334 Options(); |
332 }; | 335 }; |
333 | 336 |
334 class ChildThreadImpl::Options::Builder { | 337 class ChildThreadImpl::Options::Builder { |
335 public: | 338 public: |
336 Builder(); | 339 Builder(); |
337 | 340 |
338 Builder& InBrowserProcess(const InProcessChildThreadParams& params); | 341 Builder& InBrowserProcess(const InProcessChildThreadParams& params); |
339 Builder& UseMojoChannel(bool use_mojo_channel); | 342 Builder& UseMojoChannel(bool use_mojo_channel); |
| 343 Builder& AutoStartMojoShellConnection(bool auto_start); |
340 Builder& WithChannelName(const std::string& channel_name); | 344 Builder& WithChannelName(const std::string& channel_name); |
341 Builder& AddStartupFilter(IPC::MessageFilter* filter); | 345 Builder& AddStartupFilter(IPC::MessageFilter* filter); |
342 | 346 |
343 Options Build(); | 347 Options Build(); |
344 | 348 |
345 private: | 349 private: |
346 struct Options options_; | 350 struct Options options_; |
347 | 351 |
348 DISALLOW_COPY_AND_ASSIGN(Builder); | 352 DISALLOW_COPY_AND_ASSIGN(Builder); |
349 }; | 353 }; |
350 | 354 |
351 } // namespace content | 355 } // namespace content |
352 | 356 |
353 #endif // CONTENT_CHILD_CHILD_THREAD_IMPL_H_ | 357 #endif // CONTENT_CHILD_CHILD_THREAD_IMPL_H_ |
OLD | NEW |