Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: base/threading/thread.h

Issue 61643006: Adds the ability for MessageLoop to take a MessagePump (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 BASE_THREADING_THREAD_H_ 5 #ifndef BASE_THREADING_THREAD_H_
6 #define BASE_THREADING_THREAD_H_ 6 #define BASE_THREADING_THREAD_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_loop_proxy.h" 12 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 class MessagePump;
18
17 // A simple thread abstraction that establishes a MessageLoop on a new thread. 19 // A simple thread abstraction that establishes a MessageLoop on a new thread.
18 // The consumer uses the MessageLoop of the thread to cause code to execute on 20 // The consumer uses the MessageLoop of the thread to cause code to execute on
19 // the thread. When this object is destroyed the thread is terminated. All 21 // the thread. When this object is destroyed the thread is terminated. All
20 // pending tasks queued on the thread's message loop will run to completion 22 // pending tasks queued on the thread's message loop will run to completion
21 // before the thread is terminated. 23 // before the thread is terminated.
22 // 24 //
23 // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). 25 // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread().
24 // 26 //
25 // After the thread is stopped, the destruction sequence is: 27 // After the thread is stopped, the destruction sequence is:
26 // 28 //
27 // (1) Thread::CleanUp() 29 // (1) Thread::CleanUp()
28 // (2) MessageLoop::~MessageLoop 30 // (2) MessageLoop::~MessageLoop
29 // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop 31 // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop
30 class BASE_EXPORT Thread : PlatformThread::Delegate { 32 class BASE_EXPORT Thread : PlatformThread::Delegate {
31 public: 33 public:
32 struct Options { 34 struct Options {
33 Options() : message_loop_type(MessageLoop::TYPE_DEFAULT), stack_size(0) {} 35 Options()
36 : message_loop_type(MessageLoop::TYPE_DEFAULT),
37 message_pump(NULL),
38 stack_size(0) {
39 }
34 Options(MessageLoop::Type type, size_t size) 40 Options(MessageLoop::Type type, size_t size)
35 : message_loop_type(type), stack_size(size) {} 41 : message_loop_type(type),
42 message_pump(NULL),
43 stack_size(size) {}
36 44
37 // Specifies the type of message loop that will be allocated on the thread. 45 // Specifies the type of message loop that will be allocated on the thread.
38 MessageLoop::Type message_loop_type; 46 MessageLoop::Type message_loop_type;
39 47
48 // If non-null this is used as the MessagePump for the Thread's MessageLoop.
49 // MessageLoop takes ownership of this.
50 MessagePump* message_pump;
darin (slow to review) 2013/11/07 00:17:54 Perhaps it would be nice to use scoped_ptr here as
51
40 // Specifies the maximum stack size that the thread is allowed to use. 52 // Specifies the maximum stack size that the thread is allowed to use.
41 // This does not necessarily correspond to the thread's initial stack size. 53 // This does not necessarily correspond to the thread's initial stack size.
42 // A value of 0 indicates that the default maximum should be used. 54 // A value of 0 indicates that the default maximum should be used.
43 size_t stack_size; 55 size_t stack_size;
44 }; 56 };
45 57
46 // Constructor. 58 // Constructor.
47 // name is a display string to identify the thread. 59 // name is a display string to identify the thread.
48 explicit Thread(const char* name); 60 explicit Thread(const char* name);
49 61
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 std::string name_; 219 std::string name_;
208 220
209 friend void ThreadQuitHelper(); 221 friend void ThreadQuitHelper();
210 222
211 DISALLOW_COPY_AND_ASSIGN(Thread); 223 DISALLOW_COPY_AND_ASSIGN(Thread);
212 }; 224 };
213 225
214 } // namespace base 226 } // namespace base
215 227
216 #endif // BASE_THREADING_THREAD_H_ 228 #endif // BASE_THREADING_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698