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

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

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
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 #include "base/threading/thread.h" 5 #include "base/threading/thread.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
10 #include "base/threading/thread_id_name_manager.h" 10 #include "base/threading/thread_id_name_manager.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const Thread::Options& options; 42 const Thread::Options& options;
43 43
44 // Used to synchronize thread startup. 44 // Used to synchronize thread startup.
45 WaitableEvent event; 45 WaitableEvent event;
46 46
47 explicit StartupData(const Options& opt) 47 explicit StartupData(const Options& opt)
48 : options(opt), 48 : options(opt),
49 event(false, false) {} 49 event(false, false) {}
50 }; 50 };
51 51
52 Thread::Options::Options()
53 : message_loop_type(MessageLoop::TYPE_DEFAULT),
54 stack_size(0) {
55 }
56
57 Thread::Options::Options(MessageLoop::Type type,
58 size_t size)
59 : message_loop_type(type),
60 stack_size(size) {
61 }
62
63 Thread::Options::~Options() {
64 }
65
52 Thread::Thread(const char* name) 66 Thread::Thread(const char* name)
53 : 67 :
54 #if defined(OS_WIN) 68 #if defined(OS_WIN)
55 com_status_(NONE), 69 com_status_(NONE),
56 #endif 70 #endif
57 started_(false), 71 started_(false),
58 stopping_(false), 72 stopping_(false),
59 running_(false), 73 running_(false),
60 startup_data_(NULL), 74 startup_data_(NULL),
61 thread_(0), 75 thread_(0),
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 #ifndef NDEBUG 181 #ifndef NDEBUG
168 quit_properly = lazy_tls_bool.Pointer()->Get(); 182 quit_properly = lazy_tls_bool.Pointer()->Get();
169 #endif 183 #endif
170 return quit_properly; 184 return quit_properly;
171 } 185 }
172 186
173 void Thread::ThreadMain() { 187 void Thread::ThreadMain() {
174 { 188 {
175 // The message loop for this thread. 189 // The message loop for this thread.
176 // Allocated on the heap to centralize any leak reports at this line. 190 // Allocated on the heap to centralize any leak reports at this line.
177 scoped_ptr<MessageLoop> message_loop( 191 scoped_ptr<MessageLoop> message_loop;
178 new MessageLoop(startup_data_->options.message_loop_type)); 192 if (!startup_data_->options.message_pump_factory.is_null()) {
193 message_loop.reset(
194 new MessageLoop(startup_data_->options.message_pump_factory.Run()));
195 } else {
196 message_loop.reset(
197 new MessageLoop(startup_data_->options.message_loop_type));
198 }
179 199
180 // Complete the initialization of our Thread object. 200 // Complete the initialization of our Thread object.
181 thread_id_ = PlatformThread::CurrentId(); 201 thread_id_ = PlatformThread::CurrentId();
182 PlatformThread::SetName(name_.c_str()); 202 PlatformThread::SetName(name_.c_str());
183 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. 203 ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
184 message_loop->set_thread_name(name_); 204 message_loop->set_thread_name(name_);
185 message_loop_ = message_loop.get(); 205 message_loop_ = message_loop.get();
186 206
187 #if defined(OS_WIN) 207 #if defined(OS_WIN)
188 scoped_ptr<win::ScopedCOMInitializer> com_initializer; 208 scoped_ptr<win::ScopedCOMInitializer> com_initializer;
(...skipping 25 matching lines...) Expand all
214 234
215 // Assert that MessageLoop::Quit was called by ThreadQuitHelper. 235 // Assert that MessageLoop::Quit was called by ThreadQuitHelper.
216 DCHECK(GetThreadWasQuitProperly()); 236 DCHECK(GetThreadWasQuitProperly());
217 237
218 // We can't receive messages anymore. 238 // We can't receive messages anymore.
219 message_loop_ = NULL; 239 message_loop_ = NULL;
220 } 240 }
221 } 241 }
222 242
223 } // namespace base 243 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/thread.h ('k') | chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698