Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: chrome/browser/conflicts/module_inspector_win.cc

Issue 2721503003: Add ModuleInspector (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698