Chromium Code Reviews| Index: chrome/browser/install_module_verifier_win.cc |
| diff --git a/chrome/browser/install_module_verifier_win.cc b/chrome/browser/install_module_verifier_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f1c6384d38af6b3507bdea5ce1665220a7868150 |
| --- /dev/null |
| +++ b/chrome/browser/install_module_verifier_win.cc |
| @@ -0,0 +1,99 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/install_module_verifier_win.h" |
| + |
| +#include <set> |
| +#include <string> |
| +#include "base/basictypes.h" |
| +#include "base/bind.h" |
| +#include "base/callback.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/metrics/sparse_histogram.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/enumerate_modules_model_win.h" |
| +#include "chrome/browser/expected_install_modules_win.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/browser/notification_source.h" |
| + |
| +namespace { |
| + |
| +void OnModuleMatch(size_t module_id) { |
| + UMA_HISTOGRAM_SPARSE_SLOWLY("InstallVerifier.ModuleMatch", module_id); |
| +} |
| + |
| +class InstallModuleVerifier : public content::NotificationObserver { |
| + public: |
| + InstallModuleVerifier() { |
| + notification_registrar_.Add(this, |
| + chrome::NOTIFICATION_MODULE_LIST_ENUMERATED, |
| + content::NotificationService::AllSources()); |
| + } |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE { |
| + EnumerateModulesModel* model = |
| + content::Source<EnumerateModulesModel>(source).ptr(); |
| + scoped_ptr<base::ListValue> module_list(model->GetModuleList()); |
| + |
| + if (module_list.get()) { |
| + VerifyModules(module_list.get(), base::Bind(&OnModuleMatch)); |
| + } |
| + delete this; |
| + } |
| + |
| + private: |
| + content::NotificationRegistrar notification_registrar_; |
| + DISALLOW_COPY_AND_ASSIGN(InstallModuleVerifier); |
| +}; |
| + |
| +} // namespace |
| + |
| +void BeginModuleVerification() { |
| + scoped_ptr<base::ListValue> module_list( |
| + EnumerateModulesModel::GetInstance()->GetModuleList()); |
| + if (module_list.get()) { |
| + VerifyModules(module_list.get(), |
| + base::Bind(&OnModuleMatch)); |
|
robertshield
2013/09/17 17:06:59
nit: indent
|
| + } else { |
| + // Will delete itself when scan results are available. |
| + new InstallModuleVerifier(); |
| + EnumerateModulesModel::GetInstance()->ScanNow(); |
| + } |
| +} |
| + |
| +void VerifyModules(base::ListValue* module_list, |
| + const base::Callback<void(size_t)>& delegate) { |
|
MAD
2013/09/17 15:20:21
A DCHECK that module_list is not NULL?
|
| + std::set<std::wstring> canonical_module_names; |
| + for (size_t i = 0; i < module_list->GetSize(); ++i) { |
| + base::DictionaryValue* module_dictionary = NULL; |
| + if (!module_list->GetDictionary(i, &module_dictionary)) |
| + continue; |
| + ModuleEnumerator::ModuleType module_type = |
| + ModuleEnumerator::LOADED_MODULE; |
| + if (!module_dictionary->GetInteger( |
| + "type", reinterpret_cast<int*>(&module_type)) || |
| + module_type != ModuleEnumerator::LOADED_MODULE) { |
| + continue; |
| + } |
| + std::string utf8_module_name; |
| + if (!module_dictionary->GetString("name", &utf8_module_name)) |
| + continue; |
| + std::wstring module_name = base::UTF8ToWide(utf8_module_name); |
| + |
| + std::wstring canonical_module_name = CanonicalizeModuleName(module_name); |
| + canonical_module_names.insert(canonical_module_name); |
| + } |
| + for (size_t module_index = 0; kExpectedInstallModules[module_index] != 0; |
|
MAD
2013/09/17 15:20:21
0 -> NULL?
|
| + ++module_index) { |
| + if (canonical_module_names.find(kExpectedInstallModules[module_index]) != |
| + canonical_module_names.end()) { |
| + delegate.Run(module_index); |
| + } |
| + } |
| +} |