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/child/mojo/mojo_application.h" | 21 #include "content/child/mojo/mojo_application.h" |
22 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
23 #include "content/public/child/child_thread.h" | 23 #include "content/public/child/child_thread.h" |
24 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. | 24 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. |
25 #include "ipc/ipc_platform_file.h" | 25 #include "ipc/ipc_platform_file.h" |
26 #include "ipc/message_router.h" | 26 #include "ipc/message_router.h" |
27 #include "services/shell/public/cpp/shell_client.h" | |
28 | 27 |
29 namespace base { | 28 namespace base { |
30 class MessageLoop; | 29 class MessageLoop; |
31 } // namespace base | 30 } // namespace base |
32 | 31 |
33 namespace IPC { | 32 namespace IPC { |
34 class MessageFilter; | 33 class MessageFilter; |
35 class SyncChannel; | 34 class SyncChannel; |
36 class SyncMessageFilter; | 35 class SyncMessageFilter; |
37 } // namespace IPC | 36 } // namespace IPC |
(...skipping 24 matching lines...) Expand all Loading... |
62 class QuotaMessageFilter; | 61 class QuotaMessageFilter; |
63 class ResourceDispatcher; | 62 class ResourceDispatcher; |
64 class ThreadSafeSender; | 63 class ThreadSafeSender; |
65 class WebSocketDispatcher; | 64 class WebSocketDispatcher; |
66 class WebSocketMessageFilter; | 65 class WebSocketMessageFilter; |
67 struct RequestInfo; | 66 struct RequestInfo; |
68 | 67 |
69 // The main thread of a child process derives from this class. | 68 // The main thread of a child process derives from this class. |
70 class CONTENT_EXPORT ChildThreadImpl | 69 class CONTENT_EXPORT ChildThreadImpl |
71 : public IPC::Listener, | 70 : public IPC::Listener, |
72 virtual public ChildThread, | 71 virtual public ChildThread { |
73 public NON_EXPORTED_BASE(shell::ShellClient){ | |
74 public: | 72 public: |
75 struct CONTENT_EXPORT Options; | 73 struct CONTENT_EXPORT Options; |
76 | 74 |
77 // Creates the thread. | 75 // Creates the thread. |
78 ChildThreadImpl(); | 76 ChildThreadImpl(); |
79 // Allow to be used for single-process mode and for in process gpu mode via | 77 // Allow to be used for single-process mode and for in process gpu mode via |
80 // options. | 78 // options. |
81 explicit ChildThreadImpl(const Options& options); | 79 explicit ChildThreadImpl(const Options& options); |
82 // ChildProcess::main_thread() is reset after Shutdown(), and before the | 80 // ChildProcess::main_thread() is reset after Shutdown(), and before the |
83 // destructor, so any subsystem that relies on ChildProcess::main_thread() | 81 // destructor, so any subsystem that relies on ChildProcess::main_thread() |
84 // must be terminated before Shutdown returns. In particular, if a subsystem | 82 // must be terminated before Shutdown returns. In particular, if a subsystem |
85 // has a thread that post tasks to ChildProcess::main_thread(), that thread | 83 // has a thread that post tasks to ChildProcess::main_thread(), that thread |
86 // should be joined in Shutdown(). | 84 // should be joined in Shutdown(). |
87 ~ChildThreadImpl() override; | 85 ~ChildThreadImpl() override; |
88 virtual void Shutdown(); | 86 virtual void Shutdown(); |
89 void ShutdownDiscardableSharedMemoryManager(); | 87 void ShutdownDiscardableSharedMemoryManager(); |
90 | 88 |
91 // IPC::Sender implementation: | 89 // IPC::Sender implementation: |
92 bool Send(IPC::Message* msg) override; | 90 bool Send(IPC::Message* msg) override; |
93 | 91 |
94 // ChildThread implementation: | 92 // ChildThread implementation: |
95 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
96 void PreCacheFont(const LOGFONT& log_font) override; | 94 void PreCacheFont(const LOGFONT& log_font) override; |
97 void ReleaseCachedFonts() override; | 95 void ReleaseCachedFonts() override; |
98 #endif | 96 #endif |
99 void RecordAction(const base::UserMetricsAction& action) override; | 97 void RecordAction(const base::UserMetricsAction& action) override; |
100 void RecordComputedAction(const std::string& action) override; | 98 void RecordComputedAction(const std::string& action) override; |
101 MojoShellConnection* GetMojoShellConnection() override; | |
102 shell::InterfaceRegistry* GetInterfaceRegistry() override; | 99 shell::InterfaceRegistry* GetInterfaceRegistry() override; |
103 shell::InterfaceProvider* GetRemoteInterfaces() override; | 100 shell::InterfaceProvider* GetRemoteInterfaces() override; |
104 | 101 |
105 // shell::ShellClient: | |
106 shell::InterfaceRegistry* GetInterfaceRegistryForConnection() override; | |
107 shell::InterfaceProvider* GetInterfaceProviderForConnection() override; | |
108 | |
109 IPC::SyncChannel* channel() { return channel_.get(); } | 102 IPC::SyncChannel* channel() { return channel_.get(); } |
110 | 103 |
111 IPC::MessageRouter* GetRouter(); | 104 IPC::MessageRouter* GetRouter(); |
112 | 105 |
113 // 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 |
114 // failure. | 107 // failure. |
115 // 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, |
116 // but on windows the child process directly allocates the block. | 109 // but on windows the child process directly allocates the block. |
117 std::unique_ptr<base::SharedMemory> AllocateSharedMemory(size_t buf_size); | 110 std::unique_ptr<base::SharedMemory> AllocateSharedMemory(size_t buf_size); |
118 | 111 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 void OnSetProfilerStatus(tracked_objects::ThreadData::Status status); | 240 void OnSetProfilerStatus(tracked_objects::ThreadData::Status status); |
248 void OnGetChildProfilerData(int sequence_number, int current_profiling_phase); | 241 void OnGetChildProfilerData(int sequence_number, int current_profiling_phase); |
249 void OnProfilingPhaseCompleted(int profiling_phase); | 242 void OnProfilingPhaseCompleted(int profiling_phase); |
250 #ifdef IPC_MESSAGE_LOG_ENABLED | 243 #ifdef IPC_MESSAGE_LOG_ENABLED |
251 void OnSetIPCLoggingEnabled(bool enable); | 244 void OnSetIPCLoggingEnabled(bool enable); |
252 #endif | 245 #endif |
253 | 246 |
254 void EnsureConnected(); | 247 void EnsureConnected(); |
255 | 248 |
256 std::unique_ptr<mojo::edk::ScopedIPCSupport> mojo_ipc_support_; | 249 std::unique_ptr<mojo::edk::ScopedIPCSupport> mojo_ipc_support_; |
257 bool use_mojo_shell_connection_ = false; | |
258 std::unique_ptr<MojoApplication> mojo_application_; | 250 std::unique_ptr<MojoApplication> mojo_application_; |
259 std::unique_ptr<MojoShellConnection> mojo_shell_connection_; | |
260 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; | |
261 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; | |
262 | 251 |
263 std::string channel_name_; | 252 std::string channel_name_; |
264 std::unique_ptr<IPC::SyncChannel> channel_; | 253 std::unique_ptr<IPC::SyncChannel> channel_; |
265 | 254 |
266 // Allows threads other than the main thread to send sync messages. | 255 // Allows threads other than the main thread to send sync messages. |
267 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; | 256 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; |
268 | 257 |
269 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 258 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
270 | 259 |
271 // Implements message routing functionality to the consumers of | 260 // Implements message routing functionality to the consumers of |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 ~Options(); | 311 ~Options(); |
323 | 312 |
324 class Builder; | 313 class Builder; |
325 | 314 |
326 std::string channel_name; | 315 std::string channel_name; |
327 bool use_mojo_channel; | 316 bool use_mojo_channel; |
328 scoped_refptr<base::SequencedTaskRunner> browser_process_io_runner; | 317 scoped_refptr<base::SequencedTaskRunner> browser_process_io_runner; |
329 std::vector<IPC::MessageFilter*> startup_filters; | 318 std::vector<IPC::MessageFilter*> startup_filters; |
330 std::string in_process_ipc_token; | 319 std::string in_process_ipc_token; |
331 std::string in_process_application_token; | 320 std::string in_process_application_token; |
332 bool use_mojo_shell_connection = false; | |
333 | 321 |
334 private: | 322 private: |
335 Options(); | 323 Options(); |
336 }; | 324 }; |
337 | 325 |
338 class ChildThreadImpl::Options::Builder { | 326 class ChildThreadImpl::Options::Builder { |
339 public: | 327 public: |
340 Builder(); | 328 Builder(); |
341 | 329 |
342 Builder& InBrowserProcess(const InProcessChildThreadParams& params); | 330 Builder& InBrowserProcess(const InProcessChildThreadParams& params); |
343 Builder& UseMojoChannel(bool use_mojo_channel); | 331 Builder& UseMojoChannel(bool use_mojo_channel); |
344 Builder& WithChannelName(const std::string& channel_name); | 332 Builder& WithChannelName(const std::string& channel_name); |
345 Builder& AddStartupFilter(IPC::MessageFilter* filter); | 333 Builder& AddStartupFilter(IPC::MessageFilter* filter); |
346 Builder& UseMojoShellConnection(bool use_mojo_shell_connection); | |
347 | 334 |
348 Options Build(); | 335 Options Build(); |
349 | 336 |
350 private: | 337 private: |
351 struct Options options_; | 338 struct Options options_; |
352 | 339 |
353 DISALLOW_COPY_AND_ASSIGN(Builder); | 340 DISALLOW_COPY_AND_ASSIGN(Builder); |
354 }; | 341 }; |
355 | 342 |
356 } // namespace content | 343 } // namespace content |
357 | 344 |
358 #endif // CONTENT_CHILD_CHILD_THREAD_IMPL_H_ | 345 #endif // CONTENT_CHILD_CHILD_THREAD_IMPL_H_ |
OLD | NEW |