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

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

Issue 2916663002: Pass the path mapping via RefCountedData in ModuleInspector (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « chrome/browser/conflicts/module_inspector_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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/conflicts/module_inspector_win.h" 5 #include "chrome/browser/conflicts/module_inspector_win.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/task_scheduler/post_task.h" 10 #include "base/task_scheduler/post_task.h"
11 11
12 namespace { 12 namespace {
13 13
14 StringMapping GetPathMapping() { 14 StringMapping GetPathMapping() {
15 return GetEnvironmentVariablesMapping({ 15 return GetEnvironmentVariablesMapping({
16 L"LOCALAPPDATA", L"ProgramFiles", L"ProgramData", L"USERPROFILE", 16 L"LOCALAPPDATA", L"ProgramFiles", L"ProgramData", L"USERPROFILE",
17 L"SystemRoot", L"TEMP", L"TMP", L"CommonProgramFiles", 17 L"SystemRoot", L"TEMP", L"TMP", L"CommonProgramFiles",
18 }); 18 });
19 } 19 }
20 20
21 // Wrapper function for InspectModule() that takes the StringMapping via a
22 // scoped_refptr. This saves a copy per invocation.
23 std::unique_ptr<ModuleInspectionResult> InspectModuleOnBlockingSequence(
24 scoped_refptr<base::RefCountedData<StringMapping>> env_variable_mapping,
25 const ModuleInfoKey& module_key) {
26 return InspectModule(env_variable_mapping->data, module_key);
27 }
28
21 } // namespace 29 } // namespace
22 30
23 ModuleInspector::ModuleInspector( 31 ModuleInspector::ModuleInspector(
24 const OnModuleInspectedCallback& on_module_inspected_callback) 32 const OnModuleInspectedCallback& on_module_inspected_callback)
25 : on_module_inspected_callback_(on_module_inspected_callback), 33 : on_module_inspected_callback_(on_module_inspected_callback),
26 inspection_task_priority_(base::TaskPriority::BACKGROUND), 34 inspection_task_priority_(base::TaskPriority::BACKGROUND),
27 path_mapping_(GetPathMapping()), 35 path_mapping_(base::MakeRefCounted<base::RefCountedData<StringMapping>>(
36 GetPathMapping())),
28 weak_ptr_factory_(this) {} 37 weak_ptr_factory_(this) {}
29 38
30 ModuleInspector::~ModuleInspector() = default; 39 ModuleInspector::~ModuleInspector() = default;
31 40
32 void ModuleInspector::AddModule(const ModuleInfoKey& module_key) { 41 void ModuleInspector::AddModule(const ModuleInfoKey& module_key) {
33 DCHECK(thread_checker_.CalledOnValidThread()); 42 DCHECK(thread_checker_.CalledOnValidThread());
34 queue_.push(module_key); 43 queue_.push(module_key);
35 if (queue_.size() == 1) 44 if (queue_.size() == 1)
36 StartInspectingModule(); 45 StartInspectingModule();
37 } 46 }
38 47
39 void ModuleInspector::IncreaseInspectionPriority() { 48 void ModuleInspector::IncreaseInspectionPriority() {
40 DCHECK(thread_checker_.CalledOnValidThread()); 49 DCHECK(thread_checker_.CalledOnValidThread());
41 // Modify the TaskPriority so that future inspections are done faster. 50 // Modify the TaskPriority so that future inspections are done faster.
42 inspection_task_priority_ = base::TaskPriority::USER_VISIBLE; 51 inspection_task_priority_ = base::TaskPriority::USER_VISIBLE;
43 } 52 }
44 53
45 void ModuleInspector::StartInspectingModule() { 54 void ModuleInspector::StartInspectingModule() {
46 ModuleInfoKey module_key = queue_.front(); 55 ModuleInfoKey module_key = queue_.front();
47 queue_.pop(); 56 queue_.pop();
48 57
49 base::PostTaskWithTraitsAndReplyWithResult( 58 base::PostTaskWithTraitsAndReplyWithResult(
50 FROM_HERE, 59 FROM_HERE,
51 {base::MayBlock(), inspection_task_priority_, 60 {base::MayBlock(), inspection_task_priority_,
52 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, 61 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
53 base::BindOnce(&InspectModule, path_mapping_, module_key), 62 base::BindOnce(&InspectModuleOnBlockingSequence, path_mapping_,
63 module_key),
54 base::BindOnce(&ModuleInspector::OnInspectionFinished, 64 base::BindOnce(&ModuleInspector::OnInspectionFinished,
55 weak_ptr_factory_.GetWeakPtr(), module_key)); 65 weak_ptr_factory_.GetWeakPtr(), module_key));
56 } 66 }
57 67
58 void ModuleInspector::OnInspectionFinished( 68 void ModuleInspector::OnInspectionFinished(
59 const ModuleInfoKey& module_key, 69 const ModuleInfoKey& module_key,
60 std::unique_ptr<ModuleInspectionResult> inspection_result) { 70 std::unique_ptr<ModuleInspectionResult> inspection_result) {
61 on_module_inspected_callback_.Run(module_key, std::move(inspection_result)); 71 on_module_inspected_callback_.Run(module_key, std::move(inspection_result));
62 72
63 // Continue the work. 73 // Continue the work.
64 if (!queue_.empty()) 74 if (!queue_.empty())
65 StartInspectingModule(); 75 StartInspectingModule();
66 } 76 }
OLDNEW
« no previous file with comments | « chrome/browser/conflicts/module_inspector_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698