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/single_thread_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/associated_interfaces.mojom.h" | 21 #include "content/common/associated_interfaces.mojom.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.mojom.h" | 24 #include "ipc/ipc.mojom.h" |
25 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. | 25 #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. |
26 #include "ipc/ipc_platform_file.h" | 26 #include "ipc/ipc_platform_file.h" |
27 #include "ipc/message_router.h" | 27 #include "ipc/message_router.h" |
28 #include "mojo/public/cpp/bindings/associated_binding.h" | 28 #include "mojo/public/cpp/bindings/associated_binding.h" |
(...skipping 12 matching lines...) Expand all Loading... |
41 namespace service_manager { | 41 namespace service_manager { |
42 class Connection; | 42 class Connection; |
43 } // namespace service_manager | 43 } // namespace service_manager |
44 | 44 |
45 namespace mojo { | 45 namespace mojo { |
46 namespace edk { | 46 namespace edk { |
47 class ScopedIPCSupport; | 47 class ScopedIPCSupport; |
48 } // namespace edk | 48 } // namespace edk |
49 } // namespace mojo | 49 } // namespace mojo |
50 | 50 |
51 namespace discardable_memory { | |
52 class ClientDiscardableSharedMemoryManager; | |
53 } // namespace discardable_memory | |
54 | |
55 namespace content { | 51 namespace content { |
56 class ChildHistogramMessageFilter; | 52 class ChildHistogramMessageFilter; |
57 class ChildResourceMessageFilter; | 53 class ChildResourceMessageFilter; |
58 class ChildSharedBitmapManager; | 54 class ChildSharedBitmapManager; |
59 class FileSystemDispatcher; | 55 class FileSystemDispatcher; |
60 class InProcessChildThreadParams; | 56 class InProcessChildThreadParams; |
61 class NotificationDispatcher; | 57 class NotificationDispatcher; |
62 class PushDispatcher; | 58 class PushDispatcher; |
63 class ServiceWorkerMessageFilter; | 59 class ServiceWorkerMessageFilter; |
64 class QuotaDispatcher; | 60 class QuotaDispatcher; |
(...skipping 15 matching lines...) Expand all Loading... |
80 // 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 |
81 // options. | 77 // options. |
82 explicit ChildThreadImpl(const Options& options); | 78 explicit ChildThreadImpl(const Options& options); |
83 // ChildProcess::main_thread() is reset after Shutdown(), and before the | 79 // ChildProcess::main_thread() is reset after Shutdown(), and before the |
84 // destructor, so any subsystem that relies on ChildProcess::main_thread() | 80 // destructor, so any subsystem that relies on ChildProcess::main_thread() |
85 // must be terminated before Shutdown returns. In particular, if a subsystem | 81 // must be terminated before Shutdown returns. In particular, if a subsystem |
86 // 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 |
87 // should be joined in Shutdown(). | 83 // should be joined in Shutdown(). |
88 ~ChildThreadImpl() override; | 84 ~ChildThreadImpl() override; |
89 virtual void Shutdown(); | 85 virtual void Shutdown(); |
90 void ShutdownDiscardableSharedMemoryManager(); | |
91 | 86 |
92 // IPC::Sender implementation: | 87 // IPC::Sender implementation: |
93 bool Send(IPC::Message* msg) override; | 88 bool Send(IPC::Message* msg) override; |
94 | 89 |
95 // ChildThread implementation: | 90 // ChildThread implementation: |
96 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
97 void PreCacheFont(const LOGFONT& log_font) override; | 92 void PreCacheFont(const LOGFONT& log_font) override; |
98 void ReleaseCachedFonts() override; | 93 void ReleaseCachedFonts() override; |
99 #endif | 94 #endif |
100 void RecordAction(const base::UserMetricsAction& action) override; | 95 void RecordAction(const base::UserMetricsAction& action) override; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 127 |
133 #if defined(OS_LINUX) | 128 #if defined(OS_LINUX) |
134 void SetThreadPriority(base::PlatformThreadId id, | 129 void SetThreadPriority(base::PlatformThreadId id, |
135 base::ThreadPriority priority); | 130 base::ThreadPriority priority); |
136 #endif | 131 #endif |
137 | 132 |
138 ChildSharedBitmapManager* shared_bitmap_manager() const { | 133 ChildSharedBitmapManager* shared_bitmap_manager() const { |
139 return shared_bitmap_manager_.get(); | 134 return shared_bitmap_manager_.get(); |
140 } | 135 } |
141 | 136 |
142 discardable_memory::ClientDiscardableSharedMemoryManager* | |
143 discardable_shared_memory_manager() const { | |
144 return discardable_shared_memory_manager_.get(); | |
145 } | |
146 | |
147 ResourceDispatcher* resource_dispatcher() const { | 137 ResourceDispatcher* resource_dispatcher() const { |
148 return resource_dispatcher_.get(); | 138 return resource_dispatcher_.get(); |
149 } | 139 } |
150 | 140 |
151 FileSystemDispatcher* file_system_dispatcher() const { | 141 FileSystemDispatcher* file_system_dispatcher() const { |
152 return file_system_dispatcher_.get(); | 142 return file_system_dispatcher_.get(); |
153 } | 143 } |
154 | 144 |
155 QuotaDispatcher* quota_dispatcher() const { | 145 QuotaDispatcher* quota_dispatcher() const { |
156 return quota_dispatcher_.get(); | 146 return quota_dispatcher_.get(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 virtual void OnProcessBackgrounded(bool backgrounded); | 208 virtual void OnProcessBackgrounded(bool backgrounded); |
219 virtual void OnProcessPurgeAndSuspend(); | 209 virtual void OnProcessPurgeAndSuspend(); |
220 virtual void OnProcessResume(); | 210 virtual void OnProcessResume(); |
221 | 211 |
222 // IPC::Listener implementation: | 212 // IPC::Listener implementation: |
223 bool OnMessageReceived(const IPC::Message& msg) override; | 213 bool OnMessageReceived(const IPC::Message& msg) override; |
224 void OnChannelConnected(int32_t peer_pid) override; | 214 void OnChannelConnected(int32_t peer_pid) override; |
225 void OnChannelError() override; | 215 void OnChannelError() override; |
226 | 216 |
227 bool IsInBrowserProcess() const; | 217 bool IsInBrowserProcess() const; |
228 scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner(); | 218 scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner(); |
229 | 219 |
230 private: | 220 private: |
231 class ChildThreadMessageRouter : public IPC::MessageRouter { | 221 class ChildThreadMessageRouter : public IPC::MessageRouter { |
232 public: | 222 public: |
233 // |sender| must outlive this object. | 223 // |sender| must outlive this object. |
234 explicit ChildThreadMessageRouter(IPC::Sender* sender); | 224 explicit ChildThreadMessageRouter(IPC::Sender* sender); |
235 bool Send(IPC::Message* msg) override; | 225 bool Send(IPC::Message* msg) override; |
236 | 226 |
237 // MessageRouter overrides. | 227 // MessageRouter overrides. |
238 bool RouteMessage(const IPC::Message& msg) override; | 228 bool RouteMessage(const IPC::Message& msg) override; |
239 | 229 |
240 private: | 230 private: |
241 IPC::Sender* const sender_; | 231 IPC::Sender* const sender_; |
242 }; | 232 }; |
243 | 233 |
244 class ClientDiscardableSharedMemoryManagerDelegate; | |
245 | |
246 void Init(const Options& options); | 234 void Init(const Options& options); |
247 | 235 |
248 // We create the channel first without connecting it so we can add filters | 236 // We create the channel first without connecting it so we can add filters |
249 // prior to any messages being received, then connect it afterwards. | 237 // prior to any messages being received, then connect it afterwards. |
250 void ConnectChannel(); | 238 void ConnectChannel(); |
251 | 239 |
252 // IPC message handlers. | 240 // IPC message handlers. |
253 void OnShutdown(); | 241 void OnShutdown(); |
254 void OnSetProfilerStatus(tracked_objects::ThreadData::Status status); | 242 void OnSetProfilerStatus(tracked_objects::ThreadData::Status status); |
255 void OnGetChildProfilerData(int sequence_number, int current_profiling_phase); | 243 void OnGetChildProfilerData(int sequence_number, int current_profiling_phase); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 scoped_refptr<ServiceWorkerMessageFilter> service_worker_message_filter_; | 311 scoped_refptr<ServiceWorkerMessageFilter> service_worker_message_filter_; |
324 | 312 |
325 scoped_refptr<QuotaMessageFilter> quota_message_filter_; | 313 scoped_refptr<QuotaMessageFilter> quota_message_filter_; |
326 | 314 |
327 scoped_refptr<NotificationDispatcher> notification_dispatcher_; | 315 scoped_refptr<NotificationDispatcher> notification_dispatcher_; |
328 | 316 |
329 scoped_refptr<PushDispatcher> push_dispatcher_; | 317 scoped_refptr<PushDispatcher> push_dispatcher_; |
330 | 318 |
331 std::unique_ptr<ChildSharedBitmapManager> shared_bitmap_manager_; | 319 std::unique_ptr<ChildSharedBitmapManager> shared_bitmap_manager_; |
332 | 320 |
333 std::unique_ptr<discardable_memory::ClientDiscardableSharedMemoryManager> | |
334 discardable_shared_memory_manager_; | |
335 | |
336 std::unique_ptr<ClientDiscardableSharedMemoryManagerDelegate> | |
337 client_discardable_shared_memory_manager_delegate_; | |
338 | |
339 std::unique_ptr<base::PowerMonitor> power_monitor_; | 321 std::unique_ptr<base::PowerMonitor> power_monitor_; |
340 | 322 |
341 scoped_refptr<base::SequencedTaskRunner> browser_process_io_runner_; | 323 scoped_refptr<base::SingleThreadTaskRunner> browser_process_io_runner_; |
342 | 324 |
343 std::unique_ptr<base::WeakPtrFactory<ChildThreadImpl>> | 325 std::unique_ptr<base::WeakPtrFactory<ChildThreadImpl>> |
344 channel_connected_factory_; | 326 channel_connected_factory_; |
345 | 327 |
346 base::WeakPtrFactory<ChildThreadImpl> weak_factory_; | 328 base::WeakPtrFactory<ChildThreadImpl> weak_factory_; |
347 | 329 |
348 DISALLOW_COPY_AND_ASSIGN(ChildThreadImpl); | 330 DISALLOW_COPY_AND_ASSIGN(ChildThreadImpl); |
349 }; | 331 }; |
350 | 332 |
351 struct ChildThreadImpl::Options { | 333 struct ChildThreadImpl::Options { |
352 Options(const Options& other); | 334 Options(const Options& other); |
353 ~Options(); | 335 ~Options(); |
354 | 336 |
355 class Builder; | 337 class Builder; |
356 | 338 |
357 bool auto_start_service_manager_connection; | 339 bool auto_start_service_manager_connection; |
358 bool connect_to_browser; | 340 bool connect_to_browser; |
359 scoped_refptr<base::SequencedTaskRunner> browser_process_io_runner; | 341 scoped_refptr<base::SingleThreadTaskRunner> browser_process_io_runner; |
360 std::vector<IPC::MessageFilter*> startup_filters; | 342 std::vector<IPC::MessageFilter*> startup_filters; |
361 std::string in_process_service_request_token; | 343 std::string in_process_service_request_token; |
362 | 344 |
363 private: | 345 private: |
364 Options(); | 346 Options(); |
365 }; | 347 }; |
366 | 348 |
367 class ChildThreadImpl::Options::Builder { | 349 class ChildThreadImpl::Options::Builder { |
368 public: | 350 public: |
369 Builder(); | 351 Builder(); |
370 | 352 |
371 Builder& InBrowserProcess(const InProcessChildThreadParams& params); | 353 Builder& InBrowserProcess(const InProcessChildThreadParams& params); |
372 Builder& AutoStartServiceManagerConnection(bool auto_start); | 354 Builder& AutoStartServiceManagerConnection(bool auto_start); |
373 Builder& ConnectToBrowser(bool connect_to_browser); | 355 Builder& ConnectToBrowser(bool connect_to_browser); |
374 Builder& AddStartupFilter(IPC::MessageFilter* filter); | 356 Builder& AddStartupFilter(IPC::MessageFilter* filter); |
375 | 357 |
376 Options Build(); | 358 Options Build(); |
377 | 359 |
378 private: | 360 private: |
379 struct Options options_; | 361 struct Options options_; |
380 | 362 |
381 DISALLOW_COPY_AND_ASSIGN(Builder); | 363 DISALLOW_COPY_AND_ASSIGN(Builder); |
382 }; | 364 }; |
383 | 365 |
384 } // namespace content | 366 } // namespace content |
385 | 367 |
386 #endif // CONTENT_CHILD_CHILD_THREAD_IMPL_H_ | 368 #endif // CONTENT_CHILD_CHILD_THREAD_IMPL_H_ |
OLD | NEW |