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

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: 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // A few events we handle (kindred to messages), and used to profile actions. 80 // A few events we handle (kindred to messages), and used to profile actions.
81 VALUE_TO_NUMBER_AND_NAME(kTaskRunEvent) 81 VALUE_TO_NUMBER_AND_NAME(kTaskRunEvent)
82 VALUE_TO_NUMBER_AND_NAME(kTimerEvent) 82 VALUE_TO_NUMBER_AND_NAME(kTimerEvent)
83 83
84 {-1, NULL} // The list must be null terminated, per API to histogram. 84 {-1, NULL} // The list must be null terminated, per API to histogram.
85 }; 85 };
86 86
87 bool enable_histogrammer_ = false; 87 bool enable_histogrammer_ = false;
88 88
89 MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL; 89 MessageLoop::MessagePumpFactory* message_pump_for_ui_factory_ = NULL;
90
darin (slow to review) 2014/03/05 00:37:05 nit: I think it was better to have a new line here
91 // Returns true if MessagePump::ScheduleWork() must be called one 90 // Returns true if MessagePump::ScheduleWork() must be called one
92 // time for every task that is added to the MessageLoop incoming queue. 91 // time for every task that is added to the MessageLoop incoming queue.
93 bool AlwaysNotifyPump(MessageLoop::Type type) { 92 bool AlwaysNotifyPump(MessageLoop::Type type) {
94 #if defined(OS_ANDROID) 93 #if defined(OS_ANDROID)
95 return type == MessageLoop::TYPE_UI || type == MessageLoop::TYPE_JAVA; 94 return type == MessageLoop::TYPE_UI || type == MessageLoop::TYPE_JAVA;
96 #else 95 #else
97 return false; 96 return false;
98 #endif 97 #endif
99 } 98 }
100 99
(...skipping 15 matching lines...) Expand all
116 MessageLoop::MessageLoop(Type type) 115 MessageLoop::MessageLoop(Type type)
117 : type_(type), 116 : type_(type),
118 nestable_tasks_allowed_(true), 117 nestable_tasks_allowed_(true),
119 #if defined(OS_WIN) 118 #if defined(OS_WIN)
120 os_modal_loop_(false), 119 os_modal_loop_(false),
121 #endif // OS_WIN 120 #endif // OS_WIN
122 message_histogram_(NULL), 121 message_histogram_(NULL),
123 run_loop_(NULL) { 122 run_loop_(NULL) {
124 Init(); 123 Init();
125 124
126 pump_.reset(CreateMessagePumpForType(type)); 125 pump_.reset(CreateMessagePumpForType(type).release());
darin (slow to review) 2014/03/05 00:37:05 nit: you could also write: pump_ = CreateMessag
127 } 126 }
128 127
129 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump) 128 MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump)
130 : pump_(pump.Pass()), 129 : pump_(pump.Pass()),
131 type_(TYPE_CUSTOM), 130 type_(TYPE_CUSTOM),
132 nestable_tasks_allowed_(true), 131 nestable_tasks_allowed_(true),
133 #if defined(OS_WIN) 132 #if defined(OS_WIN)
134 os_modal_loop_(false), 133 os_modal_loop_(false),
135 #endif // OS_WIN 134 #endif // OS_WIN
136 message_histogram_(NULL), 135 message_histogram_(NULL),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // DCHECK(loop) << "Ouch, did you forget to initialize me?"; 182 // DCHECK(loop) << "Ouch, did you forget to initialize me?";
184 return lazy_tls_ptr.Pointer()->Get(); 183 return lazy_tls_ptr.Pointer()->Get();
185 } 184 }
186 185
187 // static 186 // static
188 void MessageLoop::EnableHistogrammer(bool enable) { 187 void MessageLoop::EnableHistogrammer(bool enable) {
189 enable_histogrammer_ = enable; 188 enable_histogrammer_ = enable;
190 } 189 }
191 190
192 // static 191 // static
193 bool MessageLoop::InitMessagePumpForUIFactory(MessagePumpFactory* factory) { 192 bool MessageLoop::InitMessagePumpForUIFactory(scoped_ptr<MessagePumpFactory>
193 factory) {
194 if (message_pump_for_ui_factory_) 194 if (message_pump_for_ui_factory_)
195 return false; 195 return false;
196 196
197 message_pump_for_ui_factory_ = factory; 197 message_pump_for_ui_factory_ = factory.release();
198 return true; 198 return true;
199 } 199 }
200 200
201 // static 201 // static
202 MessagePump* MessageLoop::CreateMessagePumpForType(Type type) { 202 scoped_ptr<MessagePump> MessageLoop::CreateMessagePumpForType(Type type) {
203 // TODO(rvargas): Get rid of the OS guards. 203 // TODO(rvargas): Get rid of the OS guards.
204 #if defined(OS_WIN) 204 #if defined(OS_WIN)
205 #define MESSAGE_PUMP_UI new MessagePumpForUI() 205 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(new MessagePumpForUI())
206 #define MESSAGE_PUMP_IO new MessagePumpForIO() 206 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpForIO())
207 #elif defined(OS_IOS) 207 #elif defined(OS_IOS)
208 #define MESSAGE_PUMP_UI MessagePumpMac::Create() 208 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(MessagePumpMac::Create())
209 #define MESSAGE_PUMP_IO new MessagePumpIOSForIO() 209 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpIOSForIO())
210 #elif defined(OS_MACOSX) 210 #elif defined(OS_MACOSX)
211 #define MESSAGE_PUMP_UI MessagePumpMac::Create() 211 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(MessagePumpMac::Create())
212 #define MESSAGE_PUMP_IO new MessagePumpLibevent() 212 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpLibevent())
213 #elif defined(OS_NACL) 213 #elif defined(OS_NACL)
214 // Currently NaCl doesn't have a UI MessageLoop. 214 // Currently NaCl doesn't have a UI MessageLoop.
215 // TODO(abarth): Figure out if we need this. 215 // TODO(abarth): Figure out if we need this.
216 #define MESSAGE_PUMP_UI NULL 216 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>()
217 // ipc_channel_nacl.cc uses a worker thread to do socket reads currently, and 217 // ipc_channel_nacl.cc uses a worker thread to do socket reads currently, and
218 // doesn't require extra support for watching file descriptors. 218 // doesn't require extra support for watching file descriptors.
219 #define MESSAGE_PUMP_IO new MessagePumpDefault() 219 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpDefault())
220 #elif defined(OS_POSIX) // POSIX but not MACOSX. 220 #elif defined(OS_POSIX) // POSIX but not MACOSX.
221 #define MESSAGE_PUMP_UI new MessagePumpForUI() 221 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(new MessagePumpForUI())
222 #define MESSAGE_PUMP_IO new MessagePumpLibevent() 222 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpLibevent())
223 #else 223 #else
224 #error Not implemented 224 #error Not implemented
225 #endif 225 #endif
226 226
227 if (type == MessageLoop::TYPE_UI) { 227 if (type == MessageLoop::TYPE_UI) {
228 if (message_pump_for_ui_factory_) 228 if (message_pump_for_ui_factory_)
229 return message_pump_for_ui_factory_(); 229 return message_pump_for_ui_factory_();
230 return MESSAGE_PUMP_UI; 230 return MESSAGE_PUMP_UI;
231 } 231 }
232 if (type == MessageLoop::TYPE_IO) 232 if (type == MessageLoop::TYPE_IO)
233 return MESSAGE_PUMP_IO; 233 return MESSAGE_PUMP_IO;
234 #if defined(TOOLKIT_GTK) 234 #if defined(TOOLKIT_GTK)
235 if (type == MessageLoop::TYPE_GPU) 235 if (type == MessageLoop::TYPE_GPU)
236 return new MessagePumpX11(); 236 return new MessagePumpX11();
237 #endif 237 #endif
238 #if defined(OS_ANDROID) 238 #if defined(OS_ANDROID)
239 if (type == MessageLoop::TYPE_JAVA) 239 if (type == MessageLoop::TYPE_JAVA)
240 return MESSAGE_PUMP_UI; 240 return MESSAGE_PUMP_UI;
241 #endif 241 #endif
242 DCHECK_EQ(MessageLoop::TYPE_DEFAULT, type); 242 DCHECK_EQ(MessageLoop::TYPE_DEFAULT, type);
243 return new MessagePumpDefault(); 243 return scoped_ptr<MessagePump>(new MessagePumpDefault());
244 } 244 }
245 245
246 void MessageLoop::AddDestructionObserver( 246 void MessageLoop::AddDestructionObserver(
247 DestructionObserver* destruction_observer) { 247 DestructionObserver* destruction_observer) {
248 DCHECK_EQ(this, current()); 248 DCHECK_EQ(this, current());
249 destruction_observers_.AddObserver(destruction_observer); 249 destruction_observers_.AddObserver(destruction_observer);
250 } 250 }
251 251
252 void MessageLoop::RemoveDestructionObserver( 252 void MessageLoop::RemoveDestructionObserver(
253 DestructionObserver* destruction_observer) { 253 DestructionObserver* destruction_observer) {
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 fd, 718 fd,
719 persistent, 719 persistent,
720 mode, 720 mode,
721 controller, 721 controller,
722 delegate); 722 delegate);
723 } 723 }
724 724
725 #endif 725 #endif
726 726
727 } // namespace base 727 } // 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