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

Side by Side Diff: base/message_loop/message_loop.cc

Issue 185413019: Used scoped_ptr in InitMessagePumpForUIFactory and CreateMessagePumpForType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes in accordance to build fail for linux chromeos Created 6 years, 9 months 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
« no previous file with comments | « base/message_loop/message_loop.h ('k') | base/message_loop/message_loop_unittest.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 MessageLoop::MessageLoop(Type type) 118 MessageLoop::MessageLoop(Type type)
119 : type_(type), 119 : type_(type),
120 nestable_tasks_allowed_(true), 120 nestable_tasks_allowed_(true),
121 #if defined(OS_WIN) 121 #if defined(OS_WIN)
122 os_modal_loop_(false), 122 os_modal_loop_(false),
123 #endif // OS_WIN 123 #endif // OS_WIN
124 message_histogram_(NULL), 124 message_histogram_(NULL),
125 run_loop_(NULL) { 125 run_loop_(NULL) {
126 Init(); 126 Init();
127 127
128 pump_.reset(CreateMessagePumpForType(type)); 128 pump_ = CreateMessagePumpForType(type).Pass();
129 } 129 }
130 130
131 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump) 131 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump)
132 : pump_(pump.Pass()), 132 : pump_(pump.Pass()),
133 type_(TYPE_CUSTOM), 133 type_(TYPE_CUSTOM),
134 nestable_tasks_allowed_(true), 134 nestable_tasks_allowed_(true),
135 #if defined(OS_WIN) 135 #if defined(OS_WIN)
136 os_modal_loop_(false), 136 os_modal_loop_(false),
137 #endif // OS_WIN 137 #endif // OS_WIN
138 message_histogram_(NULL), 138 message_histogram_(NULL),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // static 194 // static
195 bool MessageLoop::InitMessagePumpForUIFactory(MessagePumpFactory* factory) { 195 bool MessageLoop::InitMessagePumpForUIFactory(MessagePumpFactory* factory) {
196 if (message_pump_for_ui_factory_) 196 if (message_pump_for_ui_factory_)
197 return false; 197 return false;
198 198
199 message_pump_for_ui_factory_ = factory; 199 message_pump_for_ui_factory_ = factory;
200 return true; 200 return true;
201 } 201 }
202 202
203 // static 203 // static
204 MessagePump* MessageLoop::CreateMessagePumpForType(Type type) { 204 scoped_ptr<MessagePump> MessageLoop::CreateMessagePumpForType(Type type) {
205 // TODO(rvargas): Get rid of the OS guards. 205 // TODO(rvargas): Get rid of the OS guards.
206 #if defined(OS_WIN) 206 #if defined(OS_WIN)
207 #define MESSAGE_PUMP_UI new MessagePumpForUI() 207 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(new MessagePumpForUI())
208 #define MESSAGE_PUMP_IO new MessagePumpForIO() 208 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpForIO())
209 #elif defined(OS_IOS) 209 #elif defined(OS_IOS)
210 #define MESSAGE_PUMP_UI MessagePumpMac::Create() 210 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(MessagePumpMac::Create())
211 #define MESSAGE_PUMP_IO new MessagePumpIOSForIO() 211 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpIOSForIO())
212 #elif defined(OS_MACOSX) 212 #elif defined(OS_MACOSX)
213 #define MESSAGE_PUMP_UI MessagePumpMac::Create() 213 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(MessagePumpMac::Create())
214 #define MESSAGE_PUMP_IO new MessagePumpLibevent() 214 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpLibevent())
215 #elif defined(OS_NACL) 215 #elif defined(OS_NACL)
216 // Currently NaCl doesn't have a UI MessageLoop. 216 // Currently NaCl doesn't have a UI MessageLoop.
217 // TODO(abarth): Figure out if we need this. 217 // TODO(abarth): Figure out if we need this.
218 #define MESSAGE_PUMP_UI NULL 218 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>()
219 // ipc_channel_nacl.cc uses a worker thread to do socket reads currently, and 219 // ipc_channel_nacl.cc uses a worker thread to do socket reads currently, and
220 // doesn't require extra support for watching file descriptors. 220 // doesn't require extra support for watching file descriptors.
221 #define MESSAGE_PUMP_IO new MessagePumpDefault() 221 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpDefault())
222 #elif defined(OS_POSIX) // POSIX but not MACOSX. 222 #elif defined(OS_POSIX) // POSIX but not MACOSX.
223 #define MESSAGE_PUMP_UI new MessagePumpForUI() 223 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(new MessagePumpForUI())
224 #define MESSAGE_PUMP_IO new MessagePumpLibevent() 224 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpLibevent())
225 #else 225 #else
226 #error Not implemented 226 #error Not implemented
227 #endif 227 #endif
228 228
229 if (type == MessageLoop::TYPE_UI) { 229 if (type == MessageLoop::TYPE_UI) {
230 if (message_pump_for_ui_factory_) 230 if (message_pump_for_ui_factory_)
231 return message_pump_for_ui_factory_(); 231 return message_pump_for_ui_factory_();
232 return MESSAGE_PUMP_UI; 232 return MESSAGE_PUMP_UI;
233 } 233 }
234 if (type == MessageLoop::TYPE_IO) 234 if (type == MessageLoop::TYPE_IO)
235 return MESSAGE_PUMP_IO; 235 return MESSAGE_PUMP_IO;
236 #if defined(TOOLKIT_GTK) 236 #if defined(TOOLKIT_GTK)
237 if (type == MessageLoop::TYPE_GPU) 237 if (type == MessageLoop::TYPE_GPU)
238 return new MessagePumpX11(); 238 return scoped_ptr<MessagePump>(new MessagePumpX11());
239 #endif 239 #endif
240 #if defined(OS_ANDROID) 240 #if defined(OS_ANDROID)
241 if (type == MessageLoop::TYPE_JAVA) 241 if (type == MessageLoop::TYPE_JAVA)
242 return MESSAGE_PUMP_UI; 242 return MESSAGE_PUMP_UI;
243 #endif 243 #endif
244 DCHECK_EQ(MessageLoop::TYPE_DEFAULT, type); 244 DCHECK_EQ(MessageLoop::TYPE_DEFAULT, type);
245 return new MessagePumpDefault(); 245 return scoped_ptr<MessagePump>(new MessagePumpDefault());
246 } 246 }
247 247
248 void MessageLoop::AddDestructionObserver( 248 void MessageLoop::AddDestructionObserver(
249 DestructionObserver* destruction_observer) { 249 DestructionObserver* destruction_observer) {
250 DCHECK_EQ(this, current()); 250 DCHECK_EQ(this, current());
251 destruction_observers_.AddObserver(destruction_observer); 251 destruction_observers_.AddObserver(destruction_observer);
252 } 252 }
253 253
254 void MessageLoop::RemoveDestructionObserver( 254 void MessageLoop::RemoveDestructionObserver(
255 DestructionObserver* destruction_observer) { 255 DestructionObserver* destruction_observer) {
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 fd, 720 fd,
721 persistent, 721 persistent,
722 mode, 722 mode,
723 controller, 723 controller,
724 delegate); 724 delegate);
725 } 725 }
726 726
727 #endif 727 #endif
728 728
729 } // namespace base 729 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_loop.h ('k') | base/message_loop/message_loop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698