Chromium Code Reviews| 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 <utility> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/task_scheduler/post_task.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 StringMapping GetPathMapping() { | |
| 15 return GetEnvironmentVariablesMapping({ | |
| 16 L"LOCALAPPDATA", L"ProgramFiles", L"ProgramData", L"USERPROFILE", | |
| 17 L"SystemRoot", L"TEMP", L"TMP", L"CommonProgramFiles", | |
| 18 }); | |
| 19 } | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 ModuleInspector::ModuleInspector( | |
| 24 const OnModuleInspectedCallback& on_module_inspected_callback) | |
| 25 : on_module_inspected_callback_(on_module_inspected_callback), | |
| 26 inspection_task_traits_( | |
| 27 base::TaskTraits() | |
| 28 .MayBlock() | |
| 29 .WithPriority(base::TaskPriority::BACKGROUND) | |
| 30 .WithShutdownBehavior( | |
| 31 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)), | |
| 32 path_mapping_(GetPathMapping()), | |
| 33 weak_ptr_factory_(this) {} | |
| 34 | |
| 35 ModuleInspector::~ModuleInspector() = default; | |
| 36 | |
| 37 void ModuleInspector::AddModule(const ModuleInfoKey& module_key) { | |
| 38 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 39 queue_.push(module_key); | |
| 40 if (queue_.size() == 1) | |
| 41 StartInspectingModule(); | |
| 42 } | |
| 43 | |
| 44 void ModuleInspector::IncreaseInspectionPriority() { | |
| 45 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 46 // Modify the task traits so that future inspections are done faster. | |
| 47 inspection_task_traits_ = | |
| 48 inspection_task_traits_.WithPriority(base::TaskPriority::USER_VISIBLE); | |
| 49 } | |
| 50 | |
| 51 void ModuleInspector::StartInspectingModule() { | |
| 52 ModuleInfoKey module_key = queue_.front(); | |
| 53 queue_.pop(); | |
| 54 | |
| 55 base::PostTaskWithTraitsAndReplyWithResult( | |
|
chrisha
2017/03/04 16:09:07
That's convenient! Wasn't aware of this variant of
| |
| 56 FROM_HERE, inspection_task_traits_, | |
| 57 base::Bind(&InspectModule, path_mapping_, module_key), | |
| 58 base::Bind(&ModuleInspector::OnInspectionFinished, | |
| 59 weak_ptr_factory_.GetWeakPtr(), module_key)); | |
| 60 } | |
| 61 | |
| 62 void ModuleInspector::OnInspectionFinished( | |
| 63 const ModuleInfoKey& module_key, | |
| 64 std::unique_ptr<ModuleInspectionResult> inspection_result) { | |
| 65 on_module_inspected_callback_.Run(module_key, std::move(inspection_result)); | |
| 66 | |
| 67 // Continue the work. | |
| 68 if (!queue_.empty()) | |
| 69 StartInspectingModule(); | |
| 70 } | |
| OLD | NEW |