OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/conflicts/third_party_metrics_recorder_win.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/strings/string_util.h" |
| 10 #include "base/task_scheduler/post_task.h" |
| 11 #include "chrome/browser/conflicts/module_database_win.h" |
| 12 |
| 13 ThirdPartyMetricsRecorder::ThirdPartyMetricsRecorder( |
| 14 ModuleDatabase* module_database) { |
| 15 // base::Unretained() is safe here because ThirdPartyMetricsRecorder owns |
| 16 // |installed_programs_| and the callback won't be invoked if the instance is |
| 17 // destroyed. |
| 18 installed_programs_.Initialize( |
| 19 base::Bind(&ThirdPartyMetricsRecorder::OnInstalledProgramsInitialized, |
| 20 base::Unretained(this), module_database)); |
| 21 } |
| 22 |
| 23 ThirdPartyMetricsRecorder::~ThirdPartyMetricsRecorder() = default; |
| 24 |
| 25 void ThirdPartyMetricsRecorder::OnNewModuleFound( |
| 26 const ModuleInfoKey& module_key, |
| 27 const ModuleInfoData& module_data) { |
| 28 if (!IsThirdPartyModule(module_data)) |
| 29 return; |
| 30 |
| 31 base::string16 program_name; |
| 32 bool uninstallable = installed_programs_.GetInstalledProgramName( |
| 33 module_key.module_path, &program_name); |
| 34 UMA_HISTOGRAM_BOOLEAN("ThirdPartyModules.Uninstallable", uninstallable); |
| 35 } |
| 36 |
| 37 bool ThirdPartyMetricsRecorder::IsThirdPartyModule( |
| 38 const ModuleInfoData& module_data) { |
| 39 static const wchar_t kMicrosoft[] = L"Microsoft "; |
| 40 static const wchar_t kGoogle[] = L"Google Inc"; |
| 41 |
| 42 const base::string16& certificate_subject = |
| 43 module_data.inspection_result->certificate_info.subject; |
| 44 |
| 45 // Check if the signer name begins with "Microsoft ". Signatures are |
| 46 // typically "Microsoft Corporation" or "Microsoft Windows", but others |
| 47 // may exist. |
| 48 if (base::StartsWith(certificate_subject, kMicrosoft, |
| 49 base::CompareCase::SENSITIVE)) |
| 50 return false; |
| 51 |
| 52 return certificate_subject != kGoogle; |
| 53 } |
| 54 |
| 55 void ThirdPartyMetricsRecorder::OnInstalledProgramsInitialized( |
| 56 ModuleDatabase* module_database) { |
| 57 module_database->AddObserver(this); |
| 58 } |
OLD | NEW |