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" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Document the assumptions made on the ProcessType enum in order to convert | 14 // Document the assumptions made on the ProcessType enum in order to convert |
15 // them to bits. | 15 // them to bits. |
16 static_assert(content::PROCESS_TYPE_UNKNOWN == 1, | 16 static_assert(content::PROCESS_TYPE_UNKNOWN == 1, |
17 "assumes unknown process type has value 1"); | 17 "assumes unknown process type has value 1"); |
18 static_assert(content::PROCESS_TYPE_BROWSER == 2, | 18 static_assert(content::PROCESS_TYPE_BROWSER == 2, |
19 "assumes browser process type has value 2"); | 19 "assumes browser process type has value 2"); |
20 constexpr uint32_t kFirstValidProcessType = content::PROCESS_TYPE_BROWSER; | 20 constexpr uint32_t kFirstValidProcessType = content::PROCESS_TYPE_BROWSER; |
21 | 21 |
22 ModuleDatabase* g_instance = nullptr; | 22 ModuleDatabase* g_instance = nullptr; |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 ModuleDatabase::ModuleDatabase( | 26 ModuleDatabase::ModuleDatabase( |
27 scoped_refptr<base::SequencedTaskRunner> task_runner) | 27 scoped_refptr<base::SequencedTaskRunner> task_runner) |
28 : task_runner_(std::move(task_runner)), weak_ptr_factory_(this) {} | 28 : task_runner_(std::move(task_runner)), |
| 29 // ModuleDatabase owns |module_inspector_|, so it is safe to use |
| 30 // base::Unretained(). |
| 31 module_inspector_(base::Bind(&ModuleDatabase::OnModuleInspected, |
| 32 base::Unretained(this))), |
| 33 weak_ptr_factory_(this) {} |
29 | 34 |
30 ModuleDatabase::~ModuleDatabase() { | 35 ModuleDatabase::~ModuleDatabase() { |
31 if (this == g_instance) | 36 if (this == g_instance) |
32 g_instance = nullptr; | 37 g_instance = nullptr; |
33 } | 38 } |
34 | 39 |
35 // static | 40 // static |
36 ModuleDatabase* ModuleDatabase::GetInstance() { | 41 ModuleDatabase* ModuleDatabase::GetInstance() { |
37 return g_instance; | 42 return g_instance; |
38 } | 43 } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 ModuleDatabase::ModuleInfo* ModuleDatabase::FindOrCreateModuleInfo( | 292 ModuleDatabase::ModuleInfo* ModuleDatabase::FindOrCreateModuleInfo( |
288 const base::FilePath& module_path, | 293 const base::FilePath& module_path, |
289 uint32_t module_size, | 294 uint32_t module_size, |
290 uint32_t module_time_date_stamp) { | 295 uint32_t module_time_date_stamp) { |
291 auto result = modules_.emplace( | 296 auto result = modules_.emplace( |
292 std::piecewise_construct, | 297 std::piecewise_construct, |
293 std::forward_as_tuple(module_path, module_size, module_time_date_stamp, | 298 std::forward_as_tuple(module_path, module_size, module_time_date_stamp, |
294 modules_.size()), | 299 modules_.size()), |
295 std::forward_as_tuple()); | 300 std::forward_as_tuple()); |
296 | 301 |
| 302 // New modules must be inspected. |
| 303 if (result.second) |
| 304 module_inspector_.AddModule(result.first->first); |
| 305 |
297 return &(*result.first); | 306 return &(*result.first); |
298 } | 307 } |
299 | 308 |
300 ModuleDatabase::ProcessInfo* ModuleDatabase::GetProcessInfo( | 309 ModuleDatabase::ProcessInfo* ModuleDatabase::GetProcessInfo( |
301 uint32_t process_id, | 310 uint32_t process_id, |
302 uint64_t creation_time) { | 311 uint64_t creation_time) { |
303 ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); | 312 ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); |
304 auto it = processes_.find(key); | 313 auto it = processes_.find(key); |
305 if (it == processes_.end()) | 314 if (it == processes_.end()) |
306 return nullptr; | 315 return nullptr; |
307 return &(*it); | 316 return &(*it); |
308 } | 317 } |
309 | 318 |
310 void ModuleDatabase::CreateProcessInfo(uint32_t process_id, | 319 void ModuleDatabase::CreateProcessInfo(uint32_t process_id, |
311 uint64_t creation_time, | 320 uint64_t creation_time, |
312 content::ProcessType process_type) { | 321 content::ProcessType process_type) { |
313 processes_.emplace(std::piecewise_construct, | 322 processes_.emplace(std::piecewise_construct, |
314 std::forward_as_tuple(ProcessInfoKey( | 323 std::forward_as_tuple(ProcessInfoKey( |
315 process_id, creation_time, process_type)), | 324 process_id, creation_time, process_type)), |
316 std::forward_as_tuple(ProcessInfoData())); | 325 std::forward_as_tuple(ProcessInfoData())); |
317 } | 326 } |
318 | 327 |
319 void ModuleDatabase::DeleteProcessInfo(uint32_t process_id, | 328 void ModuleDatabase::DeleteProcessInfo(uint32_t process_id, |
320 uint64_t creation_time) { | 329 uint64_t creation_time) { |
321 ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); | 330 ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); |
322 processes_.erase(key); | 331 processes_.erase(key); |
323 } | 332 } |
324 | 333 |
| 334 void ModuleDatabase::OnModuleInspected( |
| 335 const ModuleInfoKey& module_key, |
| 336 std::unique_ptr<ModuleInspectionResult> inspection_result) { |
| 337 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 338 |
| 339 auto it = modules_.find(module_key); |
| 340 if (it != modules_.end()) |
| 341 it->second.inspection_result = std::move(inspection_result); |
| 342 } |
| 343 |
325 // ModuleDatabase::ProcessInfoKey ---------------------------------------------- | 344 // ModuleDatabase::ProcessInfoKey ---------------------------------------------- |
326 | 345 |
327 ModuleDatabase::ProcessInfoKey::ProcessInfoKey( | 346 ModuleDatabase::ProcessInfoKey::ProcessInfoKey( |
328 uint32_t process_id, | 347 uint32_t process_id, |
329 uint64_t creation_time, | 348 uint64_t creation_time, |
330 content::ProcessType process_type) | 349 content::ProcessType process_type) |
331 : process_id(process_id), | 350 : process_id(process_id), |
332 creation_time(creation_time), | 351 creation_time(creation_time), |
333 process_type(process_type) {} | 352 process_type(process_type) {} |
334 | 353 |
335 ModuleDatabase::ProcessInfoKey::~ProcessInfoKey() = default; | 354 ModuleDatabase::ProcessInfoKey::~ProcessInfoKey() = default; |
336 | 355 |
337 bool ModuleDatabase::ProcessInfoKey::operator<( | 356 bool ModuleDatabase::ProcessInfoKey::operator<( |
338 const ProcessInfoKey& pik) const { | 357 const ProcessInfoKey& pik) const { |
339 // The key consists of the pair of (process_id, creation_time). | 358 // The key consists of the pair of (process_id, creation_time). |
340 // Use the std::tuple lexicographic comparison operator. | 359 // Use the std::tuple lexicographic comparison operator. |
341 return std::make_tuple(process_id, creation_time) < | 360 return std::make_tuple(process_id, creation_time) < |
342 std::make_tuple(pik.process_id, pik.creation_time); | 361 std::make_tuple(pik.process_id, pik.creation_time); |
343 } | 362 } |
344 | 363 |
345 // ModuleDatabase::ProcessInfoData --------------------------------------------- | 364 // ModuleDatabase::ProcessInfoData --------------------------------------------- |
346 | 365 |
347 ModuleDatabase::ProcessInfoData::ProcessInfoData() = default; | 366 ModuleDatabase::ProcessInfoData::ProcessInfoData() = default; |
348 | 367 |
349 ModuleDatabase::ProcessInfoData::ProcessInfoData(const ProcessInfoData& other) = | 368 ModuleDatabase::ProcessInfoData::ProcessInfoData(const ProcessInfoData& other) = |
350 default; | 369 default; |
351 | 370 |
352 ModuleDatabase::ProcessInfoData::~ProcessInfoData() = default; | 371 ModuleDatabase::ProcessInfoData::~ProcessInfoData() = default; |
OLD | NEW |