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

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: merge 2 trunk and BASE_EXPORT 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
« no previous file with comments | « base/message_loop/message_loop.cc ('k') | base/threading/thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/callback.h"
12 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_loop_proxy.h" 14 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
14 16
15 namespace base { 17 namespace base {
16 18
19 class MessagePump;
20
17 // A simple thread abstraction that establishes a MessageLoop on a new thread. 21 // 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 22 // 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 23 // 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 24 // pending tasks queued on the thread's message loop will run to completion
21 // before the thread is terminated. 25 // before the thread is terminated.
22 // 26 //
23 // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread(). 27 // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread().
24 // 28 //
25 // After the thread is stopped, the destruction sequence is: 29 // After the thread is stopped, the destruction sequence is:
26 // 30 //
27 // (1) Thread::CleanUp() 31 // (1) Thread::CleanUp()
28 // (2) MessageLoop::~MessageLoop 32 // (2) MessageLoop::~MessageLoop
29 // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop 33 // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop
30 class BASE_EXPORT Thread : PlatformThread::Delegate { 34 class BASE_EXPORT Thread : PlatformThread::Delegate {
31 public: 35 public:
32 struct Options { 36 struct BASE_EXPORT Options {
33 Options() : message_loop_type(MessageLoop::TYPE_DEFAULT), stack_size(0) {} 37 typedef Callback<scoped_ptr<MessagePump>()> MessagePumpFactory;
34 Options(MessageLoop::Type type, size_t size) 38
35 : message_loop_type(type), stack_size(size) {} 39 Options();
40 Options(MessageLoop::Type type, size_t size);
41 ~Options();
36 42
37 // Specifies the type of message loop that will be allocated on the thread. 43 // Specifies the type of message loop that will be allocated on the thread.
44 // This is ignored if message_pump_factory.is_null() is false.
38 MessageLoop::Type message_loop_type; 45 MessageLoop::Type message_loop_type;
39 46
47 // Used to create the MessagePump for the MessageLoop. The callback is Run()
48 // on the thread. If message_pump_factory.is_null(), then a MessagePump
49 // appropriate for |message_loop_type| is created. Setting this forces the
50 // MessageLoop::Type to TYPE_CUSTOM.
51 MessagePumpFactory message_pump_factory;
52
40 // Specifies the maximum stack size that the thread is allowed to use. 53 // 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. 54 // 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. 55 // A value of 0 indicates that the default maximum should be used.
43 size_t stack_size; 56 size_t stack_size;
44 }; 57 };
45 58
46 // Constructor. 59 // Constructor.
47 // name is a display string to identify the thread. 60 // name is a display string to identify the thread.
48 explicit Thread(const char* name); 61 explicit Thread(const char* name);
49 62
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 std::string name_; 220 std::string name_;
208 221
209 friend void ThreadQuitHelper(); 222 friend void ThreadQuitHelper();
210 223
211 DISALLOW_COPY_AND_ASSIGN(Thread); 224 DISALLOW_COPY_AND_ASSIGN(Thread);
212 }; 225 };
213 226
214 } // namespace base 227 } // namespace base
215 228
216 #endif // BASE_THREADING_THREAD_H_ 229 #endif // BASE_THREADING_THREAD_H_
OLDNEW
« no previous file with comments | « base/message_loop/message_loop.cc ('k') | base/threading/thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698