Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/install_module_verifier_win.cc

Issue 23513049: Implement install module verification metric. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer comments. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/strings/utf_string_conversions.h"
15 #include "base/values.h"
16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/enumerate_modules_model_win.h"
18 #include "chrome/browser/expected_install_modules_win.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/notification_source.h"
23
24 namespace {
25
26 void OnModuleMatch(size_t module_id) {
27 UMA_HISTOGRAM_SPARSE_SLOWLY("InstallVerifier.ModuleMatch", module_id);
28 }
29
30 class InstallModuleVerifier : public content::NotificationObserver {
31 public:
32 InstallModuleVerifier() {
33 notification_registrar_.Add(this,
34 chrome::NOTIFICATION_MODULE_LIST_ENUMERATED,
35 content::NotificationService::AllSources());
36 }
37 virtual void Observe(int type,
38 const content::NotificationSource& source,
39 const content::NotificationDetails& details) OVERRIDE {
40 EnumerateModulesModel* model =
41 content::Source<EnumerateModulesModel>(source).ptr();
42 scoped_ptr<base::ListValue> module_list(model->GetModuleList());
43
44 if (module_list.get()) {
45 VerifyModules(module_list.get(), base::Bind(&OnModuleMatch));
46 }
47 delete this;
48 }
49
50 private:
51 content::NotificationRegistrar notification_registrar_;
52 DISALLOW_COPY_AND_ASSIGN(InstallModuleVerifier);
53 };
54
55 } // namespace
56
57 void BeginModuleVerification() {
58 scoped_ptr<base::ListValue> module_list(
59 EnumerateModulesModel::GetInstance()->GetModuleList());
60 if (module_list.get()) {
61 VerifyModules(module_list.get(),
62 base::Bind(&OnModuleMatch));
robertshield 2013/09/17 17:06:59 nit: indent
63 } else {
64 // Will delete itself when scan results are available.
65 new InstallModuleVerifier();
66 EnumerateModulesModel::GetInstance()->ScanNow();
67 }
68 }
69
70 void VerifyModules(base::ListValue* module_list,
71 const base::Callback<void(size_t)>& delegate) {
MAD 2013/09/17 15:20:21 A DCHECK that module_list is not NULL?
72 std::set<std::wstring> 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 utf8_module_name;
85 if (!module_dictionary->GetString("name", &utf8_module_name))
86 continue;
87 std::wstring module_name = base::UTF8ToWide(utf8_module_name);
88
89 std::wstring canonical_module_name = CanonicalizeModuleName(module_name);
90 canonical_module_names.insert(canonical_module_name);
91 }
92 for (size_t module_index = 0; kExpectedInstallModules[module_index] != 0;
MAD 2013/09/17 15:20:21 0 -> NULL?
93 ++module_index) {
94 if (canonical_module_names.find(kExpectedInstallModules[module_index]) !=
95 canonical_module_names.end()) {
96 delegate.Run(module_index);
97 }
98 }
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698