Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
|
robertshield
2014/01/02 20:42:22
2014
csharp
2014/01/02 21:57:59
Done.
| |
| 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"; | |
|
robertshield
2014/01/02 20:42:22
nit: alphabetize these
csharp
2014/01/02 21:57:59
I looked at a couple files and this order (trial n
robertshield
2014/01/03 03:21:42
Ok, not a strong preference. If this is convention
| |
| 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 SetupChromeElfInitialization() { | |
| 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_READ | KEY_WRITE); | |
|
robertshield
2014/01/02 20:42:22
I believe this should be KEY_QUERY_VALUE | KEY_SET
csharp
2014/01/02 21:57:59
Yup, that seems to work.
| |
| 60 | |
| 61 DWORD blacklist_state = 0; | |
| 62 blacklist_registry_key.ReadValueDW(blacklist::kBeaconState, &blacklist_state); | |
| 63 | |
| 64 // Record the results of the latest blacklist setup. | |
| 65 if (blacklist_state == blacklist::BLACKLIST_ENABLED) { | |
| 66 RecordBlacklistSetupEvent(BLACKLIST_SETUP_RAN_SUCCESSFULLY); | |
| 67 } else if (blacklist_state == blacklist::BLACKLIST_SETUP_RUNNING) { | |
| 68 RecordBlacklistSetupEvent(BLACKLIST_SETUP_FAILED); | |
|
robertshield
2014/01/02 20:42:22
as discussed, can we check the version here to mak
csharp
2014/01/02 21:57:59
Done.
| |
| 69 | |
| 70 // Since the setup failed, mark the blacklist as disabled so we don't | |
| 71 // try it again for this version. | |
| 72 blacklist_registry_key.WriteValue(blacklist::kBeaconState, | |
| 73 blacklist::BLACKLIST_DISABLED); | |
| 74 } | |
| 75 | |
| 76 // Find the version the blacklist was last enabled for. | |
| 77 std::wstring blacklist_version(L""); | |
| 78 blacklist_registry_key.ReadValue(blacklist::kBeaconVersion, | |
| 79 &blacklist_version); | |
| 80 | |
| 81 // If the blacklist hasn't been enabled for this version yet, enable it. | |
| 82 chrome::VersionInfo version_info; | |
| 83 base::string16 current_version = base::UTF8ToUTF16(version_info.Version()); | |
|
robertshield
2014/01/02 20:42:22
nit: prefer direct construction vs assignment (it
csharp
2014/01/02 21:57:59
Done.
| |
| 84 if (blacklist_version != current_version) { | |
| 85 blacklist_registry_key.WriteValue(blacklist::kBeaconVersion, | |
| 86 current_version.c_str()); | |
| 87 | |
| 88 blacklist_registry_key.WriteValue(blacklist::kBeaconState, | |
| 89 blacklist::BLACKLIST_ENABLED); | |
| 90 | |
| 91 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED); | |
| 92 } | |
| 93 } | |
| OLD | NEW |