Chromium Code Reviews| Index: chrome/browser/win/enumerate_modules_model.cc |
| diff --git a/chrome/browser/win/enumerate_modules_model.cc b/chrome/browser/win/enumerate_modules_model.cc |
| index ef0e556cdb2132e5572761c97e410005e45c05ce..4b64f86030b5113aeebd201b6b27385da2c42448 100644 |
| --- a/chrome/browser/win/enumerate_modules_model.cc |
| +++ b/chrome/browser/win/enumerate_modules_model.cc |
| @@ -376,10 +376,15 @@ void ModuleEnumerator::ScanNow(ModulesVector* list) { |
| enumerated_modules_ = list; |
| // This object can't be reaped until it has finished scanning, so its safe |
| - // to post a raw pointer to another thread. |
| - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&ModuleEnumerator::ScanImpl, |
| - base::Unretained(this))); |
| + // to post a raw pointer to another thread. It will simply be leaked if the |
| + // scanning has not been finished before shutdown. |
| + auto* pool = BrowserThread::GetBlockingPool(); |
| + auto token = pool->GetSequenceToken(); |
| + auto runner = pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| + token, base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| + runner->PostTask(FROM_HERE, |
|
gab
2016/09/26 19:37:21
Since you don't need a SequencedTaskRunner for mul
chrisha
2016/09/26 19:58:17
Ah, even better, thanks.
|
| + base::Bind(&ModuleEnumerator::ScanImpl, |
| + base::Unretained(this))); |
| } |
| void ModuleEnumerator::ScanImpl() { |
| @@ -721,10 +726,18 @@ void EnumerateModulesModel::MaybePostScanningTask() { |
| void EnumerateModulesModel::ScanNow() { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| - // If a module enumerator exists then a scan is already underway. |
| + // If a module enumerator exists then a scan is already underway. The client |
| + // will receive a notification from that thread. |
| if (module_enumerator_) |
| return; |
| + // Only allow a single scan per process lifetime. Immediately notify any |
| + // observers that the scan is complete. |
| + if (!enumerated_modules_.empty()) { |
| + FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted()); |
| + return; |
| + } |
|
gab
2016/09/26 19:37:21
I'm unclear on why this change is required/related
chrisha
2016/09/26 19:58:17
Oops, that was meant to be another CL. Will move i
|
| + |
| // ScanNow does not block, rather it simply schedules a task. |
| module_enumerator_.reset(new ModuleEnumerator(this)); |
| module_enumerator_->ScanNow(&enumerated_modules_); |