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

Unified Diff: content/public/test/repeated_notification_observer.cc

Issue 2798143004: Fix for URL opening code (Closed)
Patch Set: Fixed class name usage. Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/test/repeated_notification_observer.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/test/repeated_notification_observer.cc
diff --git a/content/public/test/repeated_notification_observer.cc b/content/public/test/repeated_notification_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..097ec901b50400de314d5db8e4be22185429c9af
--- /dev/null
+++ b/content/public/test/repeated_notification_observer.cc
@@ -0,0 +1,39 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/test/repeated_notification_observer.h"
+
+#include "base/auto_reset.h"
+#include "base/macros.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+RepeatedNotificationObserver::RepeatedNotificationObserver(int type, int count)
+ : num_outstanding_(count), running_(false) {
+ registrar_.Add(this, type, NotificationService::AllSources());
+}
+
+void RepeatedNotificationObserver::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ ASSERT_GT(num_outstanding_, 0);
+ if (!--num_outstanding_ && running_)
+ run_loop_.QuitWhenIdle();
+}
+
+void RepeatedNotificationObserver::Wait() {
+ if (num_outstanding_ <= 0)
+ return;
+
+ {
+ DCHECK(!running_);
+ base::AutoReset<bool> auto_reset(&running_, true);
+ run_loop_.Run();
+ }
+}
+
+} // namespace content
« no previous file with comments | « content/public/test/repeated_notification_observer.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698