Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 // All pending tasks queued on the thread's message loop will run to completion | 22 // All pending tasks queued on the thread's message loop will run to completion |
| 23 // before the thread is terminated. | 23 // before the thread is terminated. |
| 24 // | 24 // |
| 25 // After the thread is stopped, the destruction sequence is: | 25 // After the thread is stopped, the destruction sequence is: |
| 26 // | 26 // |
| 27 // (1) Thread::CleanUp() | 27 // (1) Thread::CleanUp() |
| 28 // (2) MessageLoop::~MessageLoop | 28 // (2) MessageLoop::~MessageLoop |
| 29 // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop | 29 // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop |
| 30 class AutoThread : base::PlatformThread::Delegate { | 30 class AutoThread : base::PlatformThread::Delegate { |
| 31 public: | 31 public: |
| 32 // Used to specify the type of MessageLoop to create on the new thread. | |
| 33 // On Windows the thread may be intialized for single or multi-threaded COM. | |
| 34 enum Type { | |
|
Sergey Ulanov
2012/11/16 19:23:33
Do we really need this type? Maybe better to add i
Wez
2012/11/16 19:54:54
This class is already different enough from base::
| |
| 35 TYPE_DEFAULT, | |
| 36 TYPE_IO, | |
| 37 TYPE_UI, | |
| 38 #if defined(OS_WIN) | |
| 39 TYPE_UI_COM_STA, | |
| 40 TYPE_UI_COM_MTA | |
|
alexeypa (please no reviews)
2012/11/16 18:16:09
MTA does not need a message pump AFAIR. It is not
Wez
2012/11/16 19:54:54
Quite right; fixed.
| |
| 41 #endif | |
| 42 }; | |
| 43 | |
| 32 // Create an AutoThread with the specified message-loop |type| and |name|. | 44 // Create an AutoThread with the specified message-loop |type| and |name|. |
| 33 // The supplied AutoThreadTaskRunner will be used to join and delete the | 45 // The supplied AutoThreadTaskRunner will be used to join and delete the |
| 34 // new thread when no references to it remain. | 46 // new thread when no references to it remain. |
| 35 static scoped_refptr<AutoThreadTaskRunner> CreateWithType( | 47 static scoped_refptr<AutoThreadTaskRunner> CreateWithType( |
|
alexeypa (please no reviews)
2012/11/16 18:16:09
Add a variant CreateWithTypeAndInitializeCom?
Wez
2012/11/16 19:54:54
If I switch the interface to the ugly init_com_wit
| |
| 36 const char* name, | 48 const char* name, |
| 37 scoped_refptr<AutoThreadTaskRunner> joiner, | 49 scoped_refptr<AutoThreadTaskRunner> joiner, |
| 38 MessageLoop::Type type); | 50 Type type); |
| 39 static scoped_refptr<AutoThreadTaskRunner> Create( | 51 static scoped_refptr<AutoThreadTaskRunner> Create( |
| 40 const char* name, | 52 const char* name, |
| 41 scoped_refptr<AutoThreadTaskRunner> joiner); | 53 scoped_refptr<AutoThreadTaskRunner> joiner); |
| 42 | 54 |
| 43 // Construct the AutoThread. |name| identifies the thread for debugging. | 55 // Construct the AutoThread. |name| identifies the thread for debugging. |
| 44 explicit AutoThread(const char* name); | 56 explicit AutoThread(const char* name); |
| 45 | 57 |
| 46 // Waits for the thread to exit, and then destroys it. | 58 // Waits for the thread to exit, and then destroys it. |
| 47 virtual ~AutoThread(); | 59 virtual ~AutoThread(); |
| 48 | 60 |
| 49 // Starts a the thread, running the specified type of MessageLoop. Returns | 61 // Starts a the thread, running the specified type of MessageLoop. Returns |
| 50 // an AutoThreadTaskRunner through which tasks may be posted to the thread | 62 // an AutoThreadTaskRunner through which tasks may be posted to the thread |
| 51 // if successful, or NULL on failure. | 63 // if successful, or NULL on failure. |
| 52 // | 64 // |
| 53 // Note: This function can't be called on Windows with the loader lock held; | 65 // 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() | 66 // i.e. during a DllMain, global object construction or destruction, atexit() |
| 55 // callback. | 67 // callback. |
| 56 // | 68 // |
| 57 // NOTE: You must not call this MessageLoop's Quit method directly. The | 69 // NOTE: You must not call this MessageLoop's Quit method directly. The |
| 58 // thread will exit when no references to the TaskRunner remain. | 70 // thread will exit when no references to the TaskRunner remain. |
| 59 scoped_refptr<AutoThreadTaskRunner> StartWithType(MessageLoop::Type type); | 71 scoped_refptr<AutoThreadTaskRunner> StartWithType(Type type); |
| 60 | 72 |
| 61 // Shorthand for StartWithType(MessageLoop::TYPE_DEFAULT). | 73 // Shorthand for StartWithType(MessageLoop::TYPE_DEFAULT). |
| 62 scoped_refptr<AutoThreadTaskRunner> Start(); | 74 scoped_refptr<AutoThreadTaskRunner> Start(); |
| 63 | 75 |
| 64 private: | 76 private: |
| 65 AutoThread(const char* name, AutoThreadTaskRunner* joiner); | 77 AutoThread(const char* name, AutoThreadTaskRunner* joiner); |
| 66 | 78 |
| 67 void QuitThread(scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 79 void QuitThread(scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 68 void JoinAndDeleteThread(); | 80 void JoinAndDeleteThread(); |
| 69 | 81 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 86 | 98 |
| 87 // AutoThreadTaskRunner to post a task to to join & delete this thread. | 99 // AutoThreadTaskRunner to post a task to to join & delete this thread. |
| 88 scoped_refptr<AutoThreadTaskRunner> joiner_; | 100 scoped_refptr<AutoThreadTaskRunner> joiner_; |
| 89 | 101 |
| 90 DISALLOW_COPY_AND_ASSIGN(AutoThread); | 102 DISALLOW_COPY_AND_ASSIGN(AutoThread); |
| 91 }; | 103 }; |
| 92 | 104 |
| 93 } // namespace remoting | 105 } // namespace remoting |
| 94 | 106 |
| 95 #endif // REMOTING_AUTO_THREAD_H_ | 107 #endif // REMOTING_AUTO_THREAD_H_ |
| OLD | NEW |