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

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

Issue 302633009: Add example to MessageLoop::ReleaseSoon comment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 void DeleteSoon(const tracked_objects::Location& from_here, const T* object) { 200 void DeleteSoon(const tracked_objects::Location& from_here, const T* object) {
201 base::subtle::DeleteHelperInternal<T, void>::DeleteViaSequencedTaskRunner( 201 base::subtle::DeleteHelperInternal<T, void>::DeleteViaSequencedTaskRunner(
202 this, from_here, object); 202 this, from_here, object);
203 } 203 }
204 204
205 // A variant on PostTask that releases the given reference counted object 205 // A variant on PostTask that releases the given reference counted object
206 // (by calling its Release method). This is useful if the object needs to 206 // (by calling its Release method). This is useful if the object needs to
207 // live until the next run of the MessageLoop, or if the object needs to be 207 // live until the next run of the MessageLoop, or if the object needs to be
208 // released on a particular thread. 208 // released on a particular thread.
209 // 209 //
210 // A common pattern is to manually increment the object's reference count
211 // (AddRef), issue a ReleaseSoon, then clear the pointer. The reference count
212 // is incremented manually to ensure clearing the pointer does not trigger a
213 // delete and to account for the upcoming decrement (ReleaseSoon). For
214 // example:
215 //
216 // scoped_refptr<Foo> foo = ...
217 // foo.AddRef();
218 // message_loop->ReleaseSoon(foo.get());
219 // foo = NULL;
220 //
210 // 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
211 // released (and thus possibly deleted) on the thread that executes 222 // released (and thus possibly deleted) on the thread that executes
212 // 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
213 // PostDelayedTask(FROM_HERE, ), then T MUST inherit from 224 // PostDelayedTask(FROM_HERE, ), then T MUST inherit from
214 // RefCountedThreadSafe<T>! 225 // RefCountedThreadSafe<T>!
215 template <class T> 226 template <class T>
216 void ReleaseSoon(const tracked_objects::Location& from_here, 227 void ReleaseSoon(const tracked_objects::Location& from_here,
217 const T* object) { 228 const T* object) {
218 base::subtle::ReleaseHelperInternal<T, void>::ReleaseViaSequencedTaskRunner( 229 base::subtle::ReleaseHelperInternal<T, void>::ReleaseViaSequencedTaskRunner(
219 this, from_here, object); 230 this, from_here, object);
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 641
631 // Do not add any member variables to MessageLoopForIO! This is important b/c 642 // Do not add any member variables to MessageLoopForIO! This is important b/c
632 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra 643 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra
633 // data that you need should be stored on the MessageLoop's pump_ instance. 644 // data that you need should be stored on the MessageLoop's pump_ instance.
634 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), 645 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
635 MessageLoopForIO_should_not_have_extra_member_variables); 646 MessageLoopForIO_should_not_have_extra_member_variables);
636 647
637 } // namespace base 648 } // namespace base
638 649
639 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ 650 #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