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 REMOTING_BASE_AUTO_THREAD_H_ | 5 #ifndef REMOTING_BASE_AUTO_THREAD_H_ |
6 #define REMOTING_BASE_AUTO_THREAD_H_ | 6 #define REMOTING_BASE_AUTO_THREAD_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/callback_forward.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "base/threading/thread_checker.h" |
13 #include "build/build_config.h" | 15 #include "build/build_config.h" |
14 #include "remoting/base/auto_thread_task_runner.h" | 16 #include "remoting/base/auto_thread_task_runner.h" |
15 | 17 |
16 namespace remoting { | 18 namespace remoting { |
17 | 19 |
18 // Thread implementation that runs a MessageLoop on a new thread, and manages | 20 // Thread implementation that runs a MessageLoop on a new thread, and manages |
19 // the lifetime of the MessageLoop and thread by tracking references to the | 21 // the lifetime of the MessageLoop and thread by tracking references to the |
20 // thread's TaskRunner. The caller passes the thread's TaskRunner to each | 22 // thread's TaskRunner. The caller passes the thread's TaskRunner to each |
21 // object that needs to run code on the thread, and when no references to the | 23 // object that needs to run code on the thread, and when no references to the |
22 // TaskRunner remain, the thread will exit. When the caller destroys this | 24 // TaskRunner remain, the thread will exit. When the caller destroys this |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 76 |
75 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
76 // Configures the thread to initialize the specified COM apartment type. | 78 // Configures the thread to initialize the specified COM apartment type. |
77 // SetComInitType() must be called before Start(). | 79 // SetComInitType() must be called before Start(). |
78 void SetComInitType(ComInitType com_init_type); | 80 void SetComInitType(ComInitType com_init_type); |
79 #endif | 81 #endif |
80 | 82 |
81 private: | 83 private: |
82 AutoThread(const char* name, AutoThreadTaskRunner* joiner); | 84 AutoThread(const char* name, AutoThreadTaskRunner* joiner); |
83 | 85 |
84 void QuitThread(scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 86 void QuitThread(const base::Closure& quit_when_idle_closure); |
85 void JoinAndDeleteThread(); | 87 void JoinAndDeleteThread(); |
86 | 88 |
87 // base::PlatformThread::Delegate methods: | 89 // base::PlatformThread::Delegate methods: |
88 void ThreadMain() override; | 90 void ThreadMain() override; |
89 | 91 |
90 // Used to pass data to ThreadMain. | 92 // Used to pass data to ThreadMain. |
91 struct StartupData; | 93 struct StartupData; |
92 StartupData* startup_data_; | 94 StartupData* startup_data_; |
93 | 95 |
94 #if defined(OS_WIN) | 96 #if defined(OS_WIN) |
95 // Specifies which kind of COM apartment to initialize, if any. | 97 // Specifies which kind of COM apartment to initialize, if any. |
96 ComInitType com_init_type_; | 98 ComInitType com_init_type_; |
97 #endif | 99 #endif |
98 | 100 |
99 // The thread's handle. | 101 // The thread's handle. |
100 base::PlatformThreadHandle thread_; | 102 base::PlatformThreadHandle thread_; |
101 | 103 |
102 // The name of the thread. Used for debugging purposes. | 104 // The name of the thread. Used for debugging purposes. |
103 std::string name_; | 105 std::string name_; |
104 | 106 |
105 // Flag used to indicate whether MessageLoop was quit properly. | 107 // Flag used to indicate whether MessageLoop was quit properly. |
106 // This allows us to detect premature exit via MessageLoop::QuitWhenIdle(). | 108 // This allows us to detect premature exit via MessageLoop::QuitWhenIdle(). |
107 bool was_quit_properly_; | 109 bool was_quit_properly_; |
108 | 110 |
109 // AutoThreadTaskRunner to post a task to to join & delete this thread. | 111 // AutoThreadTaskRunner to post a task to to join & delete this thread. |
110 scoped_refptr<AutoThreadTaskRunner> joiner_; | 112 scoped_refptr<AutoThreadTaskRunner> joiner_; |
111 | 113 |
| 114 // Verifies that QuitThread() is called on the same thread as ThreadMain(). |
| 115 base::ThreadChecker thread_checker_; |
| 116 |
112 DISALLOW_COPY_AND_ASSIGN(AutoThread); | 117 DISALLOW_COPY_AND_ASSIGN(AutoThread); |
113 }; | 118 }; |
114 | 119 |
115 } // namespace remoting | 120 } // namespace remoting |
116 | 121 |
117 #endif // REMOTING_AUTO_THREAD_H_ | 122 #endif // REMOTING_AUTO_THREAD_H_ |
OLD | NEW |