OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/test/extension_test_notification_observer.h" | 5 #include "extensions/test/extension_test_notification_observer.h" |
6 | 6 |
7 #include "content/public/browser/browser_context.h" | 7 #include "content/public/browser/browser_context.h" |
8 #include "content/public/browser/notification_details.h" | 8 #include "content/public/browser/notification_details.h" |
9 #include "content/public/browser/notification_registrar.h" | 9 #include "content/public/browser/notification_registrar.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 registry_observer_.RemoveAll(); | 187 registry_observer_.RemoveAll(); |
188 } | 188 } |
189 | 189 |
190 void ExtensionTestNotificationObserver::WaitForCondition( | 190 void ExtensionTestNotificationObserver::WaitForCondition( |
191 const ConditionCallback& condition, | 191 const ConditionCallback& condition, |
192 NotificationSet* notification_set) { | 192 NotificationSet* notification_set) { |
193 if (condition.Run()) | 193 if (condition.Run()) |
194 return; | 194 return; |
195 condition_ = condition; | 195 condition_ = condition; |
196 | 196 |
197 scoped_refptr<content::MessageLoopRunner> runner( | 197 base::RunLoop run_loop; |
198 new content::MessageLoopRunner); | 198 quit_closure_ = run_loop.QuitClosure(); |
199 quit_closure_ = runner->QuitClosure(); | |
200 | 199 |
201 std::unique_ptr<base::CallbackList<void()>::Subscription> subscription; | 200 std::unique_ptr<base::CallbackList<void()>::Subscription> subscription; |
202 if (notification_set) { | 201 if (notification_set) { |
203 subscription = notification_set->callback_list().Add(base::Bind( | 202 subscription = notification_set->callback_list().Add(base::Bind( |
204 &ExtensionTestNotificationObserver::MaybeQuit, base::Unretained(this))); | 203 &ExtensionTestNotificationObserver::MaybeQuit, base::Unretained(this))); |
205 } | 204 } |
206 runner->Run(); | 205 run_loop.Run(); |
207 | 206 |
208 condition_.Reset(); | 207 condition_.Reset(); |
209 quit_closure_.Reset(); | 208 quit_closure_.Reset(); |
210 } | 209 } |
211 | 210 |
212 void ExtensionTestNotificationObserver::MaybeQuit() { | 211 void ExtensionTestNotificationObserver::MaybeQuit() { |
213 if (condition_.Run()) | 212 if (condition_.Run()) |
214 quit_closure_.Run(); | 213 quit_closure_.Run(); |
215 } | 214 } |
216 | 215 |
217 } // namespace extensions | 216 } // namespace extensions |
OLD | NEW |