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

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: Merge and final nits. 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/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/metrics/sparse_histogram.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/enumerate_modules_model_win.h"
19 #include "chrome/browser/expected_install_modules_win.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/notification_source.h"
24
25 namespace {
26
27 void OnModuleMatch(size_t module_id) {
28 UMA_HISTOGRAM_SPARSE_SLOWLY("InstallVerifier.ModuleMatch", module_id);
29 }
30
31 class InstallModuleVerifier : public content::NotificationObserver {
32 public:
33 InstallModuleVerifier() {
34 notification_registrar_.Add(this,
35 chrome::NOTIFICATION_MODULE_LIST_ENUMERATED,
36 content::NotificationService::AllSources());
37 }
38 virtual void Observe(int type,
39 const content::NotificationSource& source,
40 const content::NotificationDetails& details) OVERRIDE {
Finnur 2013/09/20 14:23:14 Maybe DCHECK that you got back type == NOTIFICATIO
erikwright (departed) 2013/09/24 17:33:51 Done.
41 EnumerateModulesModel* model =
42 content::Source<EnumerateModulesModel>(source).ptr();
43 scoped_ptr<base::ListValue> module_list(model->GetModuleList());
44
45 if (module_list.get()) {
46 VerifyModules(module_list.get(), base::Bind(&OnModuleMatch));
47 }
Finnur 2013/09/20 14:23:14 nit: No braces around single line ifs.
erikwright (departed) 2013/09/24 17:33:51 Done.
48 delete this;
49 }
50
51 private:
52 content::NotificationRegistrar notification_registrar_;
53 DISALLOW_COPY_AND_ASSIGN(InstallModuleVerifier);
Finnur 2013/09/20 14:23:14 nit: Space before this line.
erikwright (departed) 2013/09/24 17:33:51 Done.
54 };
55
56 } // namespace
57
58 void BeginModuleVerification() {
59 scoped_ptr<base::ListValue> module_list(
60 EnumerateModulesModel::GetInstance()->GetModuleList());
61 if (module_list.get()) {
62 VerifyModules(module_list.get(),
63 base::Bind(&OnModuleMatch));
64 } else {
65 // Will delete itself when scan results are available.
66 new InstallModuleVerifier();
67 EnumerateModulesModel::GetInstance()->ScanNow();
68 }
69 }
70
71 void VerifyModules(base::ListValue* module_list,
sky 2013/09/19 20:54:36 Can this take a const base::ListValue& ?
erikwright (departed) 2013/09/24 17:33:51 Done.
72 const base::Callback<void(size_t)>& delegate) {
73 DCHECK(module_list);
74
75 std::set<std::wstring> canonical_module_names;
sky 2013/09/19 20:54:36 This code would be clearer if you broke this into
erikwright (departed) 2013/09/24 17:33:51 Let me know if the new factoring corresponds to wh
76 for (size_t i = 0; i < module_list->GetSize(); ++i) {
77 base::DictionaryValue* module_dictionary = NULL;
78 if (!module_list->GetDictionary(i, &module_dictionary))
79 continue;
80 ModuleEnumerator::ModuleType module_type =
81 ModuleEnumerator::LOADED_MODULE;
82 if (!module_dictionary->GetInteger(
83 "type", reinterpret_cast<int*>(&module_type)) ||
84 module_type != ModuleEnumerator::LOADED_MODULE) {
85 continue;
86 }
87 std::string utf8_module_name;
88 if (!module_dictionary->GetString("name", &utf8_module_name))
89 continue;
90 std::wstring module_name = base::UTF8ToWide(utf8_module_name);
Finnur 2013/09/20 14:23:14 nit: s/std::wstring/string16/g Yes, it is the same
erikwright (departed) 2013/09/24 17:33:51 Done.
Finnur 2013/09/25 12:54:22 Hmmm, I didn't realize we had started using the ba
91
92 std::wstring canonical_module_name = CanonicalizeModuleName(module_name);
93 canonical_module_names.insert(canonical_module_name);
94 }
95 for (size_t module_index = 0; kExpectedInstallModules[module_index] != NULL;
96 ++module_index) {
97 if (canonical_module_names.find(kExpectedInstallModules[module_index]) !=
98 canonical_module_names.end()) {
99 delegate.Run(module_index);
100 }
Finnur 2013/09/20 14:23:14 Nit: Single line -- no brace. Also, don't you wan
erikwright (departed) 2013/09/24 17:33:51 My understanding is that, if the condition is more
Finnur 2013/09/25 12:54:22 Oh, it is a *set*. I overlooked that part. I thoug
101 }
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698