Chromium Code Reviews| 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(unsigned int 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()); | |
|
robertshield
2013/09/13 17:26:05
<ignore-this-comment>ugh, notifications</ignore-th
erikwright (departed)
2013/09/16 20:04:55
Done.
| |
| 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> module_name_digests; | |
| 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 module_name_digest = | |
| 89 CalculateInstalledModuleDigest(module_name); | |
| 90 module_name_digests.insert(module_name_digest); | |
| 91 } | |
| 92 for (size_t i = 0; kExpectedInstallModuleDigests[i] != 0; ++i) { | |
|
robertshield
2013/09/13 17:26:05
nit: i -> module_id
MAD
2013/09/13 20:15:33
You could avoid having a 0 at the end if you compa
erikwright (departed)
2013/09/13 20:19:56
arraysize doesn't work with pointers like this. It
MAD
2013/09/13 20:34:39
I don't understand. Why do you say that the size i
erikwright (departed)
2013/09/16 20:04:55
Done.
| |
| 93 if (module_name_digests.find(kExpectedInstallModuleDigests[i]) != | |
| 94 module_name_digests.end()) { | |
| 95 delegate.Run(i); | |
| 96 } | |
| 97 } | |
| 98 } | |
| OLD | NEW |