Commit e0b982ec authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Revert "Reland #3: Switch WindowedNotificationObserver to use base::RunLoop."

This reverts commit 54fcb75f.

Reason for revert: landed too early and causing flakes

Original change's description:
> Reland #3: Switch WindowedNotificationObserver to use base::RunLoop.
> 
> Now it will quit the message loop immediately after receiving the
> notification. Also it does not allow nested tasks anymore.
> 
> Bug: 668707
> Change-Id: I8d8a0ffb073236c3bbd00877bd48cc496b1c5036
> Reviewed-on: https://chromium-review.googlesource.com/982612
> Reviewed-by: John Abd-El-Malek <jam@chromium.org>
> Reviewed-by: Gabriel Charette <gab@chromium.org>
> Commit-Queue: Alexander Semashko <ahest@yandex-team.ru>
> Cr-Commit-Position: refs/heads/master@{#576110}

TBR=gab@chromium.org,jam@chromium.org,ahest@yandex-team.ru

Change-Id: Ibc82b94b56e77bb9914c74517dd9f755527544f6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 668707
Reviewed-on: https://chromium-review.googlesource.com/1143740Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576519}
parent e630455c
...@@ -319,26 +319,33 @@ void MessageLoopRunner::Quit() { ...@@ -319,26 +319,33 @@ void MessageLoopRunner::Quit() {
WindowedNotificationObserver::WindowedNotificationObserver( WindowedNotificationObserver::WindowedNotificationObserver(
int notification_type, int notification_type,
const NotificationSource& source) const NotificationSource& source)
: source_(NotificationService::AllSources()) { : seen_(false),
running_(false),
source_(NotificationService::AllSources()) {
AddNotificationType(notification_type, source); AddNotificationType(notification_type, source);
} }
WindowedNotificationObserver::WindowedNotificationObserver( WindowedNotificationObserver::WindowedNotificationObserver(
int notification_type, int notification_type,
const ConditionTestCallback& callback) const ConditionTestCallback& callback)
: callback_(callback), source_(NotificationService::AllSources()) { : seen_(false),
running_(false),
callback_(callback),
source_(NotificationService::AllSources()) {
AddNotificationType(notification_type, source_); AddNotificationType(notification_type, source_);
} }
WindowedNotificationObserver::WindowedNotificationObserver( WindowedNotificationObserver::WindowedNotificationObserver(
int notification_type, int notification_type,
const ConditionTestCallbackWithoutSourceAndDetails& callback) const ConditionTestCallbackWithoutSourceAndDetails& callback)
: callback_(base::Bind(&IgnoreSourceAndDetails, callback)), : seen_(false),
running_(false),
callback_(base::Bind(&IgnoreSourceAndDetails, callback)),
source_(NotificationService::AllSources()) { source_(NotificationService::AllSources()) {
registrar_.Add(this, notification_type, source_); registrar_.Add(this, notification_type, source_);
} }
WindowedNotificationObserver::~WindowedNotificationObserver() = default; WindowedNotificationObserver::~WindowedNotificationObserver() {}
void WindowedNotificationObserver::AddNotificationType( void WindowedNotificationObserver::AddNotificationType(
int notification_type, int notification_type,
...@@ -347,21 +354,30 @@ void WindowedNotificationObserver::AddNotificationType( ...@@ -347,21 +354,30 @@ void WindowedNotificationObserver::AddNotificationType(
} }
void WindowedNotificationObserver::Wait() { void WindowedNotificationObserver::Wait() {
if (!seen_) if (seen_)
run_loop_.Run(); return;
running_ = true;
message_loop_runner_ = new MessageLoopRunner;
message_loop_runner_->Run();
EXPECT_TRUE(seen_); EXPECT_TRUE(seen_);
} }
void WindowedNotificationObserver::Observe(int type, void WindowedNotificationObserver::Observe(
const NotificationSource& source, int type,
const NotificationDetails& details) { const NotificationSource& source,
const NotificationDetails& details) {
source_ = source; source_ = source;
details_ = details; details_ = details;
if (!callback_.is_null() && !callback_.Run(source, details)) if (!callback_.is_null() && !callback_.Run(source, details))
return; return;
seen_ = true; seen_ = true;
run_loop_.Quit(); if (!running_)
return;
message_loop_runner_->Quit();
running_ = false;
} }
InProcessUtilityThreadHelper::InProcessUtilityThreadHelper() InProcessUtilityThreadHelper::InProcessUtilityThreadHelper()
......
...@@ -251,14 +251,15 @@ class WindowedNotificationObserver : public NotificationObserver { ...@@ -251,14 +251,15 @@ class WindowedNotificationObserver : public NotificationObserver {
const NotificationDetails& details) override; const NotificationDetails& details) override;
private: private:
bool seen_ = false; bool seen_;
bool running_;
NotificationRegistrar registrar_; NotificationRegistrar registrar_;
ConditionTestCallback callback_; ConditionTestCallback callback_;
NotificationSource source_; NotificationSource source_;
NotificationDetails details_; NotificationDetails details_;
base::RunLoop run_loop_; scoped_refptr<MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment