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

Unified Diff: chrome/browser/download/save_page_browsertest.cc

Issue 1408993003: Using RunLoop rather than the deprecated, older loop running methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@save_page_tests_my_flakiness
Patch Set: Rebasing... Created 5 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/save_page_browsertest.cc
diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc
index 42f1a69cfa8a01ad40f8b93b01ccccfadefb4a8b..daa54c1094e7d954f03f5992591cf3081e7defcd 100644
--- a/chrome/browser/download/save_page_browsertest.cc
+++ b/chrome/browser/download/save_page_browsertest.cc
@@ -69,10 +69,9 @@ class DownloadPersistedObserver : public DownloadHistory::Observer {
const history::DownloadRow&)> PersistedFilter;
DownloadPersistedObserver(Profile* profile, const PersistedFilter& filter)
- : profile_(profile),
- filter_(filter),
- waiting_(false),
- persisted_(false) {
+ : profile_(profile),
+ filter_(filter),
+ persisted_(false) {
DownloadServiceFactory::GetForBrowserContext(profile_)->
GetDownloadHistory()->AddObserver(this);
}
@@ -87,23 +86,24 @@ class DownloadPersistedObserver : public DownloadHistory::Observer {
bool WaitForPersisted() {
if (persisted_)
return true;
- waiting_ = true;
- content::RunMessageLoop();
- waiting_ = false;
+ base::RunLoop run_loop;
+ quit_waiting_callback_ = run_loop.QuitClosure();
+ run_loop.Run();
+ quit_waiting_callback_ = base::Closure();
return persisted_;
}
void OnDownloadStored(DownloadItem* item,
const history::DownloadRow& info) override {
persisted_ = persisted_ || filter_.Run(item, info);
- if (persisted_ && waiting_)
- base::MessageLoopForUI::current()->QuitWhenIdle();
+ if (persisted_ && !quit_waiting_callback_.is_null())
+ quit_waiting_callback_.Run();
}
private:
Profile* profile_;
PersistedFilter filter_;
- bool waiting_;
+ base::Closure quit_waiting_callback_;
bool persisted_;
DISALLOW_COPY_AND_ASSIGN(DownloadPersistedObserver);
@@ -115,17 +115,16 @@ class DownloadRemovedObserver : public DownloadPersistedObserver {
DownloadRemovedObserver(Profile* profile, int32 download_id)
: DownloadPersistedObserver(profile, PersistedFilter()),
removed_(false),
- waiting_(false),
- download_id_(download_id) {
- }
+ download_id_(download_id) {}
~DownloadRemovedObserver() override {}
bool WaitForRemoved() {
if (removed_)
return true;
- waiting_ = true;
- content::RunMessageLoop();
- waiting_ = false;
+ base::RunLoop run_loop;
+ quit_waiting_callback_ = run_loop.QuitClosure();
+ run_loop.Run();
+ quit_waiting_callback_ = base::Closure();
return removed_;
}
@@ -134,13 +133,13 @@ class DownloadRemovedObserver : public DownloadPersistedObserver {
void OnDownloadsRemoved(const DownloadHistory::IdSet& ids) override {
removed_ = ids.find(download_id_) != ids.end();
- if (removed_ && waiting_)
- base::MessageLoopForUI::current()->QuitWhenIdle();
+ if (removed_ && !quit_waiting_callback_.is_null())
+ quit_waiting_callback_.Run();
}
private:
bool removed_;
- bool waiting_;
+ base::Closure quit_waiting_callback_;
int32 download_id_;
DISALLOW_COPY_AND_ASSIGN(DownloadRemovedObserver);
@@ -192,7 +191,7 @@ static const char kAppendedExtension[] = ".html";
class DownloadItemCreatedObserver : public DownloadManager::Observer {
public:
explicit DownloadItemCreatedObserver(DownloadManager* manager)
- : waiting_(false), manager_(manager) {
+ : manager_(manager) {
manager->AddObserver(this);
}
@@ -214,9 +213,10 @@ class DownloadItemCreatedObserver : public DownloadManager::Observer {
}
if (items_seen_.empty()) {
- waiting_ = true;
- content::RunMessageLoop();
- waiting_ = false;
+ base::RunLoop run_loop;
+ quit_waiting_callback_ = run_loop.QuitClosure();
+ run_loop.Run();
+ quit_waiting_callback_ = base::Closure();
}
*items_seen = items_seen_;
@@ -230,18 +230,18 @@ class DownloadItemCreatedObserver : public DownloadManager::Observer {
DCHECK_EQ(manager, manager_);
items_seen_.push_back(item);
- if (waiting_)
- base::MessageLoopForUI::current()->QuitWhenIdle();
+ if (!quit_waiting_callback_.is_null())
+ quit_waiting_callback_.Run();
}
void ManagerGoingDown(DownloadManager* manager) override {
manager_->RemoveObserver(this);
manager_ = NULL;
- if (waiting_)
- base::MessageLoopForUI::current()->QuitWhenIdle();
+ if (!quit_waiting_callback_.is_null())
+ quit_waiting_callback_.Run();
}
- bool waiting_;
+ base::Closure quit_waiting_callback_;
DownloadManager* manager_;
std::vector<DownloadItem*> items_seen_;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698