OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BASE_CALLBACK_LIST_INTERNAL_H_ | |
6 #define BASE_CALLBACK_LIST_INTERNAL_H_ | |
7 | |
8 #include <limits> | |
9 #include <vector> | |
10 | |
11 #include "base/base_export.h" | |
12 #include "base/basictypes.h" | |
13 #include "base/callback_internal.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 | |
17 namespace base { | |
18 | |
19 namespace internal { | |
20 | |
21 // Holds the CallbackList methods that do not require specialization to reduce | |
22 // template bloat. | |
23 // | |
24 // This class is meant as an implementation detail for CallbackList and | |
25 // CallbackListWithDetails. Do not use it directly. | |
26 | |
27 class BASE_EXPORT CallbackListImpl { | |
28 public: | |
29 typedef std::vector<base::internal::CallbackBase*> ListType; | |
awong
2013/09/04 23:20:07
This typedef can be private.
Cait (Slow)
2013/09/06 18:41:46
Done.
| |
30 | |
31 // An iterator class that can be used to access the list of callbacks. | |
32 class Iterator { | |
33 public: | |
34 explicit Iterator(const base::WeakPtr<CallbackListImpl>& list); | |
35 | |
36 ~Iterator(); | |
37 | |
38 base::internal::CallbackBase* GetNext(); | |
39 | |
40 private: | |
41 base::WeakPtr<CallbackListImpl> list_; | |
42 size_t index_; | |
43 }; | |
44 | |
45 CallbackListImpl(); | |
46 ~CallbackListImpl(); | |
47 | |
48 // Add a callback to the list, if it is not already in there. This method | |
49 // takes ownership of |cb|, and will handle deleting it upon removal from the | |
50 // list. The returned closure is used to remove the callback from the list. | |
51 base::Closure Add(base::internal::CallbackBase* cb); | |
52 | |
53 // Delete all callbacks in the list. | |
54 void Clear(); | |
55 | |
56 // Assert that the list is empty and no iterators are active. | |
57 void AssertEmpty(); | |
awong
2013/09/04 23:20:07
This is missing an implementation.
Cait (Slow)
2013/09/06 18:41:46
Done.
| |
58 | |
59 // Get an iterator to the CallbackList. | |
60 scoped_ptr<CallbackListImpl::Iterator> GetIterator(); | |
awong
2013/09/04 23:20:07
What about returning the Iterator by copy like eri
Cait (Slow)
2013/09/06 18:41:46
Done.
| |
61 | |
62 // Compact the list (remove any elements which were nulled out during | |
awong
2013/09/04 23:20:07
nulled -> NULLed
Cait (Slow)
2013/09/06 18:41:46
Done.
| |
63 // iteration). | |
64 void Compact(); | |
65 | |
66 private: | |
67 // Remove a callback from the list if it is in the list. | |
68 void Remove(base::internal::CallbackBase* cb); | |
69 | |
70 ListType callbacks_; | |
71 int active_iterator_count_; | |
72 base::WeakPtrFactory<CallbackListImpl> weak_factory_; | |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(CallbackListImpl); | |
75 }; | |
76 | |
77 } // namespace internal | |
78 } // namespace base | |
79 | |
80 #endif // BASE_CALLBACK_LIST_INTERNAL_H_ | |
OLD | NEW |