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

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

Issue 120963002: Use a Finch Experiment to control the Browser Blacklist (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Responding to comments Created 6 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2014 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 "base/metrics/field_trial.h"
6 #include "base/metrics/histogram.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/win/registry.h"
9 #include "chrome/browser/chrome_elf_init_win.h"
10 #include "chrome/common/chrome_version_info.h"
11 #include "chrome_elf/blacklist/blacklist.h"
12
13 namespace {
14
15 const char kBrowserBlacklistTrialName[] = "BrowserBlacklist";
16 const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled";
17
18 // This enum is used to define the buckets for an enumerated UMA histogram.
19 // Hence,
20 // (a) existing enumerated constants should never be deleted or reordered, and
21 // (b) new constants should only be appended in front of
22 // BLACKLIST_SETUP_EVENT_MAX.
23 enum BlacklistSetupEventType {
24 // The blacklist beacon has placed to enable the browser blacklisting.
25 BLACKLIST_SETUP_ENABLED = 0,
26
27 // The blacklist was successfully enabled.
28 BLACKLIST_SETUP_RAN_SUCCESSFULLY,
29
30 // The blacklist setup code failed to execute.
31 BLACKLIST_SETUP_FAILED,
32
33 // Always keep this at the end.
34 BLACKLIST_SETUP_EVENT_MAX,
35 };
36
37 void RecordBlacklistSetupEvent(BlacklistSetupEventType blacklist_setup_event) {
38 UMA_HISTOGRAM_ENUMERATION("Blacklist.Setup",
39 blacklist_setup_event,
40 BLACKLIST_SETUP_EVENT_MAX);
41 }
42
43 } // namespace
44
45 void InitializeChromeElf() {
46 if (base::FieldTrialList::FindFullName(kBrowserBlacklistTrialName) ==
47 kBrowserBlacklistTrialEnabledGroupName) {
48 BrowserBlacklistBeaconSetup();
49 } else {
50 // Disable the blacklist for all future runs by removing the beacon.
51 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER);
52 blacklist_registry_key.DeleteKey(blacklist::kRegistryBeaconPath);
53 }
54 }
55
56 void BrowserBlacklistBeaconSetup() {
57 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER,
58 blacklist::kRegistryBeaconPath,
59 KEY_QUERY_VALUE | KEY_SET_VALUE);
60
61 // Find the last recorded blacklist version and the current version.
62 base::string16 blacklist_version;
63 blacklist_registry_key.ReadValue(blacklist::kBeaconVersion,
sky 2014/01/07 23:15:08 What will the effects be of someone running two ve
csharp 2014/01/08 21:07:07 Different user installs should interact with each
64 &blacklist_version);
65
66 chrome::VersionInfo version_info;
67 base::string16 current_version(base::UTF8ToUTF16(version_info.Version()));
68 if (blacklist_version != current_version) {
69 // The blacklist hasn't run for this version yet, so enable it.
70 LONG set_version = blacklist_registry_key.WriteValue(
71 blacklist::kBeaconVersion,
72 current_version.c_str());
73
74 LONG set_state = blacklist_registry_key.WriteValue(
75 blacklist::kBeaconState,
76 blacklist::BLACKLIST_ENABLED);
77
78 // Only report the blacklist as getting setup when both registry writes
79 // succeed, since otherwise the blacklist wasn't properly setup.
80 if (set_version == ERROR_SUCCESS && set_state == ERROR_SUCCESS) {
sky 2014/01/07 23:15:08 nit: no {}
csharp 2014/01/08 21:07:07 Done.
81 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED);
82 }
83
84 // Don't try to record if the blacklist setup succeeded or failed in the
85 // run since it could have been from either this version or the previous
86 // version (since crashes occur before we set the version in the registry).
87 } else {
88 // The blacklist version didn't change, so record the results of the
89 // latest setup.
90 DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX;
91 blacklist_registry_key.ReadValueDW(blacklist::kBeaconState,
92 &blacklist_state);
93
94 // Record the results of the latest blacklist setup.
95 if (blacklist_state == blacklist::BLACKLIST_ENABLED) {
96 RecordBlacklistSetupEvent(BLACKLIST_SETUP_RAN_SUCCESSFULLY);
97 } else if (blacklist_state == blacklist::BLACKLIST_SETUP_RUNNING) {
98 RecordBlacklistSetupEvent(BLACKLIST_SETUP_FAILED);
99
100 // Since the setup failed, mark the blacklist as disabled so we don't
101 // try it again for this version.
102 blacklist_registry_key.WriteValue(blacklist::kBeaconState,
103 blacklist::BLACKLIST_DISABLED);
104 }
105 }
106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698