OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/win/enumerate_modules_model.h" | 5 #include "chrome/browser/win/enumerate_modules_model.h" |
6 | 6 |
7 #include <softpub.h> | 7 #include <softpub.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <tlhelp32.h> | 10 #include <tlhelp32.h> |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 } | 369 } |
370 | 370 |
371 ModuleEnumerator::~ModuleEnumerator() { | 371 ModuleEnumerator::~ModuleEnumerator() { |
372 } | 372 } |
373 | 373 |
374 void ModuleEnumerator::ScanNow(ModulesVector* list) { | 374 void ModuleEnumerator::ScanNow(ModulesVector* list) { |
375 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 375 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
376 enumerated_modules_ = list; | 376 enumerated_modules_ = list; |
377 | 377 |
378 // This object can't be reaped until it has finished scanning, so its safe | 378 // This object can't be reaped until it has finished scanning, so its safe |
379 // to post a raw pointer to another thread. | 379 // to post a raw pointer to another thread. It will simply be leaked if the |
380 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 380 // scanning has not been finished before shutdown. |
381 base::Bind(&ModuleEnumerator::ScanImpl, | 381 auto* pool = BrowserThread::GetBlockingPool(); |
382 base::Unretained(this))); | 382 auto token = pool->GetSequenceToken(); |
383 auto runner = pool->GetSequencedTaskRunnerWithShutdownBehavior( | |
384 token, base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | |
385 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.
| |
386 base::Bind(&ModuleEnumerator::ScanImpl, | |
387 base::Unretained(this))); | |
383 } | 388 } |
384 | 389 |
385 void ModuleEnumerator::ScanImpl() { | 390 void ModuleEnumerator::ScanImpl() { |
386 base::TimeTicks start_time = base::TimeTicks::Now(); | 391 base::TimeTicks start_time = base::TimeTicks::Now(); |
387 | 392 |
388 enumerated_modules_->clear(); | 393 enumerated_modules_->clear(); |
389 | 394 |
390 // Make sure the path mapping vector is setup so we can collapse paths. | 395 // Make sure the path mapping vector is setup so we can collapse paths. |
391 PreparePathMappings(); | 396 PreparePathMappings(); |
392 | 397 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 FROM_HERE, | 719 FROM_HERE, |
715 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 720 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
716 base::Bind(&EnumerateModulesModel::ScanNow, base::Unretained(this))); | 721 base::Bind(&EnumerateModulesModel::ScanNow, base::Unretained(this))); |
717 done = true; | 722 done = true; |
718 } | 723 } |
719 } | 724 } |
720 | 725 |
721 void EnumerateModulesModel::ScanNow() { | 726 void EnumerateModulesModel::ScanNow() { |
722 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 727 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
723 | 728 |
724 // If a module enumerator exists then a scan is already underway. | 729 // If a module enumerator exists then a scan is already underway. The client |
730 // will receive a notification from that thread. | |
725 if (module_enumerator_) | 731 if (module_enumerator_) |
726 return; | 732 return; |
727 | 733 |
734 // Only allow a single scan per process lifetime. Immediately notify any | |
735 // observers that the scan is complete. | |
736 if (!enumerated_modules_.empty()) { | |
737 FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted()); | |
738 return; | |
739 } | |
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
| |
740 | |
728 // ScanNow does not block, rather it simply schedules a task. | 741 // ScanNow does not block, rather it simply schedules a task. |
729 module_enumerator_.reset(new ModuleEnumerator(this)); | 742 module_enumerator_.reset(new ModuleEnumerator(this)); |
730 module_enumerator_->ScanNow(&enumerated_modules_); | 743 module_enumerator_->ScanNow(&enumerated_modules_); |
731 } | 744 } |
732 | 745 |
733 base::ListValue* EnumerateModulesModel::GetModuleList() { | 746 base::ListValue* EnumerateModulesModel::GetModuleList() { |
734 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 747 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
735 | 748 |
736 // If a |module_enumerator_| is still around then scanning has not yet | 749 // If a |module_enumerator_| is still around then scanning has not yet |
737 // completed, and it is unsafe to read from |enumerated_modules_|. | 750 // completed, and it is unsafe to read from |enumerated_modules_|. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
858 module_enumerator_.reset(); | 871 module_enumerator_.reset(); |
859 | 872 |
860 UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules", | 873 UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules", |
861 suspected_bad_modules_detected_); | 874 suspected_bad_modules_detected_); |
862 UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules", | 875 UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules", |
863 confirmed_bad_modules_detected_); | 876 confirmed_bad_modules_detected_); |
864 | 877 |
865 // Forward the callback to any registered observers. | 878 // Forward the callback to any registered observers. |
866 FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted()); | 879 FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted()); |
867 } | 880 } |
OLD | NEW |