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

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

Issue 615693002: Improve MessageLoop's comments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 | « no previous file | no next file » | 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 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 void PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 187 void PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
188 const Closure& task, 188 const Closure& task,
189 TimeDelta delay); 189 TimeDelta delay);
190 190
191 // A variant on PostTask that deletes the given object. This is useful 191 // A variant on PostTask that deletes the given object. This is useful
192 // if the object needs to live until the next run of the MessageLoop (for 192 // if the object needs to live until the next run of the MessageLoop (for
193 // example, deleting a RenderProcessHost from within an IPC callback is not 193 // example, deleting a RenderProcessHost from within an IPC callback is not
194 // good). 194 // good).
195 // 195 //
196 // NOTE: This method may be called on any thread. The object will be deleted 196 // NOTE: This method may be called on any thread. The object will be deleted
197 // on the thread that executes MessageLoop::Run(). If this is not the same 197 // on the thread that executes MessageLoop::Run().
198 // as the thread that calls PostDelayedTask(FROM_HERE, ), then T MUST inherit
199 // from RefCountedThreadSafe<T>!
200 template <class T> 198 template <class T>
201 void DeleteSoon(const tracked_objects::Location& from_here, const T* object) { 199 void DeleteSoon(const tracked_objects::Location& from_here, const T* object) {
202 base::subtle::DeleteHelperInternal<T, void>::DeleteViaSequencedTaskRunner( 200 base::subtle::DeleteHelperInternal<T, void>::DeleteViaSequencedTaskRunner(
203 this, from_here, object); 201 this, from_here, object);
204 } 202 }
205 203
206 // A variant on PostTask that releases the given reference counted object 204 // A variant on PostTask that releases the given reference counted object
207 // (by calling its Release method). This is useful if the object needs to 205 // (by calling its Release method). This is useful if the object needs to
208 // live until the next run of the MessageLoop, or if the object needs to be 206 // live until the next run of the MessageLoop, or if the object needs to be
209 // released on a particular thread. 207 // released on a particular thread.
210 // 208 //
211 // A common pattern is to manually increment the object's reference count 209 // A common pattern is to manually increment the object's reference count
212 // (AddRef), clear the pointer, then issue a ReleaseSoon. The reference count 210 // (AddRef), clear the pointer, then issue a ReleaseSoon. The reference count
213 // is incremented manually to ensure clearing the pointer does not trigger a 211 // is incremented manually to ensure clearing the pointer does not trigger a
214 // delete and to account for the upcoming decrement (ReleaseSoon). For 212 // delete and to account for the upcoming decrement (ReleaseSoon). For
215 // example: 213 // example:
216 // 214 //
217 // scoped_refptr<Foo> foo = ... 215 // scoped_refptr<Foo> foo = ...
218 // foo->AddRef(); 216 // foo->AddRef();
219 // Foo* raw_foo = foo.get(); 217 // Foo* raw_foo = foo.get();
220 // foo = NULL; 218 // foo = NULL;
221 // message_loop->ReleaseSoon(raw_foo); 219 // message_loop->ReleaseSoon(raw_foo);
222 // 220 //
223 // NOTE: This method may be called on any thread. The object will be 221 // NOTE: This method may be called on any thread. The object will be
224 // released (and thus possibly deleted) on the thread that executes 222 // released (and thus possibly deleted) on the thread that executes
225 // MessageLoop::Run(). If this is not the same as the thread that calls 223 // MessageLoop::Run(). If this is not the same as the thread that calls
226 // PostDelayedTask(FROM_HERE, ), then T MUST inherit from 224 // ReleaseSoon(FROM_HERE, ), then T MUST inherit from
227 // RefCountedThreadSafe<T>! 225 // RefCountedThreadSafe<T>!
228 template <class T> 226 template <class T>
229 void ReleaseSoon(const tracked_objects::Location& from_here, 227 void ReleaseSoon(const tracked_objects::Location& from_here,
230 const T* object) { 228 const T* object) {
231 base::subtle::ReleaseHelperInternal<T, void>::ReleaseViaSequencedTaskRunner( 229 base::subtle::ReleaseHelperInternal<T, void>::ReleaseViaSequencedTaskRunner(
232 this, from_here, object); 230 this, from_here, object);
233 } 231 }
234 232
235 // Deprecated: use RunLoop instead. 233 // Deprecated: use RunLoop instead.
236 // Run the message loop. 234 // Run the message loop.
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 648
651 // Do not add any member variables to MessageLoopForIO! This is important b/c 649 // Do not add any member variables to MessageLoopForIO! This is important b/c
652 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 650 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
653 // data that you need should be stored on the MessageLoop's pump_ instance. 651 // data that you need should be stored on the MessageLoop's pump_ instance.
654 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 652 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
655 MessageLoopForIO_should_not_have_extra_member_variables); 653 MessageLoopForIO_should_not_have_extra_member_variables);
656 654
657 } // namespace base 655 } // namespace base
658 656
659 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 657 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698