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

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: 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,
Alexei Svitkine (slow) 2014/01/06 20:43:05 Can this fail? (Should this check the return value
csharp 2014/01/07 20:04:02 This can potentially fail, but I don't think that
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 blacklist_registry_key.WriteValue(blacklist::kBeaconVersion,
71 current_version.c_str());
72
73 blacklist_registry_key.WriteValue(blacklist::kBeaconState,
74 blacklist::BLACKLIST_ENABLED);
75
76 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED);
77
78 // Don't try to record if the blacklist setup succeeded or failed in the
79 // run since it could have been from either this version or the previous
80 // version (since crashes occur before we set the version in the registry).
81 } else {
82 // The blacklist version didn't change, so record the results of the
83 // latest setup.
84 DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX;
85 blacklist_registry_key.ReadValueDW(blacklist::kBeaconState,
86 &blacklist_state);
87
88 // Record the results of the latest blacklist setup.
89 if (blacklist_state == blacklist::BLACKLIST_ENABLED) {
90 RecordBlacklistSetupEvent(BLACKLIST_SETUP_RAN_SUCCESSFULLY);
91 } else if (blacklist_state == blacklist::BLACKLIST_SETUP_RUNNING) {
92 RecordBlacklistSetupEvent(BLACKLIST_SETUP_FAILED);
93
94 // Since the setup failed, mark the blacklist as disabled so we don't
95 // try it again for this version.
96 blacklist_registry_key.WriteValue(blacklist::kBeaconState,
97 blacklist::BLACKLIST_DISABLED);
98 }
99 }
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698