Chromium Code Reviews| Index: chrome/browser/chromeos/base/file_flusher.cc |
| diff --git a/chrome/browser/chromeos/base/file_flusher.cc b/chrome/browser/chromeos/base/file_flusher.cc |
| index 43e06b5875dd34e5c58c3c566196ba7c1a353dab..45d5d1375fee964cf59e69533b94c77b95b08283 100644 |
| --- a/chrome/browser/chromeos/base/file_flusher.cc |
| +++ b/chrome/browser/chromeos/base/file_flusher.cc |
| @@ -4,6 +4,7 @@ |
| #include "chrome/browser/chromeos/base/file_flusher.h" |
| +#include <algorithm> |
| #include <set> |
| #include "base/bind.h" |
| @@ -68,6 +69,7 @@ class FileFlusher::Job { |
| bool started_ = false; |
| base::CancellationFlag cancel_flag_; |
| + bool finish_scheduled_ = false; |
| DISALLOW_COPY_AND_ASSIGN(Job); |
| }; |
| @@ -143,6 +145,10 @@ bool FileFlusher::Job::ShouldExclude(const base::FilePath& path) const { |
| } |
| void FileFlusher::Job::ScheduleFinish() { |
| + if (finish_scheduled_) |
| + return; |
| + |
| + finish_scheduled_ = true; |
| content::BrowserThread::PostTask( |
| content::BrowserThread::UI, FROM_HERE, |
| base::Bind(&Job::FinishOnUIThread, base::Unretained(this))); |
| @@ -183,8 +189,19 @@ void FileFlusher::RequestFlush(const base::FilePath& path, |
| ScheduleJob(); |
| } |
| +void FileFlusher::PauseForTest() { |
| + DCHECK(std::none_of(jobs_.begin(), jobs_.end(), |
|
achuithb
2016/09/15 18:36:56
Wow, nice. It's like python.
|
| + [](const Job* job) { return job->started(); })); |
| + paused_for_test_ = true; |
| +} |
| + |
| +void FileFlusher::ResumeForTest() { |
| + paused_for_test_ = false; |
| + ScheduleJob(); |
| +} |
| + |
| void FileFlusher::ScheduleJob() { |
| - if (jobs_.empty()) |
| + if (jobs_.empty() || paused_for_test_) |
| return; |
| auto* job = jobs_.front(); |