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/memory/scoped_callback_factory.h

Issue 6714032: Move some files in base to base/memory. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: only base Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // ScopedCallbackFactory helps in cases where you wish to allocate a Callback 5 // ScopedCallbackFactory helps in cases where you wish to allocate a Callback
6 // (see base/callback.h), but need to prevent any pending callbacks from 6 // (see base/callback.h), but need to prevent any pending callbacks from
7 // executing when your object gets destroyed. 7 // executing when your object gets destroyed.
8 // 8 //
9 // EXAMPLE: 9 // EXAMPLE:
10 // 10 //
(...skipping 15 matching lines...) Expand all
26 // 26 //
27 // base::ScopedCallbackFactory<MyClass> factory_; 27 // base::ScopedCallbackFactory<MyClass> factory_;
28 // }; 28 // };
29 // 29 //
30 // In the above example, the Process function calls GatherDataAsynchronously to 30 // In the above example, the Process function calls GatherDataAsynchronously to
31 // kick off some asynchronous processing that upon completion will notify a 31 // kick off some asynchronous processing that upon completion will notify a
32 // callback. If in the meantime, the MyClass instance is destroyed, when the 32 // callback. If in the meantime, the MyClass instance is destroyed, when the
33 // callback runs, it will notice that the MyClass instance is dead, and it will 33 // callback runs, it will notice that the MyClass instance is dead, and it will
34 // avoid calling the GotData method. 34 // avoid calling the GotData method.
35 35
36 #ifndef BASE_SCOPED_CALLBACK_FACTORY_H_ 36 #ifndef BASE_MEMORY_SCOPED_CALLBACK_FACTORY_H_
37 #define BASE_SCOPED_CALLBACK_FACTORY_H_ 37 #define BASE_MEMORY_SCOPED_CALLBACK_FACTORY_H_
38 38
39 #include "base/callback.h" 39 #include "base/callback.h"
40 #include "base/weak_ptr.h" 40 #include "base/memory/weak_ptr.h"
41 41
42 namespace base { 42 namespace base {
43 43
44 template <class T> 44 template <class T>
45 class ScopedCallbackFactory { 45 class ScopedCallbackFactory {
46 public: 46 public:
47 explicit ScopedCallbackFactory(T* obj) : weak_factory_(obj) { 47 explicit ScopedCallbackFactory(T* obj) : weak_factory_(obj) {
48 } 48 }
49 49
50 typename Callback0::Type* NewCallback( 50 typename Callback0::Type* NewCallback(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 return; 123 return;
124 DispatchToMethod(this->obj_.get(), this->meth_, params); 124 DispatchToMethod(this->obj_.get(), this->meth_, params);
125 } 125 }
126 }; 126 };
127 127
128 WeakPtrFactory<T> weak_factory_; 128 WeakPtrFactory<T> weak_factory_;
129 }; 129 };
130 130
131 } // namespace base 131 } // namespace base
132 132
133 #endif // BASE_SCOPED_CALLBACK_FACTORY_H_ 133 #endif // BASE_MEMORY_SCOPED_CALLBACK_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698