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

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

Issue 2854983002: Add the ThirdPartyModules.Uninstallable histogram. (Closed)
Patch Set: Created 3 years, 7 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
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_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 #include "chrome/browser/conflicts/module_database_observer_win.h"
11 12
12 namespace { 13 namespace {
13 14
14 // Document the assumptions made on the ProcessType enum in order to convert 15 // Document the assumptions made on the ProcessType enum in order to convert
15 // them to bits. 16 // them to bits.
16 static_assert(content::PROCESS_TYPE_UNKNOWN == 1, 17 static_assert(content::PROCESS_TYPE_UNKNOWN == 1,
17 "assumes unknown process type has value 1"); 18 "assumes unknown process type has value 1");
18 static_assert(content::PROCESS_TYPE_BROWSER == 2, 19 static_assert(content::PROCESS_TYPE_BROWSER == 2,
19 "assumes browser process type has value 2"); 20 "assumes browser process type has value 2");
20 constexpr uint32_t kFirstValidProcessType = content::PROCESS_TYPE_BROWSER; 21 constexpr uint32_t kFirstValidProcessType = content::PROCESS_TYPE_BROWSER;
21 22
22 ModuleDatabase* g_instance = nullptr; 23 ModuleDatabase* g_instance = nullptr;
23 24
24 } // namespace 25 } // namespace
25 26
26 ModuleDatabase::ModuleDatabase( 27 ModuleDatabase::ModuleDatabase(
27 scoped_refptr<base::SequencedTaskRunner> task_runner) 28 scoped_refptr<base::SequencedTaskRunner> task_runner)
28 : task_runner_(std::move(task_runner)), 29 : task_runner_(std::move(task_runner)),
29 // ModuleDatabase owns |module_inspector_|, so it is safe to use 30 // ModuleDatabase owns |module_inspector_|, so it is safe to use
30 // base::Unretained(). 31 // base::Unretained().
31 module_inspector_(base::Bind(&ModuleDatabase::OnModuleInspected, 32 module_inspector_(base::Bind(&ModuleDatabase::OnModuleInspected,
32 base::Unretained(this))), 33 base::Unretained(this))),
34 third_party_metrics_(this),
33 weak_ptr_factory_(this) {} 35 weak_ptr_factory_(this) {}
34 36
35 ModuleDatabase::~ModuleDatabase() { 37 ModuleDatabase::~ModuleDatabase() {
36 if (this == g_instance) 38 if (this == g_instance)
37 g_instance = nullptr; 39 g_instance = nullptr;
38 } 40 }
39 41
40 // static 42 // static
41 ModuleDatabase* ModuleDatabase::GetInstance() { 43 ModuleDatabase* ModuleDatabase::GetInstance() {
42 return g_instance; 44 return g_instance;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 task_runner_->PostTask( 147 task_runner_->PostTask(
146 FROM_HERE, 148 FROM_HERE,
147 base::Bind(&ModuleDatabase::OnProcessEnded, 149 base::Bind(&ModuleDatabase::OnProcessEnded,
148 weak_ptr_factory_.GetWeakPtr(), process_id, creation_time)); 150 weak_ptr_factory_.GetWeakPtr(), process_id, creation_time));
149 return; 151 return;
150 } 152 }
151 153
152 DeleteProcessInfo(process_id, creation_time); 154 DeleteProcessInfo(process_id, creation_time);
153 } 155 }
154 156
157 void ModuleDatabase::AddObserver(ModuleDatabaseObserver* observer) {
158 observer_list_.AddObserver(observer);
159 for (const auto& module : modules_) {
160 if (module.second.inspection_result)
161 observer->OnNewModuleFound(module.first, module.second);
162 }
163 }
164
165 void ModuleDatabase::RemoveObserver(ModuleDatabaseObserver* observer) {
166 observer_list_.RemoveObserver(observer);
167 }
168
155 // static 169 // static
156 uint32_t ModuleDatabase::ProcessTypeToBit(content::ProcessType process_type) { 170 uint32_t ModuleDatabase::ProcessTypeToBit(content::ProcessType process_type) {
157 uint32_t bit_index = 171 uint32_t bit_index =
158 static_cast<uint32_t>(process_type) - kFirstValidProcessType; 172 static_cast<uint32_t>(process_type) - kFirstValidProcessType;
159 DCHECK_GE(31u, bit_index); 173 DCHECK_GE(31u, bit_index);
160 uint32_t bit = (1 << bit_index); 174 uint32_t bit = (1 << bit_index);
161 return bit; 175 return bit;
162 } 176 }
163 177
164 // static 178 // static
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN); 344 ProcessInfoKey key(process_id, creation_time, content::PROCESS_TYPE_UNKNOWN);
331 processes_.erase(key); 345 processes_.erase(key);
332 } 346 }
333 347
334 void ModuleDatabase::OnModuleInspected( 348 void ModuleDatabase::OnModuleInspected(
335 const ModuleInfoKey& module_key, 349 const ModuleInfoKey& module_key,
336 std::unique_ptr<ModuleInspectionResult> inspection_result) { 350 std::unique_ptr<ModuleInspectionResult> inspection_result) {
337 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 351 DCHECK(task_runner_->RunsTasksOnCurrentThread());
338 352
339 auto it = modules_.find(module_key); 353 auto it = modules_.find(module_key);
340 if (it != modules_.end()) 354 if (it == modules_.end())
341 it->second.inspection_result = std::move(inspection_result); 355 return;
356
357 it->second.inspection_result = std::move(inspection_result);
358
359 for (auto& observer : observer_list_)
360 observer.OnNewModuleFound(it->first, it->second);
342 } 361 }
343 362
344 // ModuleDatabase::ProcessInfoKey ---------------------------------------------- 363 // ModuleDatabase::ProcessInfoKey ----------------------------------------------
345 364
346 ModuleDatabase::ProcessInfoKey::ProcessInfoKey( 365 ModuleDatabase::ProcessInfoKey::ProcessInfoKey(
347 uint32_t process_id, 366 uint32_t process_id,
348 uint64_t creation_time, 367 uint64_t creation_time,
349 content::ProcessType process_type) 368 content::ProcessType process_type)
350 : process_id(process_id), 369 : process_id(process_id),
351 creation_time(creation_time), 370 creation_time(creation_time),
352 process_type(process_type) {} 371 process_type(process_type) {}
353 372
354 ModuleDatabase::ProcessInfoKey::~ProcessInfoKey() = default; 373 ModuleDatabase::ProcessInfoKey::~ProcessInfoKey() = default;
355 374
356 bool ModuleDatabase::ProcessInfoKey::operator<( 375 bool ModuleDatabase::ProcessInfoKey::operator<(
357 const ProcessInfoKey& pik) const { 376 const ProcessInfoKey& pik) const {
358 // The key consists of the pair of (process_id, creation_time). 377 // The key consists of the pair of (process_id, creation_time).
359 // Use the std::tuple lexicographic comparison operator. 378 // Use the std::tuple lexicographic comparison operator.
360 return std::make_tuple(process_id, creation_time) < 379 return std::tie(process_id, creation_time) <
chrisha 2017/05/02 21:28:25 I always forget about 'tie'....
361 std::make_tuple(pik.process_id, pik.creation_time); 380 std::tie(pik.process_id, pik.creation_time);
362 } 381 }
363 382
364 // ModuleDatabase::ProcessInfoData --------------------------------------------- 383 // ModuleDatabase::ProcessInfoData ---------------------------------------------
365 384
366 ModuleDatabase::ProcessInfoData::ProcessInfoData() = default; 385 ModuleDatabase::ProcessInfoData::ProcessInfoData() = default;
367 386
368 ModuleDatabase::ProcessInfoData::ProcessInfoData(const ProcessInfoData& other) = 387 ModuleDatabase::ProcessInfoData::ProcessInfoData(const ProcessInfoData& other) =
369 default; 388 default;
370 389
371 ModuleDatabase::ProcessInfoData::~ProcessInfoData() = default; 390 ModuleDatabase::ProcessInfoData::~ProcessInfoData() = default;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698