| 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..4ec84e542735959f269c55f3a00bc9b3c6046142
|
| --- /dev/null
|
| +++ b/chrome/browser/install_module_verifier_win.cc
|
| @@ -0,0 +1,97 @@
|
| +// 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/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()) {
|
| + VerifyInstalledModules(module_list.get(), base::Bind(&OnModuleMatch));
|
| + }
|
| + delete this;
|
| + }
|
| +
|
| + private:
|
| + content::NotificationRegistrar notification_registrar_;
|
| + DISALLOW_COPY_AND_ASSIGN(InstallModuleVerifier);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +void InitiateInstalledModuleVerification() {
|
| + scoped_ptr<base::ListValue> module_list(
|
| + EnumerateModulesModel::GetInstance()->GetModuleList());
|
| + if (module_list.get()) {
|
| + VerifyInstalledModules(module_list.get(),
|
| + base::Bind(&OnModuleMatch));
|
| + } else {
|
| + // Will delete itself when scan results are available.
|
| + new InstallModuleVerifier();
|
| + EnumerateModulesModel::GetInstance()->ScanNow();
|
| + }
|
| +}
|
| +
|
| +void VerifyInstalledModules(
|
| + base::ListValue* module_list,
|
| + const base::Callback<void(unsigned int)>& delegate) {
|
| + std::set<std::string> 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 module_name;
|
| + if (!module_dictionary->GetString("name", &module_name))
|
| + continue;
|
| +
|
| + std::string canonical_module_name = CanonicalizeModuleName(module_name);
|
| + canonical_module_names.insert(canonical_module_name);
|
| + }
|
| + for (size_t i = 0; kExpectedInstallModules[i] != 0; ++i) {
|
| + if (canonical_module_names.find(kExpectedInstallModules[i]) !=
|
| + canonical_module_names.end()) {
|
| + delegate.Run(i);
|
| + }
|
| + }
|
| +}
|
|
|