Chromium Code Reviews| 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 c775d8af9ac78290687e1fe8f4a7837c17214a1b..24b669aed555b7ce297f46707e07fb46f0b44f2b 100644 |
| --- a/chrome/browser/download/save_page_browsertest.cc |
| +++ b/chrome/browser/download/save_page_browsertest.cc |
| @@ -68,10 +68,10 @@ 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), |
| + quit_waiting_callback_(), |
|
Randy Smith (Not in Mondays)
2015/10/19 19:37:02
I think member variables normally are default cons
Łukasz Anforowicz
2015/10/19 22:04:39
Done.
In the original patchset/snapshot, I left t
|
| + persisted_(false) { |
| DownloadServiceFactory::GetForBrowserContext(profile_)-> |
| GetDownloadHistory()->AddObserver(this); |
| } |
| @@ -86,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()->Quit(); |
| + 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); |
| @@ -114,17 +115,17 @@ class DownloadRemovedObserver : public DownloadPersistedObserver { |
| DownloadRemovedObserver(Profile* profile, int32 download_id) |
| : DownloadPersistedObserver(profile, PersistedFilter()), |
| removed_(false), |
| - waiting_(false), |
| - download_id_(download_id) { |
| - } |
| + quit_waiting_callback_(), |
|
Randy Smith (Not in Mondays)
2015/10/19 19:37:01
Ditto (can remove line).
Łukasz Anforowicz
2015/10/19 22:04:39
Done.
|
| + 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_; |
| } |
| @@ -133,13 +134,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()->Quit(); |
| + 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); |
| @@ -191,7 +192,7 @@ static const char kAppendedExtension[] = ".html"; |
| class DownloadItemCreatedObserver : public DownloadManager::Observer { |
| public: |
| explicit DownloadItemCreatedObserver(DownloadManager* manager) |
| - : waiting_(false), manager_(manager) { |
| + : quit_waiting_callback_(), manager_(manager) { |
|
Randy Smith (Not in Mondays)
2015/10/19 19:37:02
Ditto.
Łukasz Anforowicz
2015/10/19 22:04:39
Done.
|
| manager->AddObserver(this); |
| } |
| @@ -213,9 +214,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_; |
| @@ -229,18 +231,18 @@ class DownloadItemCreatedObserver : public DownloadManager::Observer { |
| DCHECK_EQ(manager, manager_); |
| items_seen_.push_back(item); |
| - if (waiting_) |
| - base::MessageLoopForUI::current()->Quit(); |
| + 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()->Quit(); |
| + if (!quit_waiting_callback_.is_null()) |
| + quit_waiting_callback_.Run(); |
| } |
| - bool waiting_; |
| + base::Closure quit_waiting_callback_; |
| DownloadManager* manager_; |
| std::vector<DownloadItem*> items_seen_; |