Chromium Code Reviews| 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior( | 381 BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior( |
| 382 FROM_HERE, | 382 FROM_HERE, |
| 383 base::Bind(&ModuleEnumerator::ScanImpl, | 383 base::Bind(&ModuleEnumerator::ScanImpl, |
| 384 base::Unretained(this)), | 384 base::Unretained(this)), |
| 385 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 385 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void ModuleEnumerator::ScanImpl() { | 388 void ModuleEnumerator::ScanImpl() { |
| 389 base::TimeTicks start_time = base::TimeTicks::Now(); | 389 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 390 | 390 |
| 391 enumerated_modules_->clear(); | 391 enumerated_modules_->clear(); |
|
gab
2016/09/27 15:11:24
DCHECK(enumerated_modules_->empty()); instead with
chrisha
2016/09/27 15:29:07
Great idea. Done.
| |
| 392 | 392 |
| 393 // Make sure the path mapping vector is setup so we can collapse paths. | 393 // Make sure the path mapping vector is setup so we can collapse paths. |
| 394 PreparePathMappings(); | 394 PreparePathMappings(); |
| 395 | 395 |
| 396 // Enumerating loaded modules must happen first since the other types of | 396 // Enumerating loaded modules must happen first since the other types of |
| 397 // modules check for duplication against the loaded modules. | 397 // modules check for duplication against the loaded modules. |
| 398 base::TimeTicks checkpoint = base::TimeTicks::Now(); | 398 base::TimeTicks checkpoint = base::TimeTicks::Now(); |
| 399 EnumerateLoadedModules(); | 399 EnumerateLoadedModules(); |
| 400 base::TimeTicks checkpoint2 = base::TimeTicks::Now(); | 400 base::TimeTicks checkpoint2 = base::TimeTicks::Now(); |
| 401 UMA_HISTOGRAM_TIMES("Conflicts.EnumerateLoadedModules", | 401 UMA_HISTOGRAM_TIMES("Conflicts.EnumerateLoadedModules", |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 FROM_HERE, | 717 FROM_HERE, |
| 718 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 718 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
| 719 base::Bind(&EnumerateModulesModel::ScanNow, base::Unretained(this))); | 719 base::Bind(&EnumerateModulesModel::ScanNow, base::Unretained(this))); |
| 720 done = true; | 720 done = true; |
| 721 } | 721 } |
| 722 } | 722 } |
| 723 | 723 |
| 724 void EnumerateModulesModel::ScanNow() { | 724 void EnumerateModulesModel::ScanNow() { |
| 725 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 725 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 726 | 726 |
| 727 // If a module enumerator exists then a scan is already underway. | 727 // If a module enumerator exists then a scan is already underway. The client |
| 728 // will receive a notification from that thread. | |
| 728 if (module_enumerator_) | 729 if (module_enumerator_) |
| 729 return; | 730 return; |
| 730 | 731 |
| 732 // Only allow a single scan per process lifetime. Immediately notify any | |
| 733 // observers that the scan is complete. | |
| 734 if (!enumerated_modules_.empty()) { | |
|
gab
2016/09/27 14:27:11
I'm not convinced usage of |enumerated_modules_| i
chrisha
2016/09/27 14:49:39
Greg and I had extensive discussions on the thread
gab
2016/09/27 15:11:24
Indeed, I meant the BlockingPool tasks "racing eac
chrisha
2016/09/27 15:29:07
There's some other cleanup I want to do as well (m
| |
| 735 FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted()); | |
| 736 return; | |
| 737 } | |
| 738 | |
| 731 // ScanNow does not block, rather it simply schedules a task. | 739 // ScanNow does not block, rather it simply schedules a task. |
| 732 module_enumerator_.reset(new ModuleEnumerator(this)); | 740 module_enumerator_.reset(new ModuleEnumerator(this)); |
| 733 module_enumerator_->ScanNow(&enumerated_modules_); | 741 module_enumerator_->ScanNow(&enumerated_modules_); |
| 734 } | 742 } |
| 735 | 743 |
| 736 base::ListValue* EnumerateModulesModel::GetModuleList() { | 744 base::ListValue* EnumerateModulesModel::GetModuleList() { |
| 737 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 745 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 738 | 746 |
| 739 // If a |module_enumerator_| is still around then scanning has not yet | 747 // If a |module_enumerator_| is still around then scanning has not yet |
| 740 // completed, and it is unsafe to read from |enumerated_modules_|. | 748 // completed, and it is unsafe to read from |enumerated_modules_|. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 module_enumerator_.reset(); | 869 module_enumerator_.reset(); |
| 862 | 870 |
| 863 UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules", | 871 UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules", |
| 864 suspected_bad_modules_detected_); | 872 suspected_bad_modules_detected_); |
| 865 UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules", | 873 UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules", |
| 866 confirmed_bad_modules_detected_); | 874 confirmed_bad_modules_detected_); |
| 867 | 875 |
| 868 // Forward the callback to any registered observers. | 876 // Forward the callback to any registered observers. |
| 869 FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted()); | 877 FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted()); |
| 870 } | 878 } |
| OLD | NEW |