OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/conflicts/module_inspector_win.h" |
| 6 |
| 7 #include "base/task_scheduler/post_task.h" |
| 8 |
| 9 namespace { |
| 10 |
| 11 StringMapping GetPathMapping() { |
| 12 return GetEnvironmentVariablesMapping({ |
| 13 L"LOCALAPPDATA", L"ProgramFiles", L"ProgramData", L"USERPROFILE", |
| 14 L"SystemRoot", L"TEMP", L"TMP", L"CommonProgramFiles", |
| 15 }); |
| 16 } |
| 17 |
| 18 } // namespace |
| 19 |
| 20 ModuleInspector::ModuleInspector(Delegate* delegate) |
| 21 : delegate_(delegate), |
| 22 inspection_task_traits_( |
| 23 base::TaskTraits() |
| 24 .MayBlock() |
| 25 .WithPriority(base::TaskPriority::BACKGROUND) |
| 26 .WithShutdownBehavior( |
| 27 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)), |
| 28 path_mapping_(GetPathMapping()), |
| 29 weak_ptr_factory_(this) {} |
| 30 |
| 31 ModuleInspector::~ModuleInspector() = default; |
| 32 |
| 33 void ModuleInspector::AddModule(const ModuleInfoKey& module_key) { |
| 34 queue_.push(module_key); |
| 35 if (queue_.size() == 1) |
| 36 StartInspectingModule(); |
| 37 } |
| 38 |
| 39 void ModuleInspector::IncreaseInspectionPriority() { |
| 40 // Modify the task traits so that future inspections are done faster. |
| 41 inspection_task_traits_ = |
| 42 inspection_task_traits_.WithPriority(base::TaskPriority::USER_VISIBLE); |
| 43 } |
| 44 |
| 45 void ModuleInspector::StartInspectingModule() { |
| 46 ModuleInfoKey module_key = queue_.front(); |
| 47 queue_.pop(); |
| 48 |
| 49 base::PostTaskWithTraitsAndReplyWithResult( |
| 50 FROM_HERE, inspection_task_traits_, |
| 51 base::Bind(&InspectModule, path_mapping_, module_key), |
| 52 base::Bind(&ModuleInspector::OnInspectionFinished, |
| 53 weak_ptr_factory_.GetWeakPtr(), module_key)); |
| 54 } |
| 55 |
| 56 void ModuleInspector::OnInspectionFinished(const ModuleInfoKey& module_key, |
| 57 const ModuleInfoData& module_data) { |
| 58 delegate_->OnModuleInspected(module_key, module_data); |
| 59 |
| 60 // Continue the work. |
| 61 if (!queue_.empty()) |
| 62 StartInspectingModule(); |
| 63 } |
OLD | NEW |