| Index: chrome/browser/conflicts/module_inspector_win.cc
|
| diff --git a/chrome/browser/conflicts/module_inspector_win.cc b/chrome/browser/conflicts/module_inspector_win.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9cc4e7d38fa5c116d9ac0f4b5ce402437590745b
|
| --- /dev/null
|
| +++ b/chrome/browser/conflicts/module_inspector_win.cc
|
| @@ -0,0 +1,63 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/conflicts/module_inspector_win.h"
|
| +
|
| +#include "base/task_scheduler/post_task.h"
|
| +
|
| +namespace {
|
| +
|
| +StringMapping GetPathMapping() {
|
| + return GetEnvironmentVariablesMapping({
|
| + L"LOCALAPPDATA", L"ProgramFiles", L"ProgramData", L"USERPROFILE",
|
| + L"SystemRoot", L"TEMP", L"TMP", L"CommonProgramFiles",
|
| + });
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +ModuleInspector::ModuleInspector(Delegate* delegate)
|
| + : delegate_(delegate),
|
| + inspection_task_traits_(
|
| + base::TaskTraits()
|
| + .MayBlock()
|
| + .WithPriority(base::TaskPriority::BACKGROUND)
|
| + .WithShutdownBehavior(
|
| + base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)),
|
| + path_mapping_(GetPathMapping()),
|
| + weak_ptr_factory_(this) {}
|
| +
|
| +ModuleInspector::~ModuleInspector() = default;
|
| +
|
| +void ModuleInspector::AddModule(const ModuleInfoKey& module_key) {
|
| + queue_.push(module_key);
|
| + if (queue_.size() == 1)
|
| + StartInspectingModule();
|
| +}
|
| +
|
| +void ModuleInspector::IncreaseInspectionPriority() {
|
| + // Modify the task traits so that future inspections are done faster.
|
| + inspection_task_traits_ =
|
| + inspection_task_traits_.WithPriority(base::TaskPriority::USER_VISIBLE);
|
| +}
|
| +
|
| +void ModuleInspector::StartInspectingModule() {
|
| + ModuleInfoKey module_key = queue_.front();
|
| + queue_.pop();
|
| +
|
| + base::PostTaskWithTraitsAndReplyWithResult(
|
| + FROM_HERE, inspection_task_traits_,
|
| + base::Bind(&InspectModule, path_mapping_, module_key),
|
| + base::Bind(&ModuleInspector::OnInspectionFinished,
|
| + weak_ptr_factory_.GetWeakPtr(), module_key));
|
| +}
|
| +
|
| +void ModuleInspector::OnInspectionFinished(const ModuleInfoKey& module_key,
|
| + const ModuleInfoData& module_data) {
|
| + delegate_->OnModuleInspected(module_key, module_data);
|
| +
|
| + // Continue the work.
|
| + if (!queue_.empty())
|
| + StartInspectingModule();
|
| +}
|
|
|