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

Side by Side Diff: base/callback_list.h

Issue 23645019: C++ Readability Review for caitkp (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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
« no previous file with comments | « no previous file | base/callback_list.h.pump » ('j') | base/callback_list_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // This file was GENERATED by command: 1 // This file was GENERATED by command:
2 // pump.py callback_list.h.pump 2 // pump.py callback_list.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_LIST_H_ 10 #ifndef BASE_CALLBACK_LIST_H_
(...skipping 27 matching lines...) Expand all
38 // RegisterCallback(const OnFooCallback& cb) { 38 // RegisterCallback(const OnFooCallback& cb) {
39 // return callback_list_.Add(cb); 39 // return callback_list_.Add(cb);
40 // } 40 // }
41 // 41 //
42 // private: 42 // private:
43 // void NotifyFoo(const Foo& foo) { 43 // void NotifyFoo(const Foo& foo) {
44 // callback_list_.Notify(foo); 44 // callback_list_.Notify(foo);
45 // } 45 // }
46 // 46 //
47 // base::CallbackList<void(const Foo&)> callback_list_; 47 // base::CallbackList<void(const Foo&)> callback_list_;
48 //
49 // DISALLOW_COPY_AND_ASSIGN(MyWidget);
48 // }; 50 // };
49 // 51 //
50 // 52 //
51 // class MyWidgetListener { 53 // class MyWidgetListener {
52 // public: 54 // public:
53 // MyWidgetListener::MyWidgetListener() { 55 // MyWidgetListener::MyWidgetListener() {
54 // foo_subscription_ = MyWidget::GetCurrent()->RegisterCallback( 56 // foo_subscription_ = MyWidget::GetCurrent()->RegisterCallback(
55 // base::Bind(&MyWidgetListener::OnFoo, this))); 57 // base::Bind(&MyWidgetListener::OnFoo, this)));
56 // } 58 // }
57 // 59 //
58 // MyWidgetListener::~MyWidgetListener() { 60 // MyWidgetListener::~MyWidgetListener() {
59 // // Subscription gets deleted automatically and will deregister 61 // // Subscription gets deleted automatically and will deregister
60 // // the callback in the process. 62 // // the callback in the process.
61 // } 63 // }
62 // 64 //
63 // private: 65 // private:
64 // void OnFoo(const Foo& foo) { 66 // void OnFoo(const Foo& foo) {
65 // // Do something. 67 // // Do something.
66 // } 68 // }
67 // 69 //
68 // scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription> 70 // scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription>
69 // foo_subscription_; 71 // foo_subscription_;
72 //
73 // DISALLOW_COPY_AND_ASSIGN(MyWidgetListener);
70 // }; 74 // };
71 75
72 namespace base { 76 namespace base {
73 77
74 namespace internal { 78 namespace internal {
75 79
76 template <typename CallbackType> 80 template <typename CallbackType>
77 class CallbackListBase { 81 class CallbackListBase {
78 public: 82 public:
79 class Subscription { 83 class Subscription {
80 public: 84 public:
81 Subscription(CallbackListBase<CallbackType>* list, 85 Subscription(CallbackListBase<CallbackType>* list,
82 typename std::list<CallbackType>::iterator iter) 86 typename std::list<CallbackType>::iterator iter)
83 : list_(list), 87 : list_(list),
84 iter_(iter) {} 88 iter_(iter) {
89 }
85 90
86 ~Subscription() { 91 ~Subscription() {
87 if (list_->active_iterator_count_) 92 if (list_->active_iterator_count_)
88 (*iter_).Reset(); 93 iter_->Reset();
89 else 94 else
90 list_->callbacks_.erase(iter_); 95 list_->callbacks_.erase(iter_);
91 } 96 }
92 97
93 private: 98 private:
94 CallbackListBase<CallbackType>* list_; 99 CallbackListBase<CallbackType>* list_;
95 typename std::list<CallbackType>::iterator iter_; 100 typename std::list<CallbackType>::iterator iter_;
96 101
97 DISALLOW_COPY_AND_ASSIGN(Subscription); 102 DISALLOW_COPY_AND_ASSIGN(Subscription);
98 }; 103 };
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ++list_iter_; 143 ++list_iter_;
139 } 144 }
140 return cb; 145 return cb;
141 } 146 }
142 147
143 private: 148 private:
144 CallbackListBase<CallbackType>* list_; 149 CallbackListBase<CallbackType>* list_;
145 typename std::list<CallbackType>::iterator list_iter_; 150 typename std::list<CallbackType>::iterator list_iter_;
146 }; 151 };
147 152
148 CallbackListBase() 153 CallbackListBase() : active_iterator_count_(0) {}
149 : active_iterator_count_(0) {}
150 154
151 ~CallbackListBase() { 155 ~CallbackListBase() {
152 DCHECK_EQ(0, active_iterator_count_); 156 DCHECK_EQ(0, active_iterator_count_);
153 DCHECK_EQ(0U, callbacks_.size()); 157 DCHECK_EQ(0U, callbacks_.size());
154 } 158 }
155 159
156 // Returns an instance of a CallbackListBase::Iterator which can be used 160 // Returns an instance of a CallbackListBase::Iterator which can be used
157 // to run callbacks. 161 // to run callbacks.
158 Iterator GetIterator() { 162 Iterator GetIterator() {
159 return Iterator(this); 163 return Iterator(this);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 203 }
200 } 204 }
201 205
202 private: 206 private:
203 DISALLOW_COPY_AND_ASSIGN(CallbackList); 207 DISALLOW_COPY_AND_ASSIGN(CallbackList);
204 }; 208 };
205 209
206 template <typename A1> 210 template <typename A1>
207 class CallbackList<void(A1)> 211 class CallbackList<void(A1)>
208 : public internal::CallbackListBase< 212 : public internal::CallbackListBase<
209 Callback<void(A1)> > { 213 Callback<void(A1)> > {
milos 2013/10/03 15:49:43 This would fit on the previous line, so it would b
Cait (Slow) 2013/10/03 15:58:11 Done.
210 public: 214 public:
211 typedef Callback<void(A1)> CallbackType; 215 typedef Callback<void(A1)> CallbackType;
212 216
213 CallbackList() {} 217 CallbackList() {}
214 218
215 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1) { 219 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1) {
216 typename internal::CallbackListBase<CallbackType>::Iterator it = 220 typename internal::CallbackListBase<CallbackType>::Iterator it =
217 this->GetIterator(); 221 this->GetIterator();
218 CallbackType* cb; 222 CallbackType* cb;
219 while((cb = it.GetNext()) != NULL) { 223 while((cb = it.GetNext()) != NULL) {
milos 2013/10/03 15:49:43 Missing a space between "while" and "("
Cait (Slow) 2013/10/03 15:58:11 Done.
220 cb->Run(a1); 224 cb->Run(a1);
221 } 225 }
222 } 226 }
223 227
224 private: 228 private:
225 DISALLOW_COPY_AND_ASSIGN(CallbackList); 229 DISALLOW_COPY_AND_ASSIGN(CallbackList);
226 }; 230 };
227 231
228 template <typename A1, typename A2> 232 template <typename A1, typename A2>
229 class CallbackList<void(A1, A2)> 233 class CallbackList<void(A1, A2)>
230 : public internal::CallbackListBase< 234 : public internal::CallbackListBase<
231 Callback<void(A1, A2)> > { 235 Callback<void(A1, A2)> > {
milos 2013/10/03 15:49:43 Ditto
Cait (Slow) 2013/10/03 15:58:11 Done.
232 public: 236 public:
233 typedef Callback<void(A1, A2)> CallbackType; 237 typedef Callback<void(A1, A2)> CallbackType;
234 238
235 CallbackList() {} 239 CallbackList() {}
236 240
237 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1, 241 void Notify(typename internal::CallbackParamTraits<A1>::ForwardType a1,
238 typename internal::CallbackParamTraits<A2>::ForwardType a2) { 242 typename internal::CallbackParamTraits<A2>::ForwardType a2) {
239 typename internal::CallbackListBase<CallbackType>::Iterator it = 243 typename internal::CallbackListBase<CallbackType>::Iterator it =
240 this->GetIterator(); 244 this->GetIterator();
241 CallbackType* cb; 245 CallbackType* cb;
242 while((cb = it.GetNext()) != NULL) { 246 while((cb = it.GetNext()) != NULL) {
milos 2013/10/03 15:49:43 Ditto
Cait (Slow) 2013/10/03 15:58:11 Done.
243 cb->Run(a1, a2); 247 cb->Run(a1, a2);
244 } 248 }
245 } 249 }
246 250
247 private: 251 private:
248 DISALLOW_COPY_AND_ASSIGN(CallbackList); 252 DISALLOW_COPY_AND_ASSIGN(CallbackList);
249 }; 253 };
250 254
251 template <typename A1, typename A2, typename A3> 255 template <typename A1, typename A2, typename A3>
252 class CallbackList<void(A1, A2, A3)> 256 class CallbackList<void(A1, A2, A3)>
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 380 }
377 } 381 }
378 382
379 private: 383 private:
380 DISALLOW_COPY_AND_ASSIGN(CallbackList); 384 DISALLOW_COPY_AND_ASSIGN(CallbackList);
381 }; 385 };
382 386
383 } // namespace base 387 } // namespace base
384 388
385 #endif // BASE_CALLBACK_LIST_H_ 389 #endif // BASE_CALLBACK_LIST_H_
OLDNEW
« no previous file with comments | « no previous file | base/callback_list.h.pump » ('j') | base/callback_list_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698