OLD | NEW |
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_database_win.h" | 5 #include "chrome/browser/conflicts/module_database_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <tuple> | 8 #include <tuple> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 std::unique_ptr<ModuleDatabase> module_database) { | 48 std::unique_ptr<ModuleDatabase> module_database) { |
49 DCHECK_EQ(nullptr, g_instance); | 49 DCHECK_EQ(nullptr, g_instance); |
50 // This is deliberately leaked. It can be cleaned up by manually deleting the | 50 // This is deliberately leaked. It can be cleaned up by manually deleting the |
51 // ModuleDatabase | 51 // ModuleDatabase |
52 g_instance = module_database.release(); | 52 g_instance = module_database.release(); |
53 } | 53 } |
54 | 54 |
55 void ModuleDatabase::OnProcessStarted(uint32_t process_id, | 55 void ModuleDatabase::OnProcessStarted(uint32_t process_id, |
56 uint64_t creation_time, | 56 uint64_t creation_time, |
57 content::ProcessType process_type) { | 57 content::ProcessType process_type) { |
58 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 58 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
59 CreateProcessInfo(process_id, creation_time, process_type); | 59 CreateProcessInfo(process_id, creation_time, process_type); |
60 } | 60 } |
61 | 61 |
62 void ModuleDatabase::OnModuleLoad(uint32_t process_id, | 62 void ModuleDatabase::OnModuleLoad(uint32_t process_id, |
63 uint64_t creation_time, | 63 uint64_t creation_time, |
64 const base::FilePath& module_path, | 64 const base::FilePath& module_path, |
65 uint32_t module_size, | 65 uint32_t module_size, |
66 uint32_t module_time_date_stamp, | 66 uint32_t module_time_date_stamp, |
67 uintptr_t module_load_address) { | 67 uintptr_t module_load_address) { |
68 // Messages can arrive from any thread (UI thread for calls over IPC, and | 68 // Messages can arrive from any thread (UI thread for calls over IPC, and |
69 // anywhere at all for calls from ModuleWatcher), so bounce if necessary. | 69 // anywhere at all for calls from ModuleWatcher), so bounce if necessary. |
70 if (!task_runner_->RunsTasksOnCurrentThread()) { | 70 if (!task_runner_->RunsTasksInCurrentSequence()) { |
71 task_runner_->PostTask( | 71 task_runner_->PostTask( |
72 FROM_HERE, base::Bind(&ModuleDatabase::OnModuleLoad, | 72 FROM_HERE, base::Bind(&ModuleDatabase::OnModuleLoad, |
73 weak_ptr_factory_.GetWeakPtr(), process_id, | 73 weak_ptr_factory_.GetWeakPtr(), process_id, |
74 creation_time, module_path, module_size, | 74 creation_time, module_path, module_size, |
75 module_time_date_stamp, module_load_address)); | 75 module_time_date_stamp, module_load_address)); |
76 return; | 76 return; |
77 } | 77 } |
78 | 78 |
79 // In theory this should always succeed. However, it is possible for a client | 79 // In theory this should always succeed. However, it is possible for a client |
80 // to misbehave and send out-of-order messages. It is easy to be tolerant of | 80 // to misbehave and send out-of-order messages. It is easy to be tolerant of |
(...skipping 16 matching lines...) Expand all Loading... |
97 &process_info->second.loaded_modules); | 97 &process_info->second.loaded_modules); |
98 RemoveLoadAddressById(module_info->first.module_id, | 98 RemoveLoadAddressById(module_info->first.module_id, |
99 &process_info->second.unloaded_modules); | 99 &process_info->second.unloaded_modules); |
100 } | 100 } |
101 | 101 |
102 void ModuleDatabase::OnModuleUnload(uint32_t process_id, | 102 void ModuleDatabase::OnModuleUnload(uint32_t process_id, |
103 uint64_t creation_time, | 103 uint64_t creation_time, |
104 uintptr_t module_load_address) { | 104 uintptr_t module_load_address) { |
105 // Messages can arrive from any thread (UI thread for calls over IPC, and | 105 // Messages can arrive from any thread (UI thread for calls over IPC, and |
106 // anywhere at all for calls from ModuleWatcher), so bounce if necessary. | 106 // anywhere at all for calls from ModuleWatcher), so bounce if necessary. |
107 if (!task_runner_->RunsTasksOnCurrentThread()) { | 107 if (!task_runner_->RunsTasksInCurrentSequence()) { |
108 task_runner_->PostTask( | 108 task_runner_->PostTask( |
109 FROM_HERE, base::Bind(&ModuleDatabase::OnModuleUnload, | 109 FROM_HERE, base::Bind(&ModuleDatabase::OnModuleUnload, |
110 weak_ptr_factory_.GetWeakPtr(), process_id, | 110 weak_ptr_factory_.GetWeakPtr(), process_id, |
111 creation_time, module_load_address)); | 111 creation_time, module_load_address)); |
112 return; | 112 return; |
113 } | 113 } |
114 | 114 |
115 // See the long-winded comment in OnModuleLoad about reasons why this can | 115 // See the long-winded comment in OnModuleLoad about reasons why this can |
116 // fail (but shouldn't normally). | 116 // fail (but shouldn't normally). |
117 auto* process_info = GetProcessInfo(process_id, creation_time); | 117 auto* process_info = GetProcessInfo(process_id, creation_time); |
(...skipping 17 matching lines...) Expand all Loading... |
135 // list. | 135 // list. |
136 RemoveLoadAddressByIndex(i, &process_info->second.loaded_modules); | 136 RemoveLoadAddressByIndex(i, &process_info->second.loaded_modules); |
137 InsertLoadAddress(module_id, module_load_address, | 137 InsertLoadAddress(module_id, module_load_address, |
138 &process_info->second.unloaded_modules); | 138 &process_info->second.unloaded_modules); |
139 } | 139 } |
140 | 140 |
141 void ModuleDatabase::OnProcessEnded(uint32_t process_id, | 141 void ModuleDatabase::OnProcessEnded(uint32_t process_id, |
142 uint64_t creation_time) { | 142 uint64_t creation_time) { |
143 // Messages can arrive from any thread (UI thread for calls over IPC, and | 143 // Messages can arrive from any thread (UI thread for calls over IPC, and |
144 // anywhere at all for calls from ModuleWatcher), so bounce if necessary. | 144 // anywhere at all for calls from ModuleWatcher), so bounce if necessary. |
145 if (!task_runner_->RunsTasksOnCurrentThread()) { | 145 if (!task_runner_->RunsTasksInCurrentSequence()) { |
146 task_runner_->PostTask( | 146 task_runner_->PostTask( |
147 FROM_HERE, | 147 FROM_HERE, |
148 base::Bind(&ModuleDatabase::OnProcessEnded, | 148 base::Bind(&ModuleDatabase::OnProcessEnded, |
149 weak_ptr_factory_.GetWeakPtr(), process_id, creation_time)); | 149 weak_ptr_factory_.GetWeakPtr(), process_id, creation_time)); |
150 return; | 150 return; |
151 } | 151 } |
152 | 152 |
153 DeleteProcessInfo(process_id, creation_time); | 153 DeleteProcessInfo(process_id, creation_time); |
154 } | 154 } |
155 | 155 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 340 |
341 void ModuleDatabase::DeleteProcessInfo(uint32_t process_id, | 341 void ModuleDatabase::DeleteProcessInfo(uint32_t process_id, |
342 uint64_t creation_time) { | 342 uint64_t creation_time) { |
343 ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); | 343 ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); |
344 processes_.erase(key); | 344 processes_.erase(key); |
345 } | 345 } |
346 | 346 |
347 void ModuleDatabase::OnModuleInspected( | 347 void ModuleDatabase::OnModuleInspected( |
348 const ModuleInfoKey& module_key, | 348 const ModuleInfoKey& module_key, |
349 std::unique_ptr<ModuleInspectionResult> inspection_result) { | 349 std::unique_ptr<ModuleInspectionResult> inspection_result) { |
350 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 350 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
351 | 351 |
352 auto it = modules_.find(module_key); | 352 auto it = modules_.find(module_key); |
353 if (it == modules_.end()) | 353 if (it == modules_.end()) |
354 return; | 354 return; |
355 | 355 |
356 it->second.inspection_result = std::move(inspection_result); | 356 it->second.inspection_result = std::move(inspection_result); |
357 | 357 |
358 for (auto& observer : observer_list_) | 358 for (auto& observer : observer_list_) |
359 observer.OnNewModuleFound(it->first, it->second); | 359 observer.OnNewModuleFound(it->first, it->second); |
360 } | 360 } |
(...skipping 19 matching lines...) Expand all Loading... |
380 } | 380 } |
381 | 381 |
382 // ModuleDatabase::ProcessInfoData --------------------------------------------- | 382 // ModuleDatabase::ProcessInfoData --------------------------------------------- |
383 | 383 |
384 ModuleDatabase::ProcessInfoData::ProcessInfoData() = default; | 384 ModuleDatabase::ProcessInfoData::ProcessInfoData() = default; |
385 | 385 |
386 ModuleDatabase::ProcessInfoData::ProcessInfoData(const ProcessInfoData& other) = | 386 ModuleDatabase::ProcessInfoData::ProcessInfoData(const ProcessInfoData& other) = |
387 default; | 387 default; |
388 | 388 |
389 ModuleDatabase::ProcessInfoData::~ProcessInfoData() = default; | 389 ModuleDatabase::ProcessInfoData::~ProcessInfoData() = default; |
OLD | NEW |