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 // The provided destination for the enumerated modules should be empty, as it |
| 392 // should only be populated once, by a single ModuleEnumerator instance. See |
| 393 // EnumerateModulesModel::ScanNow for details. |
| 394 DCHECK(enumerated_modules_->empty()); |
392 | 395 |
393 // Make sure the path mapping vector is setup so we can collapse paths. | 396 // Make sure the path mapping vector is setup so we can collapse paths. |
394 PreparePathMappings(); | 397 PreparePathMappings(); |
395 | 398 |
396 // Enumerating loaded modules must happen first since the other types of | 399 // Enumerating loaded modules must happen first since the other types of |
397 // modules check for duplication against the loaded modules. | 400 // modules check for duplication against the loaded modules. |
398 base::TimeTicks checkpoint = base::TimeTicks::Now(); | 401 base::TimeTicks checkpoint = base::TimeTicks::Now(); |
399 EnumerateLoadedModules(); | 402 EnumerateLoadedModules(); |
400 base::TimeTicks checkpoint2 = base::TimeTicks::Now(); | 403 base::TimeTicks checkpoint2 = base::TimeTicks::Now(); |
401 UMA_HISTOGRAM_TIMES("Conflicts.EnumerateLoadedModules", | 404 UMA_HISTOGRAM_TIMES("Conflicts.EnumerateLoadedModules", |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 FROM_HERE, | 720 FROM_HERE, |
718 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 721 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
719 base::Bind(&EnumerateModulesModel::ScanNow, base::Unretained(this))); | 722 base::Bind(&EnumerateModulesModel::ScanNow, base::Unretained(this))); |
720 done = true; | 723 done = true; |
721 } | 724 } |
722 } | 725 } |
723 | 726 |
724 void EnumerateModulesModel::ScanNow() { | 727 void EnumerateModulesModel::ScanNow() { |
725 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 728 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
726 | 729 |
727 // If a module enumerator exists then a scan is already underway. | 730 // |module_enumerator_| is used as a lock to know whether or not there are |
| 731 // active/pending blocking pool tasks. If a module enumerator exists then a |
| 732 // scan is already underway. Otherwise, either no scan has been completed or |
| 733 // a scan has terminated. |
728 if (module_enumerator_) | 734 if (module_enumerator_) |
729 return; | 735 return; |
730 | 736 |
| 737 // Only allow a single scan per process lifetime. Immediately notify any |
| 738 // observers that the scan is complete. At this point |enumerated_modules_| is |
| 739 // safe to access as no potentially racing blocking pool task can exist. |
| 740 if (!enumerated_modules_.empty()) { |
| 741 FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted()); |
| 742 return; |
| 743 } |
| 744 |
731 // ScanNow does not block, rather it simply schedules a task. | 745 // ScanNow does not block, rather it simply schedules a task. |
732 module_enumerator_.reset(new ModuleEnumerator(this)); | 746 module_enumerator_.reset(new ModuleEnumerator(this)); |
733 module_enumerator_->ScanNow(&enumerated_modules_); | 747 module_enumerator_->ScanNow(&enumerated_modules_); |
734 } | 748 } |
735 | 749 |
736 base::ListValue* EnumerateModulesModel::GetModuleList() { | 750 base::ListValue* EnumerateModulesModel::GetModuleList() { |
737 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 751 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
738 | 752 |
739 // If a |module_enumerator_| is still around then scanning has not yet | 753 // If a |module_enumerator_| is still around then scanning has not yet |
740 // completed, and it is unsafe to read from |enumerated_modules_|. | 754 // 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(); | 875 module_enumerator_.reset(); |
862 | 876 |
863 UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules", | 877 UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules", |
864 suspected_bad_modules_detected_); | 878 suspected_bad_modules_detected_); |
865 UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules", | 879 UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules", |
866 confirmed_bad_modules_detected_); | 880 confirmed_bad_modules_detected_); |
867 | 881 |
868 // Forward the callback to any registered observers. | 882 // Forward the callback to any registered observers. |
869 FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted()); | 883 FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted()); |
870 } | 884 } |
OLD | NEW |