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

Side by Side Diff: base/callback_internal.h

Issue 22877038: Add a CallbackRegistry class to base/ to manage callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better documentation of test invariants Created 7 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file contains utility functions and classes that help the 5 // This file contains utility functions and classes that help the
6 // implementation, and management of the Callback objects. 6 // implementation, and management of the Callback objects.
7 7
8 #ifndef BASE_CALLBACK_INTERNAL_H_ 8 #ifndef BASE_CALLBACK_INTERNAL_H_
9 #define BASE_CALLBACK_INTERNAL_H_ 9 #define BASE_CALLBACK_INTERNAL_H_
10 10
11 #include <stddef.h> 11 #include <stddef.h>
12 12
13 #include "base/base_export.h" 13 #include "base/base_export.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 16
17 template <typename T> 17 template <typename T>
18 class ScopedVector; 18 class ScopedVector;
19 19
20 namespace base { 20 namespace base {
21 namespace internal { 21 namespace internal {
22 22
23 class CallbackListImpl;
24
23 // BindStateBase is used to provide an opaque handle that the Callback 25 // BindStateBase is used to provide an opaque handle that the Callback
24 // class can use to represent a function object with bound arguments. It 26 // class can use to represent a function object with bound arguments. It
25 // behaves as an existential type that is used by a corresponding 27 // behaves as an existential type that is used by a corresponding
26 // DoInvoke function to perform the function execution. This allows 28 // DoInvoke function to perform the function execution. This allows
27 // us to shield the Callback class from the types of the bound argument via 29 // us to shield the Callback class from the types of the bound argument via
28 // "type erasure." 30 // "type erasure."
29 class BindStateBase : public RefCountedThreadSafe<BindStateBase> { 31 class BindStateBase : public RefCountedThreadSafe<BindStateBase> {
30 protected: 32 protected:
31 friend class RefCountedThreadSafe<BindStateBase>; 33 friend class RefCountedThreadSafe<BindStateBase>;
32 virtual ~BindStateBase() {} 34 virtual ~BindStateBase() {}
(...skipping 25 matching lines...) Expand all
58 // derived Callback templates makes for much nicer compiler errors. 60 // derived Callback templates makes for much nicer compiler errors.
59 explicit CallbackBase(BindStateBase* bind_state); 61 explicit CallbackBase(BindStateBase* bind_state);
60 62
61 // Force the destructor to be instantiated inside this translation unit so 63 // Force the destructor to be instantiated inside this translation unit so
62 // that our subclasses will not get inlined versions. Avoids more template 64 // that our subclasses will not get inlined versions. Avoids more template
63 // bloat. 65 // bloat.
64 ~CallbackBase(); 66 ~CallbackBase();
65 67
66 scoped_refptr<BindStateBase> bind_state_; 68 scoped_refptr<BindStateBase> bind_state_;
67 InvokeFuncStorage polymorphic_invoke_; 69 InvokeFuncStorage polymorphic_invoke_;
70
71 private:
72 friend class CallbackListImpl;
68 }; 73 };
69 74
70 // This is a typetraits object that's used to take an argument type, and 75 // This is a typetraits object that's used to take an argument type, and
71 // extract a suitable type for storing and forwarding arguments. 76 // extract a suitable type for storing and forwarding arguments.
72 // 77 //
73 // In particular, it strips off references, and converts arrays to 78 // In particular, it strips off references, and converts arrays to
74 // pointers for storage; and it avoids accidentally trying to create a 79 // pointers for storage; and it avoids accidentally trying to create a
75 // "reference of a reference" if the argument is a reference type. 80 // "reference of a reference" if the argument is a reference type.
76 // 81 //
77 // This array type becomes an issue for storage because we are passing bound 82 // This array type becomes an issue for storage because we are passing bound
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return p.Pass(); 180 return p.Pass();
176 } 181 }
177 182
178 template <typename T> 183 template <typename T>
179 ScopedVector<T> CallbackForward(ScopedVector<T>& p) { return p.Pass(); } 184 ScopedVector<T> CallbackForward(ScopedVector<T>& p) { return p.Pass(); }
180 185
181 } // namespace internal 186 } // namespace internal
182 } // namespace base 187 } // namespace base
183 188
184 #endif // BASE_CALLBACK_INTERNAL_H_ 189 #endif // BASE_CALLBACK_INTERNAL_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/callback_list.h » ('j') | base/callback_list.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698