Commit 07edac9e authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

Migrate away from deprecated RunLoop API

Instead, we keep around an instance of base::RunLoop and pass it
explicitly for Quit(), which makes sure the code quits the intended loop
and not a nested one.

Bug: 783774
Change-Id: I3ea5092699bbae127f581e5c955cb27904d98f0a
Reviewed-on: https://chromium-review.googlesource.com/784790Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519664}
parent cc2743d5
......@@ -87,13 +87,15 @@ class FaviconChangeObserver : public bookmarks::BookmarkModelObserver {
}
~FaviconChangeObserver() override { model_->RemoveObserver(this); }
void WaitForGetFavicon() {
DCHECK(!run_loop_.running());
wait_for_load_ = true;
content::RunMessageLoop();
content::RunThisRunLoop(&run_loop_);
ASSERT_TRUE(node_->is_favicon_loaded());
}
void WaitForSetFavicon() {
DCHECK(!run_loop_.running());
wait_for_load_ = false;
content::RunMessageLoop();
content::RunThisRunLoop(&run_loop_);
}
// bookmarks::BookmarkModelObserver:
......@@ -125,9 +127,9 @@ class FaviconChangeObserver : public bookmarks::BookmarkModelObserver {
const BookmarkNode* node) override {}
void BookmarkNodeFaviconChanged(BookmarkModel* model,
const BookmarkNode* node) override {
if (model == model_ && node == node_) {
if (model == model_ && node == node_ && run_loop_.running()) {
if (!wait_for_load_ || (wait_for_load_ && node->is_favicon_loaded()))
base::RunLoop::QuitCurrentWhenIdleDeprecated();
run_loop_.Quit();
}
}
......@@ -135,6 +137,7 @@ class FaviconChangeObserver : public bookmarks::BookmarkModelObserver {
BookmarkModel* model_;
const BookmarkNode* node_;
bool wait_for_load_;
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(FaviconChangeObserver);
};
......
......@@ -49,15 +49,17 @@ class PasswordStoreConsumerHelper
void OnGetPasswordStoreResults(
std::vector<std::unique_ptr<PasswordForm>> results) override {
result_.swap(results);
// Quit the message loop to wake up passwords_helper::GetLogins.
base::RunLoop::QuitCurrentWhenIdleDeprecated();
run_loop_.Quit();
}
std::vector<std::unique_ptr<PasswordForm>> result() {
std::vector<std::unique_ptr<PasswordForm>> WaitForResult() {
DCHECK(!run_loop_.running());
content::RunThisRunLoop(&run_loop_);
return std::move(result_);
}
private:
base::RunLoop run_loop_;
std::vector<std::unique_ptr<PasswordForm>> result_;
DISALLOW_COPY_AND_ASSIGN(PasswordStoreConsumerHelper);
......@@ -101,8 +103,7 @@ std::vector<std::unique_ptr<PasswordForm>> GetLogins(PasswordStore* store) {
PasswordForm::SCHEME_HTML, kFakeSignonRealm, GURL()};
PasswordStoreConsumerHelper consumer;
store->GetLogins(matcher_form, &consumer);
content::RunMessageLoop();
return consumer.result();
return consumer.WaitForResult();
}
void RemoveLogin(PasswordStore* store, const PasswordForm& form) {
......
......@@ -8,7 +8,9 @@
#include "base/run_loop.h"
#include "base/timer/timer.h"
StatusChangeChecker::StatusChangeChecker() : timed_out_(false) {}
StatusChangeChecker::StatusChangeChecker()
: run_loop_(base::RunLoop::Type::kNestableTasksAllowed),
timed_out_(false) {}
StatusChangeChecker::~StatusChangeChecker() {}
......@@ -30,18 +32,9 @@ base::TimeDelta StatusChangeChecker::GetTimeoutDuration() {
return base::TimeDelta::FromSeconds(45);
}
void StatusChangeChecker::StartBlockingWait() {
base::OneShotTimer timer;
timer.Start(FROM_HERE,
GetTimeoutDuration(),
base::Bind(&StatusChangeChecker::OnTimeout,
base::Unretained(this)));
base::RunLoop(base::RunLoop::Type::kNestableTasksAllowed).Run();
}
void StatusChangeChecker::StopWaiting() {
base::RunLoop::QuitCurrentWhenIdleDeprecated();
if (run_loop_.running())
run_loop_.Quit();
}
void StatusChangeChecker::CheckExitCondition() {
......@@ -52,6 +45,17 @@ void StatusChangeChecker::CheckExitCondition() {
}
}
void StatusChangeChecker::StartBlockingWait() {
DCHECK(!run_loop_.running());
base::OneShotTimer timer;
timer.Start(
FROM_HERE, GetTimeoutDuration(),
base::Bind(&StatusChangeChecker::OnTimeout, base::Unretained(this)));
run_loop_.Run();
}
void StatusChangeChecker::OnTimeout() {
DVLOG(1) << "Await -> Timed out: " << GetDebugMessage();
timed_out_ = true;
......
......@@ -7,6 +7,7 @@
#include <string>
#include "base/run_loop.h"
#include "base/time/time.h"
// Interface for a helper class that can pump the message loop while waiting
......@@ -45,14 +46,6 @@ class StatusChangeChecker {
// Timeout length when blocking.
virtual base::TimeDelta GetTimeoutDuration();
// Helper function to start running the nested run loop.
//
// Will exit if IsExitConditionSatisfied() returns true when called from
// CheckExitCondition(), if a timeout occurs, or if StopWaiting() is called.
//
// The timeout length is specified with GetTimeoutDuration().
void StartBlockingWait();
// Stop the nested running of the message loop started in StartBlockingWait().
void StopWaiting();
......@@ -60,9 +53,19 @@ class StatusChangeChecker {
// true.
void CheckExitCondition();
private:
// Helper function to start running the nested run loop (run_loop_).
//
// Will exit if IsExitConditionSatisfied() returns true when called from
// CheckExitCondition(), if a timeout occurs, or if StopWaiting() is called.
//
// The timeout length is specified with GetTimeoutDuration().
void StartBlockingWait();
// Called when the blocking wait timeout is exceeded.
void OnTimeout();
base::RunLoop run_loop_;
bool timed_out_;
};
......
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