OLD | NEW |
---|---|
1 // This file was GENERATED by command: | 1 // This file was GENERATED by command: |
2 // pump.py callback_registry.h.pump | 2 // pump.py callback_registry.h.pump |
3 // DO NOT EDIT BY HAND!!! | 3 // DO NOT EDIT BY HAND!!! |
4 | 4 |
5 | 5 |
6 // Copyright 2013 The Chromium Authors. All rights reserved. | 6 // Copyright 2013 The Chromium Authors. All rights reserved. |
7 // Use of this source code is governed by a BSD-style license that can be | 7 // Use of this source code is governed by a BSD-style license that can be |
8 // found in the LICENSE file. | 8 // found in the LICENSE file. |
9 | 9 |
10 #ifndef BASE_CALLBACK_REGISTRY_H_ | 10 #ifndef BASE_CALLBACK_REGISTRY_H_ |
(...skipping 27 matching lines...) Expand all Loading... | |
38 // RegisterCallback(const OnFooCallback& cb) { | 38 // RegisterCallback(const OnFooCallback& cb) { |
39 // return callback_registry_.Add(cb); | 39 // return callback_registry_.Add(cb); |
40 // } | 40 // } |
41 // | 41 // |
42 // private: | 42 // private: |
43 // void NotifyFoo(const Foo& foo) { | 43 // void NotifyFoo(const Foo& foo) { |
44 // callback_registry_.Notify(foo); | 44 // callback_registry_.Notify(foo); |
45 // } | 45 // } |
46 // | 46 // |
47 // base::CallbackRegistry<void(const Foo&)> callback_registry_; | 47 // base::CallbackRegistry<void(const Foo&)> callback_registry_; |
48 // }; | 48 // }; |
milos
2013/10/01 17:54:21
Possibly add DISALLOW_COPY_AND_ASSIGN() in the exa
Cait (Slow)
2013/10/01 22:51:27
Done.
| |
49 // | 49 // |
50 // | 50 // |
51 // class MyWidgetListener { | 51 // class MyWidgetListener { |
52 // public: | 52 // public: |
53 // MyWidgetListener::MyWidgetListener() { | 53 // MyWidgetListener::MyWidgetListener() { |
54 // foo_subscription_ = MyWidget::GetCurrent()->RegisterCallback( | 54 // foo_subscription_ = MyWidget::GetCurrent()->RegisterCallback( |
55 // base::Bind(&MyWidgetListener::OnFoo, this))); | 55 // base::Bind(&MyWidgetListener::OnFoo, this))); |
56 // } | 56 // } |
57 // | 57 // |
58 // MyWidgetListener::~MyWidgetListener() { | 58 // MyWidgetListener::~MyWidgetListener() { |
(...skipping 15 matching lines...) Expand all Loading... | |
74 namespace internal { | 74 namespace internal { |
75 | 75 |
76 template <typename CallbackType> | 76 template <typename CallbackType> |
77 class CallbackRegistryBase { | 77 class CallbackRegistryBase { |
78 public: | 78 public: |
79 class Subscription { | 79 class Subscription { |
80 public: | 80 public: |
81 Subscription(CallbackRegistryBase<CallbackType>* list, | 81 Subscription(CallbackRegistryBase<CallbackType>* list, |
82 typename std::list<CallbackType>::iterator iter) | 82 typename std::list<CallbackType>::iterator iter) |
83 : list_(list), | 83 : list_(list), |
84 iter_(iter) {} | 84 iter_(iter) {} |
milos
2013/10/01 17:54:21
A nit - {} can be used when the whole expression f
Cait (Slow)
2013/10/01 22:51:27
Done.
| |
85 | 85 |
86 ~Subscription() { | 86 ~Subscription() { |
87 if (list_->active_iterator_count_) | 87 if (list_->active_iterator_count_) |
88 (*iter_).Reset(); | 88 (*iter_).Reset(); |
milos
2013/10/01 17:54:21
FYI, or iter_->Reset();
Cait (Slow)
2013/10/01 22:51:27
Done.
| |
89 else | 89 else |
90 list_->callbacks_.erase(iter_); | 90 list_->callbacks_.erase(iter_); |
91 } | 91 } |
92 | 92 |
93 private: | 93 private: |
94 CallbackRegistryBase<CallbackType>* list_; | 94 CallbackRegistryBase<CallbackType>* list_; |
95 typename std::list<CallbackType>::iterator iter_; | 95 typename std::list<CallbackType>::iterator iter_; |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(Subscription); | 97 DISALLOW_COPY_AND_ASSIGN(Subscription); |
98 }; | 98 }; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 } | 139 } |
140 return cb; | 140 return cb; |
141 } | 141 } |
142 | 142 |
143 private: | 143 private: |
144 CallbackRegistryBase<CallbackType>* list_; | 144 CallbackRegistryBase<CallbackType>* list_; |
145 typename std::list<CallbackType>::iterator list_iter_; | 145 typename std::list<CallbackType>::iterator list_iter_; |
146 }; | 146 }; |
147 | 147 |
148 CallbackRegistryBase() | 148 CallbackRegistryBase() |
149 : active_iterator_count_(0) {} | 149 : active_iterator_count_(0) {} |
milos
2013/10/01 17:54:21
This could fit on the previous line, see https://w
Cait (Slow)
2013/10/01 22:51:27
Done.
| |
150 | 150 |
151 ~CallbackRegistryBase() { | 151 ~CallbackRegistryBase() { |
152 DCHECK_EQ(0, active_iterator_count_); | 152 DCHECK_EQ(0, active_iterator_count_); |
153 DCHECK_EQ(0U, callbacks_.size()); | 153 DCHECK_EQ(0U, callbacks_.size()); |
154 } | 154 } |
155 | 155 |
156 // Returns an instance of a CallbackRegistryBase::Iterator which can be used | 156 // Returns an instance of a CallbackRegistryBase::Iterator which can be used |
157 // to run callbacks. | 157 // to run callbacks. |
158 Iterator GetIterator() { | 158 Iterator GetIterator() { |
milos
2013/10/01 17:54:21
Could the function be declared const?
Cait (Slow)
2013/10/01 22:51:27
When the Iterator is created, it increments active
| |
159 return Iterator(this); | 159 return Iterator(this); |
160 } | 160 } |
161 | 161 |
162 // Compact the list: remove any entries which were NULLed out during | 162 // Compact the list: remove any entries which were NULLed out during |
163 // iteration. | 163 // iteration. |
164 void Compact() { | 164 void Compact() { |
165 typename std::list<CallbackType>::iterator it = callbacks_.begin(); | 165 typename std::list<CallbackType>::iterator it = callbacks_.begin(); |
166 while (it != callbacks_.end()) { | 166 while (it != callbacks_.end()) { |
167 if ((*it).is_null()) | 167 if ((*it).is_null()) |
168 it = callbacks_.erase(it); | 168 it = callbacks_.erase(it); |
169 else | 169 else |
170 ++it; | 170 ++it; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 private: | 174 private: |
175 std::list<CallbackType> callbacks_; | 175 std::list<CallbackType> callbacks_; |
176 int active_iterator_count_; | 176 int active_iterator_count_; |
177 | 177 |
178 DISALLOW_COPY_AND_ASSIGN(CallbackRegistryBase); | 178 DISALLOW_COPY_AND_ASSIGN(CallbackRegistryBase); |
179 }; | 179 }; |
180 | 180 |
181 } // namespace internal | 181 } // namespace internal |
182 | 182 |
183 template <typename Sig> class CallbackRegistry; | 183 template <typename Sig> class CallbackRegistry; |
184 | 184 |
185 template <> | 185 template <> |
186 class CallbackRegistry<void(void)> | 186 class CallbackRegistry<void(void)> |
187 : public internal::CallbackRegistryBase<Callback<void(void)> > { | 187 : public internal::CallbackRegistryBase<Callback<void(void)> > { |
milos
2013/10/01 17:54:21
FYI, with C++11 there is no need for a space betwe
Cait (Slow)
2013/10/01 22:51:27
AFAIK, Chrome doesn't support C++11 yet, so the sp
| |
188 public: | 188 public: |
189 typedef Callback<void(void)> CallbackType; | 189 typedef Callback<void(void)> CallbackType; |
190 | 190 |
191 CallbackRegistry() {} | 191 CallbackRegistry() {} |
192 | 192 |
193 void Notify() { | 193 void Notify() { |
milos
2013/10/01 17:54:21
Could this function be const?
Cait (Slow)
2013/10/01 22:51:27
This calls GetIterator, so can't be const for the
| |
194 internal::CallbackRegistryBase<CallbackType>::Iterator it = | 194 internal::CallbackRegistryBase<CallbackType>::Iterator it = |
195 this->GetIterator(); | 195 this->GetIterator(); |
196 CallbackType* cb; | 196 CallbackType* cb; |
197 while((cb = it.GetNext()) != NULL) { | 197 while((cb = it.GetNext()) != NULL) { |
198 cb->Run(); | 198 cb->Run(); |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 private: | 202 private: |
203 DISALLOW_COPY_AND_ASSIGN(CallbackRegistry); | 203 DISALLOW_COPY_AND_ASSIGN(CallbackRegistry); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 private: | 379 private: |
380 DISALLOW_COPY_AND_ASSIGN(CallbackRegistry); | 380 DISALLOW_COPY_AND_ASSIGN(CallbackRegistry); |
381 }; | 381 }; |
382 | 382 |
383 } // namespace base | 383 } // namespace base |
384 | 384 |
385 #endif // BASE_CALLBACK_REGISTRY_H | 385 #endif // BASE_CALLBACK_REGISTRY_H |
386 // NOSUBMIT: Force git to add file for readability. | |
OLD | NEW |