blob: 11f59be5065c873426ed56e964f5eb2025911481 [file] [log] [blame]
[email protected]3fe674d2012-04-05 17:52:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
5#include "base/observer_list.h"
[email protected]503631c2008-10-22 23:09:216#include "base/observer_list_threadsafe.h"
[email protected]3c0d45e2010-09-17 19:33:067
8#include <vector>
9
[email protected]a6ffd7d2011-10-12 20:26:5010#include "base/compiler_specific.h"
11#include "base/memory/weak_ptr.h"
[email protected]495cad92013-07-18 08:12:4012#include "base/message_loop/message_loop.h"
[email protected]7ff48ca2013-02-06 16:56:1913#include "base/run_loop.h"
[email protected]ce072a72010-12-31 20:02:1614#include "base/threading/platform_thread.h"
initial.commitd7cae122008-07-26 21:49:3815#include "testing/gtest/include/gtest/gtest.h"
16
[email protected]7ff48ca2013-02-06 16:56:1917namespace base {
initial.commitd7cae122008-07-26 21:49:3818namespace {
19
initial.commitd7cae122008-07-26 21:49:3820class Foo {
21 public:
22 virtual void Observe(int x) = 0;
[email protected]bf92cfbe2008-08-08 16:37:4323 virtual ~Foo() {}
initial.commitd7cae122008-07-26 21:49:3824};
25
26class Adder : public Foo {
27 public:
[email protected]503631c2008-10-22 23:09:2128 explicit Adder(int scaler) : total(0), scaler_(scaler) {}
dcheng56488182014-10-21 10:54:5129 void Observe(int x) override { total += x * scaler_; }
30 ~Adder() override {}
initial.commitd7cae122008-07-26 21:49:3831 int total;
[email protected]44106182012-04-06 03:53:0232
initial.commitd7cae122008-07-26 21:49:3833 private:
34 int scaler_;
35};
36
37class Disrupter : public Foo {
38 public:
[email protected]503631c2008-10-22 23:09:2139 Disrupter(ObserverList<Foo>* list, Foo* doomed)
[email protected]44106182012-04-06 03:53:0240 : list_(list),
41 doomed_(doomed) {
42 }
dcheng56488182014-10-21 10:54:5143 ~Disrupter() override {}
44 void Observe(int x) override { list_->RemoveObserver(doomed_); }
[email protected]44106182012-04-06 03:53:0245
initial.commitd7cae122008-07-26 21:49:3846 private:
[email protected]503631c2008-10-22 23:09:2147 ObserverList<Foo>* list_;
initial.commitd7cae122008-07-26 21:49:3848 Foo* doomed_;
49};
50
[email protected]503631c2008-10-22 23:09:2151class ThreadSafeDisrupter : public Foo {
52 public:
53 ThreadSafeDisrupter(ObserverListThreadSafe<Foo>* list, Foo* doomed)
[email protected]44106182012-04-06 03:53:0254 : list_(list),
55 doomed_(doomed) {
56 }
dcheng56488182014-10-21 10:54:5157 ~ThreadSafeDisrupter() override {}
58 void Observe(int x) override { list_->RemoveObserver(doomed_); }
[email protected]44106182012-04-06 03:53:0259
[email protected]503631c2008-10-22 23:09:2160 private:
61 ObserverListThreadSafe<Foo>* list_;
62 Foo* doomed_;
63};
64
[email protected]920b1fe2011-08-09 21:29:5965template <typename ObserverListType>
[email protected]b3e2fad02008-10-31 03:32:0666class AddInObserve : public Foo {
67 public:
[email protected]920b1fe2011-08-09 21:29:5968 explicit AddInObserve(ObserverListType* observer_list)
[email protected]b3e2fad02008-10-31 03:32:0669 : added(false),
70 observer_list(observer_list),
71 adder(1) {
72 }
[email protected]44106182012-04-06 03:53:0273
mostynb9e096de2014-10-07 17:59:1174 virtual void Observe(int x) override {
[email protected]b3e2fad02008-10-31 03:32:0675 if (!added) {
76 added = true;
77 observer_list->AddObserver(&adder);
78 }
79 }
80
81 bool added;
[email protected]920b1fe2011-08-09 21:29:5982 ObserverListType* observer_list;
[email protected]b3e2fad02008-10-31 03:32:0683 Adder adder;
84};
85
86
[email protected]ce292012009-11-05 18:46:4787static const int kThreadRunTime = 2000; // ms to run the multi-threaded test.
[email protected]503631c2008-10-22 23:09:2188
89// A thread for use in the ThreadSafeObserver test
90// which will add and remove itself from the notification
91// list repeatedly.
92class AddRemoveThread : public PlatformThread::Delegate,
93 public Foo {
94 public:
95 AddRemoveThread(ObserverListThreadSafe<Foo>* list, bool notify)
96 : list_(list),
[email protected]2e58cbd2012-08-06 01:03:0597 loop_(NULL),
[email protected]503631c2008-10-22 23:09:2198 in_list_(false),
99 start_(Time::Now()),
100 count_observes_(0),
101 count_addtask_(0),
[email protected]a6ffd7d2011-10-12 20:26:50102 do_notifies_(notify),
[email protected]c9f977b2013-04-25 12:17:15103 weak_factory_(this) {
[email protected]503631c2008-10-22 23:09:21104 }
105
dcheng56488182014-10-21 10:54:51106 ~AddRemoveThread() override {}
[email protected]503631c2008-10-22 23:09:21107
dcheng56488182014-10-21 10:54:51108 void ThreadMain() override {
[email protected]503631c2008-10-22 23:09:21109 loop_ = new MessageLoop(); // Fire up a message loop.
[email protected]0586b0e2010-02-12 21:38:37110 loop_->PostTask(
[email protected]a6ffd7d2011-10-12 20:26:50111 FROM_HERE,
112 base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr()));
[email protected]503631c2008-10-22 23:09:21113 loop_->Run();
[email protected]52a261f2009-03-03 15:01:12114 //LOG(ERROR) << "Loop 0x" << std::hex << loop_ << " done. " <<
115 // count_observes_ << ", " << count_addtask_;
[email protected]503631c2008-10-22 23:09:21116 delete loop_;
117 loop_ = reinterpret_cast<MessageLoop*>(0xdeadbeef);
[email protected]bd60d732009-01-05 19:40:53118 delete this;
[email protected]503631c2008-10-22 23:09:21119 }
120
121 // This task just keeps posting to itself in an attempt
122 // to race with the notifier.
123 void AddTask() {
124 count_addtask_++;
125
126 if ((Time::Now() - start_).InMilliseconds() > kThreadRunTime) {
[email protected]b026e35d2010-10-19 02:31:03127 VLOG(1) << "DONE!";
[email protected]503631c2008-10-22 23:09:21128 return;
129 }
130
131 if (!in_list_) {
132 list_->AddObserver(this);
133 in_list_ = true;
134 }
135
136 if (do_notifies_) {
137 list_->Notify(&Foo::Observe, 10);
138 }
139
[email protected]a6ffd7d2011-10-12 20:26:50140 loop_->PostTask(
141 FROM_HERE,
142 base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr()));
[email protected]503631c2008-10-22 23:09:21143 }
144
145 void Quit() {
[email protected]a085953f2013-02-04 23:40:00146 loop_->PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure());
[email protected]503631c2008-10-22 23:09:21147 }
148
dcheng56488182014-10-21 10:54:51149 void Observe(int x) override {
[email protected]503631c2008-10-22 23:09:21150 count_observes_++;
151
152 // If we're getting called after we removed ourselves from
153 // the list, that is very bad!
154 DCHECK(in_list_);
155
156 // This callback should fire on the appropriate thread
157 EXPECT_EQ(loop_, MessageLoop::current());
158
159 list_->RemoveObserver(this);
160 in_list_ = false;
161 }
162
163 private:
164 ObserverListThreadSafe<Foo>* list_;
165 MessageLoop* loop_;
166 bool in_list_; // Are we currently registered for notifications.
167 // in_list_ is only used on |this| thread.
168 Time start_; // The time we started the test.
169
170 int count_observes_; // Number of times we observed.
171 int count_addtask_; // Number of times thread AddTask was called
172 bool do_notifies_; // Whether these threads should do notifications.
173
[email protected]a6ffd7d2011-10-12 20:26:50174 base::WeakPtrFactory<AddRemoveThread> weak_factory_;
[email protected]503631c2008-10-22 23:09:21175};
176
initial.commitd7cae122008-07-26 21:49:38177TEST(ObserverListTest, BasicTest) {
178 ObserverList<Foo> observer_list;
[email protected]631739f2011-06-05 07:07:12179 Adder a(1), b(-1), c(1), d(-1), e(-1);
[email protected]503631c2008-10-22 23:09:21180 Disrupter evil(&observer_list, &c);
initial.commitd7cae122008-07-26 21:49:38181
182 observer_list.AddObserver(&a);
183 observer_list.AddObserver(&b);
184
185 FOR_EACH_OBSERVER(Foo, observer_list, Observe(10));
186
187 observer_list.AddObserver(&evil);
188 observer_list.AddObserver(&c);
189 observer_list.AddObserver(&d);
190
[email protected]631739f2011-06-05 07:07:12191 // Removing an observer not in the list should do nothing.
192 observer_list.RemoveObserver(&e);
193
initial.commitd7cae122008-07-26 21:49:38194 FOR_EACH_OBSERVER(Foo, observer_list, Observe(10));
195
[email protected]14cf9102012-08-23 09:59:19196 EXPECT_EQ(20, a.total);
197 EXPECT_EQ(-20, b.total);
198 EXPECT_EQ(0, c.total);
199 EXPECT_EQ(-10, d.total);
200 EXPECT_EQ(0, e.total);
initial.commitd7cae122008-07-26 21:49:38201}
license.botbf09a502008-08-24 00:55:55202
[email protected]503631c2008-10-22 23:09:21203TEST(ObserverListThreadSafeTest, BasicTest) {
204 MessageLoop loop;
205
206 scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
207 new ObserverListThreadSafe<Foo>);
208 Adder a(1);
209 Adder b(-1);
210 Adder c(1);
211 Adder d(-1);
212 ThreadSafeDisrupter evil(observer_list.get(), &c);
213
214 observer_list->AddObserver(&a);
215 observer_list->AddObserver(&b);
216
217 observer_list->Notify(&Foo::Observe, 10);
[email protected]7ff48ca2013-02-06 16:56:19218 RunLoop().RunUntilIdle();
[email protected]503631c2008-10-22 23:09:21219
220 observer_list->AddObserver(&evil);
221 observer_list->AddObserver(&c);
222 observer_list->AddObserver(&d);
223
224 observer_list->Notify(&Foo::Observe, 10);
[email protected]7ff48ca2013-02-06 16:56:19225 RunLoop().RunUntilIdle();
[email protected]503631c2008-10-22 23:09:21226
[email protected]14cf9102012-08-23 09:59:19227 EXPECT_EQ(20, a.total);
228 EXPECT_EQ(-20, b.total);
229 EXPECT_EQ(0, c.total);
230 EXPECT_EQ(-10, d.total);
[email protected]503631c2008-10-22 23:09:21231}
232
[email protected]631739f2011-06-05 07:07:12233TEST(ObserverListThreadSafeTest, RemoveObserver) {
234 MessageLoop loop;
235
236 scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
237 new ObserverListThreadSafe<Foo>);
238 Adder a(1), b(1);
239
[email protected]3fe674d2012-04-05 17:52:10240 // A workaround for the compiler bug. See http://crbug.com/121960.
241 EXPECT_NE(&a, &b);
242
[email protected]631739f2011-06-05 07:07:12243 // Should do nothing.
244 observer_list->RemoveObserver(&a);
245 observer_list->RemoveObserver(&b);
246
247 observer_list->Notify(&Foo::Observe, 10);
[email protected]7ff48ca2013-02-06 16:56:19248 RunLoop().RunUntilIdle();
[email protected]631739f2011-06-05 07:07:12249
[email protected]14cf9102012-08-23 09:59:19250 EXPECT_EQ(0, a.total);
251 EXPECT_EQ(0, b.total);
[email protected]631739f2011-06-05 07:07:12252
253 observer_list->AddObserver(&a);
254
255 // Should also do nothing.
256 observer_list->RemoveObserver(&b);
257
258 observer_list->Notify(&Foo::Observe, 10);
[email protected]7ff48ca2013-02-06 16:56:19259 RunLoop().RunUntilIdle();
[email protected]631739f2011-06-05 07:07:12260
[email protected]14cf9102012-08-23 09:59:19261 EXPECT_EQ(10, a.total);
262 EXPECT_EQ(0, b.total);
[email protected]631739f2011-06-05 07:07:12263}
264
[email protected]c2b1b302011-11-23 20:34:04265TEST(ObserverListThreadSafeTest, WithoutMessageLoop) {
266 scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
267 new ObserverListThreadSafe<Foo>);
268
269 Adder a(1), b(1), c(1);
270
271 // No MessageLoop, so these should not be added.
272 observer_list->AddObserver(&a);
273 observer_list->AddObserver(&b);
274
275 {
276 // Add c when there's a loop.
277 MessageLoop loop;
278 observer_list->AddObserver(&c);
279
280 observer_list->Notify(&Foo::Observe, 10);
[email protected]7ff48ca2013-02-06 16:56:19281 RunLoop().RunUntilIdle();
[email protected]c2b1b302011-11-23 20:34:04282
283 EXPECT_EQ(0, a.total);
284 EXPECT_EQ(0, b.total);
285 EXPECT_EQ(10, c.total);
286
287 // Now add a when there's a loop.
288 observer_list->AddObserver(&a);
289
290 // Remove c when there's a loop.
291 observer_list->RemoveObserver(&c);
292
293 // Notify again.
294 observer_list->Notify(&Foo::Observe, 20);
[email protected]7ff48ca2013-02-06 16:56:19295 RunLoop().RunUntilIdle();
[email protected]c2b1b302011-11-23 20:34:04296
297 EXPECT_EQ(20, a.total);
298 EXPECT_EQ(0, b.total);
299 EXPECT_EQ(10, c.total);
300 }
301
302 // Removing should always succeed with or without a loop.
303 observer_list->RemoveObserver(&a);
304
305 // Notifying should not fail but should also be a no-op.
306 MessageLoop loop;
307 observer_list->AddObserver(&b);
308 observer_list->Notify(&Foo::Observe, 30);
[email protected]7ff48ca2013-02-06 16:56:19309 RunLoop().RunUntilIdle();
[email protected]c2b1b302011-11-23 20:34:04310
311 EXPECT_EQ(20, a.total);
312 EXPECT_EQ(30, b.total);
313 EXPECT_EQ(10, c.total);
314}
315
[email protected]3c0d45e2010-09-17 19:33:06316class FooRemover : public Foo {
317 public:
318 explicit FooRemover(ObserverListThreadSafe<Foo>* list) : list_(list) {}
dcheng56488182014-10-21 10:54:51319 ~FooRemover() override {}
[email protected]3c0d45e2010-09-17 19:33:06320
321 void AddFooToRemove(Foo* foo) {
322 foos_.push_back(foo);
323 }
324
dcheng56488182014-10-21 10:54:51325 void Observe(int x) override {
[email protected]3c0d45e2010-09-17 19:33:06326 std::vector<Foo*> tmp;
327 tmp.swap(foos_);
328 for (std::vector<Foo*>::iterator it = tmp.begin();
329 it != tmp.end(); ++it) {
330 list_->RemoveObserver(*it);
331 }
332 }
333
334 private:
335 const scoped_refptr<ObserverListThreadSafe<Foo> > list_;
336 std::vector<Foo*> foos_;
337};
338
339TEST(ObserverListThreadSafeTest, RemoveMultipleObservers) {
340 MessageLoop loop;
341 scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
342 new ObserverListThreadSafe<Foo>);
343
[email protected]3703e922013-05-31 21:37:53344 FooRemover a(observer_list.get());
[email protected]3c0d45e2010-09-17 19:33:06345 Adder b(1);
346
347 observer_list->AddObserver(&a);
348 observer_list->AddObserver(&b);
349
350 a.AddFooToRemove(&a);
351 a.AddFooToRemove(&b);
352
353 observer_list->Notify(&Foo::Observe, 1);
[email protected]7ff48ca2013-02-06 16:56:19354 RunLoop().RunUntilIdle();
[email protected]3c0d45e2010-09-17 19:33:06355}
[email protected]503631c2008-10-22 23:09:21356
357// A test driver for a multi-threaded notification loop. Runs a number
358// of observer threads, each of which constantly adds/removes itself
359// from the observer list. Optionally, if cross_thread_notifies is set
360// to true, the observer threads will also trigger notifications to
361// all observers.
[email protected]52a261f2009-03-03 15:01:12362static void ThreadSafeObserverHarness(int num_threads,
[email protected]503631c2008-10-22 23:09:21363 bool cross_thread_notifies) {
364 MessageLoop loop;
365
366 const int kMaxThreads = 15;
367 num_threads = num_threads > kMaxThreads ? kMaxThreads : num_threads;
368
369 scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
370 new ObserverListThreadSafe<Foo>);
371 Adder a(1);
372 Adder b(-1);
373 Adder c(1);
374 Adder d(-1);
375
376 observer_list->AddObserver(&a);
377 observer_list->AddObserver(&b);
378
379 AddRemoveThread* threaded_observer[kMaxThreads];
[email protected]ce072a72010-12-31 20:02:16380 base::PlatformThreadHandle threads[kMaxThreads];
[email protected]503631c2008-10-22 23:09:21381 for (int index = 0; index < num_threads; index++) {
382 threaded_observer[index] = new AddRemoveThread(observer_list.get(), false);
383 EXPECT_TRUE(PlatformThread::Create(0,
384 threaded_observer[index], &threads[index]));
385 }
386
387 Time start = Time::Now();
388 while (true) {
389 if ((Time::Now() - start).InMilliseconds() > kThreadRunTime)
390 break;
391
392 observer_list->Notify(&Foo::Observe, 10);
393
[email protected]7ff48ca2013-02-06 16:56:19394 RunLoop().RunUntilIdle();
[email protected]503631c2008-10-22 23:09:21395 }
396
397 for (int index = 0; index < num_threads; index++) {
398 threaded_observer[index]->Quit();
399 PlatformThread::Join(threads[index]);
400 }
401}
402
403TEST(ObserverListThreadSafeTest, CrossThreadObserver) {
404 // Use 7 observer threads. Notifications only come from
405 // the main thread.
406 ThreadSafeObserverHarness(7, false);
407}
408
409TEST(ObserverListThreadSafeTest, CrossThreadNotifications) {
410 // Use 3 observer threads. Notifications will fire from
411 // the main thread and all 3 observer threads.
412 ThreadSafeObserverHarness(3, true);
413}
[email protected]b3e2fad02008-10-31 03:32:06414
[email protected]920b1fe2011-08-09 21:29:59415TEST(ObserverListThreadSafeTest, OutlivesMessageLoop) {
416 MessageLoop* loop = new MessageLoop;
417 scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
418 new ObserverListThreadSafe<Foo>);
419
420 Adder a(1);
421 observer_list->AddObserver(&a);
422 delete loop;
423 // Test passes if we don't crash here.
424 observer_list->Notify(&Foo::Observe, 1);
425}
426
[email protected]b3e2fad02008-10-31 03:32:06427TEST(ObserverListTest, Existing) {
428 ObserverList<Foo> observer_list(ObserverList<Foo>::NOTIFY_EXISTING_ONLY);
429 Adder a(1);
[email protected]920b1fe2011-08-09 21:29:59430 AddInObserve<ObserverList<Foo> > b(&observer_list);
[email protected]b3e2fad02008-10-31 03:32:06431
432 observer_list.AddObserver(&a);
433 observer_list.AddObserver(&b);
434
435 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1));
436
437 EXPECT_TRUE(b.added);
438 // B's adder should not have been notified because it was added during
[email protected]6be50d72014-05-08 23:49:40439 // notification.
[email protected]b3e2fad02008-10-31 03:32:06440 EXPECT_EQ(0, b.adder.total);
441
442 // Notify again to make sure b's adder is notified.
443 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1));
444 EXPECT_EQ(1, b.adder.total);
445}
[email protected]84aebed2010-02-25 03:09:41446
[email protected]920b1fe2011-08-09 21:29:59447// Same as above, but for ObserverListThreadSafe
448TEST(ObserverListThreadSafeTest, Existing) {
449 MessageLoop loop;
450 scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
451 new ObserverListThreadSafe<Foo>(ObserverList<Foo>::NOTIFY_EXISTING_ONLY));
452 Adder a(1);
453 AddInObserve<ObserverListThreadSafe<Foo> > b(observer_list.get());
454
455 observer_list->AddObserver(&a);
456 observer_list->AddObserver(&b);
457
458 observer_list->Notify(&Foo::Observe, 1);
[email protected]7ff48ca2013-02-06 16:56:19459 RunLoop().RunUntilIdle();
[email protected]920b1fe2011-08-09 21:29:59460
461 EXPECT_TRUE(b.added);
462 // B's adder should not have been notified because it was added during
[email protected]6be50d72014-05-08 23:49:40463 // notification.
[email protected]920b1fe2011-08-09 21:29:59464 EXPECT_EQ(0, b.adder.total);
465
466 // Notify again to make sure b's adder is notified.
467 observer_list->Notify(&Foo::Observe, 1);
[email protected]7ff48ca2013-02-06 16:56:19468 RunLoop().RunUntilIdle();
[email protected]920b1fe2011-08-09 21:29:59469 EXPECT_EQ(1, b.adder.total);
470}
471
[email protected]84aebed2010-02-25 03:09:41472class AddInClearObserve : public Foo {
473 public:
474 explicit AddInClearObserve(ObserverList<Foo>* list)
475 : list_(list), added_(false), adder_(1) {}
476
dcheng56488182014-10-21 10:54:51477 void Observe(int /* x */) override {
[email protected]84aebed2010-02-25 03:09:41478 list_->Clear();
479 list_->AddObserver(&adder_);
480 added_ = true;
481 }
482
483 bool added() const { return added_; }
484 const Adder& adder() const { return adder_; }
485
486 private:
487 ObserverList<Foo>* const list_;
488
489 bool added_;
490 Adder adder_;
491};
492
493TEST(ObserverListTest, ClearNotifyAll) {
494 ObserverList<Foo> observer_list;
495 AddInClearObserve a(&observer_list);
496
497 observer_list.AddObserver(&a);
498
499 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1));
500 EXPECT_TRUE(a.added());
501 EXPECT_EQ(1, a.adder().total)
502 << "Adder should observe once and have sum of 1.";
503}
504
505TEST(ObserverListTest, ClearNotifyExistingOnly) {
506 ObserverList<Foo> observer_list(ObserverList<Foo>::NOTIFY_EXISTING_ONLY);
507 AddInClearObserve a(&observer_list);
508
509 observer_list.AddObserver(&a);
510
511 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1));
512 EXPECT_TRUE(a.added());
513 EXPECT_EQ(0, a.adder().total)
514 << "Adder should not observe, so sum should still be 0.";
515}
516
[email protected]671b74d2011-06-09 03:41:18517class ListDestructor : public Foo {
518 public:
519 explicit ListDestructor(ObserverList<Foo>* list) : list_(list) {}
dcheng56488182014-10-21 10:54:51520 ~ListDestructor() override {}
[email protected]44106182012-04-06 03:53:02521
dcheng56488182014-10-21 10:54:51522 void Observe(int x) override { delete list_; }
[email protected]2e58cbd2012-08-06 01:03:05523
[email protected]671b74d2011-06-09 03:41:18524 private:
525 ObserverList<Foo>* list_;
526};
527
528
529TEST(ObserverListTest, IteratorOutlivesList) {
530 ObserverList<Foo>* observer_list = new ObserverList<Foo>;
531 ListDestructor a(observer_list);
532 observer_list->AddObserver(&a);
533
534 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0));
535 // If this test fails, there'll be Valgrind errors when this function goes out
536 // of scope.
537}
538
[email protected]84aebed2010-02-25 03:09:41539} // namespace
[email protected]7ff48ca2013-02-06 16:56:19540} // namespace base