Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 kMinProcessType = content::PROCESS_TYPE_BROWSER; | 20 constexpr uint32_t kMinProcessType = content::PROCESS_TYPE_BROWSER; |
| 21 | 21 |
| 22 ModuleDatabase* g_instance = nullptr; | |
| 23 | |
| 22 } // namespace | 24 } // namespace |
| 23 | 25 |
| 24 ModuleDatabase::ModuleDatabase( | 26 ModuleDatabase::ModuleDatabase( |
| 25 scoped_refptr<base::SequencedTaskRunner> task_runner) | 27 scoped_refptr<base::SequencedTaskRunner> task_runner) |
| 26 : task_runner_(std::move(task_runner)), weak_ptr_factory_(this) {} | 28 : task_runner_(std::move(task_runner)), weak_ptr_factory_(this) {} |
| 27 | 29 |
| 28 ModuleDatabase::~ModuleDatabase() = default; | 30 ModuleDatabase::~ModuleDatabase() = default; |
| 29 | 31 |
| 32 // static | |
| 33 ModuleDatabase* ModuleDatabase::GetInstance() { | |
| 34 return g_instance; | |
| 35 } | |
| 36 | |
| 37 // static | |
| 38 void ModuleDatabase::SetInstance( | |
| 39 std::unique_ptr<ModuleDatabase> module_database) { | |
| 40 // This is deliberately leaked. | |
|
grt (UTC plus 2)
2017/01/06 09:44:58
DCHECK_EQ(nullptr, g_instance);
chrisha
2017/01/10 21:01:46
Done.
| |
| 41 g_instance = module_database.release(); | |
|
grt (UTC plus 2)
2017/01/06 09:44:58
wdyt of adding a dtor with something like DCHECK_N
chrisha
2017/01/10 21:01:46
Sure, I'm fine with that.
| |
| 42 } | |
| 43 | |
| 30 void ModuleDatabase::OnProcessStarted(uint32_t process_id, | 44 void ModuleDatabase::OnProcessStarted(uint32_t process_id, |
| 31 uint64_t creation_time, | 45 uint64_t creation_time, |
| 32 content::ProcessType process_type) { | 46 content::ProcessType process_type) { |
| 33 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 47 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 34 CreateProcessInfo(process_id, creation_time, process_type); | 48 CreateProcessInfo(process_id, creation_time, process_type); |
| 35 } | 49 } |
| 36 | 50 |
| 37 void ModuleDatabase::OnModuleLoad(uint32_t process_id, | 51 void ModuleDatabase::OnModuleLoad(uint32_t process_id, |
| 38 uint64_t creation_time, | 52 uint64_t creation_time, |
| 39 const base::FilePath& module_path, | 53 const base::FilePath& module_path, |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 : process_id(process_id), | 340 : process_id(process_id), |
| 327 creation_time(creation_time), | 341 creation_time(creation_time), |
| 328 process_type(process_type) {} | 342 process_type(process_type) {} |
| 329 | 343 |
| 330 bool ModuleDatabase::ProcessInfo::operator<(const ProcessInfo& pi) const { | 344 bool ModuleDatabase::ProcessInfo::operator<(const ProcessInfo& pi) const { |
| 331 // The key consists of the pair of (process_id, creation_time). | 345 // The key consists of the pair of (process_id, creation_time). |
| 332 // Use the std::tuple lexicographic comparison operator. | 346 // Use the std::tuple lexicographic comparison operator. |
| 333 return std::make_tuple(process_id, creation_time) < | 347 return std::make_tuple(process_id, creation_time) < |
| 334 std::make_tuple(pi.process_id, pi.creation_time); | 348 std::make_tuple(pi.process_id, pi.creation_time); |
| 335 } | 349 } |
| OLD | NEW |