| 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/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // The supplied AutoThreadTaskRunner will be used to join and delete the | 33 // The supplied AutoThreadTaskRunner will be used to join and delete the |
| 34 // new thread when no references to it remain. | 34 // new thread when no references to it remain. |
| 35 static scoped_refptr<AutoThreadTaskRunner> CreateWithType( | 35 static scoped_refptr<AutoThreadTaskRunner> CreateWithType( |
| 36 const char* name, | 36 const char* name, |
| 37 scoped_refptr<AutoThreadTaskRunner> joiner, | 37 scoped_refptr<AutoThreadTaskRunner> joiner, |
| 38 MessageLoop::Type type); | 38 MessageLoop::Type type); |
| 39 static scoped_refptr<AutoThreadTaskRunner> Create( | 39 static scoped_refptr<AutoThreadTaskRunner> Create( |
| 40 const char* name, | 40 const char* name, |
| 41 scoped_refptr<AutoThreadTaskRunner> joiner); | 41 scoped_refptr<AutoThreadTaskRunner> joiner); |
| 42 | 42 |
| 43 #if defined(OS_WIN) |
| 44 // Create an AutoThread initialized for COM. |com_init_type| specifies the |
| 45 // type of COM apartment to initialize. |
| 46 enum ComInitType { COM_INIT_NONE, COM_INIT_STA, COM_INIT_MTA }; |
| 47 static scoped_refptr<AutoThreadTaskRunner> CreateWithLoopAndComInitTypes( |
| 48 const char* name, |
| 49 scoped_refptr<AutoThreadTaskRunner> joiner, |
| 50 MessageLoop::Type loop_type, |
| 51 ComInitType com_init_type); |
| 52 #endif |
| 53 |
| 43 // Construct the AutoThread. |name| identifies the thread for debugging. | 54 // Construct the AutoThread. |name| identifies the thread for debugging. |
| 44 explicit AutoThread(const char* name); | 55 explicit AutoThread(const char* name); |
| 45 | 56 |
| 46 // Waits for the thread to exit, and then destroys it. | 57 // Waits for the thread to exit, and then destroys it. |
| 47 virtual ~AutoThread(); | 58 virtual ~AutoThread(); |
| 48 | 59 |
| 49 // Starts a the thread, running the specified type of MessageLoop. Returns | 60 // Starts the thread, running the specified type of MessageLoop. Returns |
| 50 // an AutoThreadTaskRunner through which tasks may be posted to the thread | 61 // an AutoThreadTaskRunner through which tasks may be posted to the thread |
| 51 // if successful, or NULL on failure. | 62 // if successful, or NULL on failure. |
| 52 // | 63 // |
| 53 // Note: This function can't be called on Windows with the loader lock held; | 64 // Note: This function can't be called on Windows with the loader lock held; |
| 54 // i.e. during a DllMain, global object construction or destruction, atexit() | 65 // i.e. during a DllMain, global object construction or destruction, atexit() |
| 55 // callback. | 66 // callback. |
| 56 // | 67 // |
| 57 // NOTE: You must not call this MessageLoop's Quit method directly. The | 68 // NOTE: You must not call this MessageLoop's Quit method directly. The |
| 58 // thread will exit when no references to the TaskRunner remain. | 69 // thread will exit when no references to the TaskRunner remain. |
| 59 scoped_refptr<AutoThreadTaskRunner> StartWithType(MessageLoop::Type type); | 70 scoped_refptr<AutoThreadTaskRunner> StartWithType(MessageLoop::Type type); |
| 60 | 71 |
| 61 // Shorthand for StartWithType(MessageLoop::TYPE_DEFAULT). | 72 #if defined(OS_WIN) |
| 62 scoped_refptr<AutoThreadTaskRunner> Start(); | 73 // Configures the thread to initialize the specified COM apartment type. |
| 74 // SetComInitType() must be called before Start(). |
| 75 void SetComInitType(ComInitType com_init_type); |
| 76 #endif |
| 63 | 77 |
| 64 private: | 78 private: |
| 65 AutoThread(const char* name, AutoThreadTaskRunner* joiner); | 79 AutoThread(const char* name, AutoThreadTaskRunner* joiner); |
| 66 | 80 |
| 67 void QuitThread(scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 81 void QuitThread(scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 68 void JoinAndDeleteThread(); | 82 void JoinAndDeleteThread(); |
| 69 | 83 |
| 70 // base::PlatformThread::Delegate methods: | 84 // base::PlatformThread::Delegate methods: |
| 71 virtual void ThreadMain() OVERRIDE; | 85 virtual void ThreadMain() OVERRIDE; |
| 72 | 86 |
| 73 // Used to pass data to ThreadMain. | 87 // Used to pass data to ThreadMain. |
| 74 struct StartupData; | 88 struct StartupData; |
| 75 StartupData* startup_data_; | 89 StartupData* startup_data_; |
| 76 | 90 |
| 91 #if defined(OS_WIN) |
| 92 // Specifies which kind of COM apartment to initialize, if any. |
| 93 ComInitType com_init_type_; |
| 94 #endif |
| 95 |
| 77 // The thread's handle. | 96 // The thread's handle. |
| 78 base::PlatformThreadHandle thread_; | 97 base::PlatformThreadHandle thread_; |
| 79 | 98 |
| 80 // The name of the thread. Used for debugging purposes. | 99 // The name of the thread. Used for debugging purposes. |
| 81 std::string name_; | 100 std::string name_; |
| 82 | 101 |
| 83 // Flag used to indicate whether MessageLoop was quit properly. | 102 // Flag used to indicate whether MessageLoop was quit properly. |
| 84 // This allows us to detect premature exit via MessageLoop::Quit(). | 103 // This allows us to detect premature exit via MessageLoop::Quit(). |
| 85 bool was_quit_properly_; | 104 bool was_quit_properly_; |
| 86 | 105 |
| 87 // AutoThreadTaskRunner to post a task to to join & delete this thread. | 106 // AutoThreadTaskRunner to post a task to to join & delete this thread. |
| 88 scoped_refptr<AutoThreadTaskRunner> joiner_; | 107 scoped_refptr<AutoThreadTaskRunner> joiner_; |
| 89 | 108 |
| 90 DISALLOW_COPY_AND_ASSIGN(AutoThread); | 109 DISALLOW_COPY_AND_ASSIGN(AutoThread); |
| 91 }; | 110 }; |
| 92 | 111 |
| 93 } // namespace remoting | 112 } // namespace remoting |
| 94 | 113 |
| 95 #endif // REMOTING_AUTO_THREAD_H_ | 114 #endif // REMOTING_AUTO_THREAD_H_ |
| OLD | NEW |