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