| 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       module_inspector_(this), | 
|  | 30       weak_ptr_factory_(this) {} | 
| 29 | 31 | 
| 30 ModuleDatabase::~ModuleDatabase() { | 32 ModuleDatabase::~ModuleDatabase() { | 
| 31   if (this == g_instance) | 33   if (this == g_instance) | 
| 32     g_instance = nullptr; | 34     g_instance = nullptr; | 
| 33 } | 35 } | 
| 34 | 36 | 
| 35 // static | 37 // static | 
| 36 ModuleDatabase* ModuleDatabase::GetInstance() { | 38 ModuleDatabase* ModuleDatabase::GetInstance() { | 
| 37   return g_instance; | 39   return g_instance; | 
| 38 } | 40 } | 
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 286 ModuleDatabase::ModuleInfo* ModuleDatabase::FindOrCreateModuleInfo( | 288 ModuleDatabase::ModuleInfo* ModuleDatabase::FindOrCreateModuleInfo( | 
| 287     const base::FilePath& module_path, | 289     const base::FilePath& module_path, | 
| 288     uint32_t module_size, | 290     uint32_t module_size, | 
| 289     uint32_t module_time_date_stamp) { | 291     uint32_t module_time_date_stamp) { | 
| 290   auto result = modules_.emplace( | 292   auto result = modules_.emplace( | 
| 291       std::piecewise_construct, | 293       std::piecewise_construct, | 
| 292       std::forward_as_tuple(module_path, module_size, module_time_date_stamp, | 294       std::forward_as_tuple(module_path, module_size, module_time_date_stamp, | 
| 293                             modules_.size()), | 295                             modules_.size()), | 
| 294       std::forward_as_tuple()); | 296       std::forward_as_tuple()); | 
| 295 | 297 | 
|  | 298   // New modules must be inspected. | 
|  | 299   if (result.second) | 
|  | 300     module_inspector_.AddModule(result.first->first); | 
|  | 301 | 
| 296   return &(*result.first); | 302   return &(*result.first); | 
| 297 } | 303 } | 
| 298 | 304 | 
| 299 ModuleDatabase::ProcessInfo* ModuleDatabase::GetProcessInfo( | 305 ModuleDatabase::ProcessInfo* ModuleDatabase::GetProcessInfo( | 
| 300     uint32_t process_id, | 306     uint32_t process_id, | 
| 301     uint64_t creation_time) { | 307     uint64_t creation_time) { | 
| 302   ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); | 308   ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); | 
| 303   auto it = processes_.find(key); | 309   auto it = processes_.find(key); | 
| 304   if (it == processes_.end()) | 310   if (it == processes_.end()) | 
| 305     return nullptr; | 311     return nullptr; | 
| 306   return &(*it); | 312   return &(*it); | 
| 307 } | 313 } | 
| 308 | 314 | 
| 309 void ModuleDatabase::CreateProcessInfo(uint32_t process_id, | 315 void ModuleDatabase::CreateProcessInfo(uint32_t process_id, | 
| 310                                        uint64_t creation_time, | 316                                        uint64_t creation_time, | 
| 311                                        content::ProcessType process_type) { | 317                                        content::ProcessType process_type) { | 
| 312   processes_.emplace(std::piecewise_construct, | 318   processes_.emplace(std::piecewise_construct, | 
| 313                      std::forward_as_tuple(ProcessInfoKey( | 319                      std::forward_as_tuple(ProcessInfoKey( | 
| 314                          process_id, creation_time, process_type)), | 320                          process_id, creation_time, process_type)), | 
| 315                      std::forward_as_tuple(ProcessInfoData())); | 321                      std::forward_as_tuple(ProcessInfoData())); | 
| 316 } | 322 } | 
| 317 | 323 | 
| 318 void ModuleDatabase::DeleteProcessInfo(uint32_t process_id, | 324 void ModuleDatabase::DeleteProcessInfo(uint32_t process_id, | 
| 319                                        uint64_t creation_time) { | 325                                        uint64_t creation_time) { | 
| 320   ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); | 326   ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); | 
| 321   processes_.erase(key); | 327   processes_.erase(key); | 
| 322 } | 328 } | 
| 323 | 329 | 
|  | 330 void ModuleDatabase::OnModuleInspected(const ModuleInfoKey& module_key, | 
|  | 331                                        const ModuleInfoData& module_data) { | 
|  | 332   DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 
|  | 333 | 
|  | 334   // Received the data. Copy it. | 
|  | 335   auto it = modules_.find(module_key); | 
|  | 336   if (it != modules_.end()) | 
|  | 337     it->second.CopyInspectionData(module_data); | 
|  | 338 } | 
|  | 339 | 
| 324 // ModuleDatabase::ProcessInfoKey ---------------------------------------------- | 340 // ModuleDatabase::ProcessInfoKey ---------------------------------------------- | 
| 325 | 341 | 
| 326 ModuleDatabase::ProcessInfoKey::ProcessInfoKey( | 342 ModuleDatabase::ProcessInfoKey::ProcessInfoKey( | 
| 327     uint32_t process_id, | 343     uint32_t process_id, | 
| 328     uint64_t creation_time, | 344     uint64_t creation_time, | 
| 329     content::ProcessType process_type) | 345     content::ProcessType process_type) | 
| 330     : process_id(process_id), | 346     : process_id(process_id), | 
| 331       creation_time(creation_time), | 347       creation_time(creation_time), | 
| 332       process_type(process_type) {} | 348       process_type(process_type) {} | 
| 333 | 349 | 
| 334 ModuleDatabase::ProcessInfoKey::~ProcessInfoKey() = default; | 350 ModuleDatabase::ProcessInfoKey::~ProcessInfoKey() = default; | 
| 335 | 351 | 
| 336 bool ModuleDatabase::ProcessInfoKey::operator<( | 352 bool ModuleDatabase::ProcessInfoKey::operator<( | 
| 337     const ProcessInfoKey& pik) const { | 353     const ProcessInfoKey& pik) const { | 
| 338   // The key consists of the pair of (process_id, creation_time). | 354   // The key consists of the pair of (process_id, creation_time). | 
| 339   // Use the std::tuple lexicographic comparison operator. | 355   // Use the std::tuple lexicographic comparison operator. | 
| 340   return std::make_tuple(process_id, creation_time) < | 356   return std::make_tuple(process_id, creation_time) < | 
| 341          std::make_tuple(pik.process_id, pik.creation_time); | 357          std::make_tuple(pik.process_id, pik.creation_time); | 
| 342 } | 358 } | 
| 343 | 359 | 
| 344 // ModuleDatabase::ProcessInfoData --------------------------------------------- | 360 // ModuleDatabase::ProcessInfoData --------------------------------------------- | 
| 345 | 361 | 
| 346 ModuleDatabase::ProcessInfoData::ProcessInfoData() = default; | 362 ModuleDatabase::ProcessInfoData::ProcessInfoData() = default; | 
| 347 | 363 | 
| 348 ModuleDatabase::ProcessInfoData::ProcessInfoData(const ProcessInfoData& other) = | 364 ModuleDatabase::ProcessInfoData::ProcessInfoData(const ProcessInfoData& other) = | 
| 349     default; | 365     default; | 
| 350 | 366 | 
| 351 ModuleDatabase::ProcessInfoData::~ProcessInfoData() = default; | 367 ModuleDatabase::ProcessInfoData::~ProcessInfoData() = default; | 
| OLD | NEW | 
|---|