| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 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 #include "content/public/test/repeated_notification_observer.h" | |
| 6 | |
| 7 #include "base/auto_reset.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/notification_service.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 RepeatedNotificationObserver::RepeatedNotificationObserver(int type, int count) | |
| 16 : num_outstanding_(count), running_(false) { | |
| 17 registrar_.Add(this, type, NotificationService::AllSources()); | |
| 18 } | |
| 19 | |
| 20 void RepeatedNotificationObserver::Observe(int type, | |
| 21 const NotificationSource& source, | |
| 22 const NotificationDetails& details) { | |
| 23 ASSERT_GT(num_outstanding_, 0); | |
| 24 if (!--num_outstanding_ && running_) | |
| 25 run_loop_.QuitWhenIdle(); | |
| 26 } | |
| 27 | |
| 28 void RepeatedNotificationObserver::Wait() { | |
| 29 if (num_outstanding_ <= 0) | |
| 30 return; | |
| 31 | |
| 32 { | |
| 33 DCHECK(!running_); | |
| 34 base::AutoReset<bool> auto_reset(&running_, true); | |
| 35 run_loop_.Run(); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 } // namespace content | |
| OLD | NEW |