Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
|
sky
2017/06/08 19:17:49
no (c)
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/public/test/repeated_notification_observer.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "content/public/browser/browser_thread.h" | |
| 9 #include "content/public/browser/notification_service.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 RepeatedNotificationObserver::RepeatedNotificationObserver(int type, int count) | |
| 15 : num_outstanding_(count), running_(false) { | |
| 16 registrar_.Add(this, type, NotificationService::AllSources()); | |
| 17 } | |
| 18 | |
| 19 void RepeatedNotificationObserver::Observe(int type, | |
| 20 const NotificationSource& source, | |
| 21 const NotificationDetails& details) { | |
| 22 ASSERT_GT(num_outstanding_, 0); | |
| 23 if (!--num_outstanding_ && running_) { | |
| 24 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
|
sky
2017/06/08 19:17:49
Can't you call run_loop_.Quit (or QuitWhenIdle())
| |
| 25 run_loop_.QuitClosure()); | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 void RepeatedNotificationObserver::Wait() { | |
| 30 if (num_outstanding_ <= 0) | |
| 31 return; | |
| 32 | |
| 33 running_ = true; | |
|
sky
2017/06/08 19:17:49
base::AutoReset.
eugenebng
2017/06/09 13:16:22
Done.
| |
| 34 run_loop_.Run(); | |
| 35 running_ = false; | |
| 36 } | |
| 37 | |
| 38 } // namespace content | |
| OLD | NEW |