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_PROCESS_H_ | 5 #ifndef CONTENT_CHILD_CHILD_PROCESS_H_ |
6 #define CONTENT_CHILD_CHILD_PROCESS_H_ | 6 #define CONTENT_CHILD_CHILD_PROCESS_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/task_scheduler/scheduler_worker_pool_params.h" |
| 14 #include "base/task_scheduler/task_scheduler.h" |
| 15 #include "base/threading/platform_thread.h" |
12 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
13 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
14 | 18 |
15 namespace content { | 19 namespace content { |
16 class ChildThreadImpl; | 20 class ChildThreadImpl; |
17 | 21 |
18 // Base class for child processes of the browser process (i.e. renderer and | 22 // Base class for child processes of the browser process (i.e. renderer and |
19 // plugin host). This is a singleton object for each child process. | 23 // plugin host). This is a singleton object for each child process. |
20 // | 24 // |
21 // During process shutdown the following sequence of actions happens in | 25 // During process shutdown the following sequence of actions happens in |
22 // order. | 26 // order. |
23 // | 27 // |
24 // 1. ChildProcess::~ChildProcess() is called. | 28 // 1. ChildProcess::~ChildProcess() is called. |
25 // 2. Shutdown event is fired. Background threads should stop. | 29 // 2. Shutdown event is fired. Background threads should stop. |
26 // 3. ChildThreadImpl::Shutdown() is called. ChildThread is also deleted. | 30 // 3. ChildThreadImpl::Shutdown() is called. ChildThread is also deleted. |
27 // 4. IO thread is stopped. | 31 // 4. IO thread is stopped. |
28 // 5. Main message loop exits. | 32 // 5. Main message loop exits. |
29 // 6. Child process is now fully stopped. | 33 // 6. Child process is now fully stopped. |
30 // | 34 // |
31 // Note: IO thread outlives the ChildThreadImpl object. | 35 // Note: IO thread outlives the ChildThreadImpl object. |
32 class CONTENT_EXPORT ChildProcess { | 36 class CONTENT_EXPORT ChildProcess { |
33 public: | 37 public: |
34 // Child processes should have an object that derives from this class. | 38 // Child processes should have an object that derives from this class. |
35 // Normally you would immediately call set_main_thread after construction. | 39 // Normally you would immediately call set_main_thread after construction. |
36 ChildProcess(); | 40 // |io_thread_priority| is the priority of the IO thread. |worker_pool_params| |
37 explicit ChildProcess(base::ThreadPriority io_thread_priority); | 41 // and |worker_pool_index_for_traits_callback| are used to initialize |
| 42 // TaskScheduler. TaskScheduler is initialized with default values if these |
| 43 // arguments are left empty. |
| 44 ChildProcess( |
| 45 base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL, |
| 46 const std::vector<base::SchedulerWorkerPoolParams>& worker_pool_params = |
| 47 std::vector<base::SchedulerWorkerPoolParams>(), |
| 48 base::TaskScheduler::WorkerPoolIndexForTraitsCallback |
| 49 worker_pool_index_for_traits_callback = |
| 50 base::TaskScheduler::WorkerPoolIndexForTraitsCallback()); |
38 virtual ~ChildProcess(); | 51 virtual ~ChildProcess(); |
39 | 52 |
40 // May be NULL if the main thread hasn't been set explicitly. | 53 // May be NULL if the main thread hasn't been set explicitly. |
41 ChildThreadImpl* main_thread(); | 54 ChildThreadImpl* main_thread(); |
42 | 55 |
43 // Sets the object associated with the main thread of this process. | 56 // Sets the object associated with the main thread of this process. |
44 // Takes ownership of the pointer. | 57 // Takes ownership of the pointer. |
45 void set_main_thread(ChildThreadImpl* thread); | 58 void set_main_thread(ChildThreadImpl* thread); |
46 | 59 |
47 base::MessageLoop* io_message_loop() { return io_thread_.message_loop(); } | 60 base::MessageLoop* io_message_loop() { return io_thread_.message_loop(); } |
(...skipping 23 matching lines...) Expand all Loading... |
71 | 84 |
72 #if defined(OS_LINUX) | 85 #if defined(OS_LINUX) |
73 void SetIOThreadPriority(base::ThreadPriority io_thread_priority); | 86 void SetIOThreadPriority(base::ThreadPriority io_thread_priority); |
74 #endif | 87 #endif |
75 | 88 |
76 // Getter for the one ChildProcess object for this process. Can only be called | 89 // Getter for the one ChildProcess object for this process. Can only be called |
77 // on the main thread. | 90 // on the main thread. |
78 static ChildProcess* current(); | 91 static ChildProcess* current(); |
79 | 92 |
80 static void WaitForDebugger(const std::string& label); | 93 static void WaitForDebugger(const std::string& label); |
| 94 |
81 private: | 95 private: |
82 // Initializes TaskScheduler. May be overridden to initialize TaskScheduler | |
83 // with custom arguments. | |
84 virtual void InitializeTaskScheduler(); | |
85 | |
86 int ref_count_; | 96 int ref_count_; |
87 | 97 |
88 // An event that will be signalled when we shutdown. | 98 // An event that will be signalled when we shutdown. |
89 base::WaitableEvent shutdown_event_; | 99 base::WaitableEvent shutdown_event_; |
90 | 100 |
91 // The thread that handles IO events. | 101 // The thread that handles IO events. |
92 base::Thread io_thread_; | 102 base::Thread io_thread_; |
93 | 103 |
94 // NOTE: make sure that main_thread_ is listed after shutdown_event_, since | 104 // NOTE: make sure that main_thread_ is listed after shutdown_event_, since |
95 // it depends on it (indirectly through IPC::SyncChannel). Same for | 105 // it depends on it (indirectly through IPC::SyncChannel). Same for |
96 // io_thread_. | 106 // io_thread_. |
97 std::unique_ptr<ChildThreadImpl> main_thread_; | 107 std::unique_ptr<ChildThreadImpl> main_thread_; |
98 | 108 |
99 // Whether this ChildProcess initialized TaskScheduler. | 109 // Whether this ChildProcess initialized TaskScheduler. |
100 bool initialized_task_scheduler_ = false; | 110 bool initialized_task_scheduler_ = false; |
101 | 111 |
102 DISALLOW_COPY_AND_ASSIGN(ChildProcess); | 112 DISALLOW_COPY_AND_ASSIGN(ChildProcess); |
103 }; | 113 }; |
104 | 114 |
105 } // namespace content | 115 } // namespace content |
106 | 116 |
107 #endif // CONTENT_CHILD_CHILD_PROCESS_H_ | 117 #endif // CONTENT_CHILD_CHILD_PROCESS_H_ |
OLD | NEW |