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 namespace internal { | |
19 | |
20 // Holds the CallbackList methods that don't require specialization to reduce | |
21 // template bloat. | |
22 // | |
23 // DO NOT USE THIS CLASS DIRECTLY YOURSELF. | |
awong
2013/08/29 19:30:48
Probably better to say
"This class is meant as an
Cait (Slow)
2013/08/30 00:28:02
Done.
| |
24 | |
25 class BASE_EXPORT CallbackListBase { | |
26 public: | |
27 // Enumeration of which callbacks are called. | |
28 enum NotificationType { | |
29 // Specifies that any callbacks added during notification are called. | |
30 NOTIFY_ALL, | |
31 | |
32 // Specifies that callbacks added while sending out notifications are not | |
33 // called. | |
34 NOTIFY_EXISTING_ONLY | |
35 }; | |
36 | |
37 explicit CallbackListBase(NotificationType type); | |
38 virtual ~CallbackListBase(); | |
awong
2013/08/29 19:30:48
I don't think this needs to be virtual. No one sh
Cait (Slow)
2013/08/30 00:28:02
Done.
| |
39 | |
40 // Delete (or nullify, if called during iteration), all callbacks in the list. | |
41 void Clear(); | |
42 | |
43 bool might_have_callbacks() const { return size() != 0; } | |
44 | |
45 protected: | |
46 typedef std::vector<base::internal::CallbackBase*> ListType; | |
awong
2013/08/29 19:30:48
It does seem that set or hash_set is a better choi
Cait (Slow)
2013/08/30 00:28:02
I think the issue is for any type of collection, e
| |
47 | |
48 // An iterator class that can be used to access the list of callbacks. | |
49 class Iterator { | |
50 public: | |
51 Iterator(CallbackListBase* list); | |
awong
2013/08/29 19:30:48
explicit
Also, this should jsut take a const base
Cait (Slow)
2013/08/30 00:28:02
I think GetWeakPtr is still needed, as CallbackLis
awong
2013/09/04 17:44:35
How about replacing it with a GetIterator()?
| |
52 | |
53 ~Iterator(); | |
54 | |
55 base::internal::CallbackBase* GetNext(); | |
56 | |
57 private: | |
58 base::WeakPtr<CallbackListBase> list_; | |
59 size_t index_; | |
60 size_t max_index_; | |
61 }; | |
62 | |
63 // Remove a callback from the list if it is in the list. | |
64 void RemoveCallback(base::internal::CallbackBase* cb); | |
65 | |
66 // Add a callback to the list, if it is not already in there. This method | |
67 // takes ownership of |cb|, and will handle deleting it upon removal from the | |
68 // list. | |
69 base::Closure AddCallback(base::internal::CallbackBase* cb); | |
70 | |
71 // Get a weak pointer to the CallbackList. | |
72 base::WeakPtr<CallbackListBase> GetWeakPtr(); | |
73 | |
74 // Compact the list (remove any elements which were nulled out during | |
75 // iteration). | |
76 void Compact(); | |
77 | |
78 // Returns the number of callbacks in the list. Note that if the list has not | |
79 // been compacted, some of these callbacks may be NULL. | |
80 size_t size() const { return callbacks_.size(); } | |
81 | |
82 private: | |
83 ListType callbacks_; | |
84 int active_iterator_count_; | |
85 NotificationType type_; | |
86 base::WeakPtrFactory<CallbackListBase> weak_factory_; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(CallbackListBase); | |
89 }; | |
90 | |
91 } // namespace internal | |
92 } // namespace base | |
93 | |
94 #endif // BASE_CALLBACK_LIST_INTERNAL_H_ | |
OLD | NEW |