| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 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/install_module_verifier_win.h" |
| 6 |
| 7 #include <set> |
| 8 #include <string> |
| 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" |
| 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/metrics/sparse_histogram.h" |
| 14 #include "base/values.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/enumerate_modules_model_win.h" |
| 17 #include "chrome/browser/expected_install_modules_win.h" |
| 18 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_source.h" |
| 22 |
| 23 namespace { |
| 24 |
| 25 void OnModuleMatch(size_t module_id) { |
| 26 UMA_HISTOGRAM_SPARSE_SLOWLY("InstallVerifier.ModuleMatch", module_id); |
| 27 } |
| 28 |
| 29 class InstallModuleVerifier : public content::NotificationObserver { |
| 30 public: |
| 31 InstallModuleVerifier() { |
| 32 notification_registrar_.Add(this, |
| 33 chrome::NOTIFICATION_MODULE_LIST_ENUMERATED, |
| 34 content::NotificationService::AllSources()); |
| 35 } |
| 36 virtual void Observe(int type, |
| 37 const content::NotificationSource& source, |
| 38 const content::NotificationDetails& details) OVERRIDE { |
| 39 EnumerateModulesModel* model = |
| 40 content::Source<EnumerateModulesModel>(source).ptr(); |
| 41 scoped_ptr<base::ListValue> module_list(model->GetModuleList()); |
| 42 |
| 43 if (module_list.get()) { |
| 44 VerifyInstalledModules(module_list.get(), base::Bind(&OnModuleMatch)); |
| 45 } |
| 46 delete this; |
| 47 } |
| 48 |
| 49 private: |
| 50 content::NotificationRegistrar notification_registrar_; |
| 51 DISALLOW_COPY_AND_ASSIGN(InstallModuleVerifier); |
| 52 }; |
| 53 |
| 54 } // namespace |
| 55 |
| 56 void InitiateInstalledModuleVerification() { |
| 57 scoped_ptr<base::ListValue> module_list( |
| 58 EnumerateModulesModel::GetInstance()->GetModuleList()); |
| 59 if (module_list.get()) { |
| 60 VerifyInstalledModules(module_list.get(), |
| 61 base::Bind(&OnModuleMatch)); |
| 62 } else { |
| 63 // Will delete itself when scan results are available. |
| 64 new InstallModuleVerifier(); |
| 65 EnumerateModulesModel::GetInstance()->ScanNow(); |
| 66 } |
| 67 } |
| 68 |
| 69 void VerifyInstalledModules( |
| 70 base::ListValue* module_list, |
| 71 const base::Callback<void(unsigned int)>& delegate) { |
| 72 std::set<std::string> canonical_module_names; |
| 73 for (size_t i = 0; i < module_list->GetSize(); ++i) { |
| 74 base::DictionaryValue* module_dictionary = NULL; |
| 75 if (!module_list->GetDictionary(i, &module_dictionary)) |
| 76 continue; |
| 77 ModuleEnumerator::ModuleType module_type = |
| 78 ModuleEnumerator::LOADED_MODULE; |
| 79 if (!module_dictionary->GetInteger( |
| 80 "type", reinterpret_cast<int*>(&module_type)) || |
| 81 module_type != ModuleEnumerator::LOADED_MODULE) { |
| 82 continue; |
| 83 } |
| 84 std::string module_name; |
| 85 if (!module_dictionary->GetString("name", &module_name)) |
| 86 continue; |
| 87 |
| 88 std::string canonical_module_name = CanonicalizeModuleName(module_name); |
| 89 canonical_module_names.insert(canonical_module_name); |
| 90 } |
| 91 for (size_t i = 0; kExpectedInstallModules[i] != 0; ++i) { |
| 92 if (canonical_module_names.find(kExpectedInstallModules[i]) != |
| 93 canonical_module_names.end()) { |
| 94 delegate.Run(i); |
| 95 } |
| 96 } |
| 97 } |
| OLD | NEW |