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

Unified 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, 12 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chrome_elf_init_win.cc
diff --git a/chrome/browser/chrome_elf_init_win.cc b/chrome/browser/chrome_elf_init_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4dd439d411a406548b5df38c70f80179587062c0
--- /dev/null
+++ b/chrome/browser/chrome_elf_init_win.cc
@@ -0,0 +1,100 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/metrics/field_trial.h"
+#include "base/metrics/histogram.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/win/registry.h"
+#include "chrome/browser/chrome_elf_init_win.h"
+#include "chrome/common/chrome_version_info.h"
+#include "chrome_elf/blacklist/blacklist.h"
+
+namespace {
+
+const char kBrowserBlacklistTrialName[] = "BrowserBlacklist";
+const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled";
+
+// This enum is used to define the buckets for an enumerated UMA histogram.
+// Hence,
+// (a) existing enumerated constants should never be deleted or reordered, and
+// (b) new constants should only be appended in front of
+// BLACKLIST_SETUP_EVENT_MAX.
+enum BlacklistSetupEventType {
+ // The blacklist beacon has placed to enable the browser blacklisting.
+ BLACKLIST_SETUP_ENABLED = 0,
+
+ // The blacklist was successfully enabled.
+ BLACKLIST_SETUP_RAN_SUCCESSFULLY,
+
+ // The blacklist setup code failed to execute.
+ BLACKLIST_SETUP_FAILED,
+
+ // Always keep this at the end.
+ BLACKLIST_SETUP_EVENT_MAX,
+};
+
+void RecordBlacklistSetupEvent(BlacklistSetupEventType blacklist_setup_event) {
+ UMA_HISTOGRAM_ENUMERATION("Blacklist.Setup",
+ blacklist_setup_event,
+ BLACKLIST_SETUP_EVENT_MAX);
+}
+
+} // namespace
+
+void InitializeChromeElf() {
+ if (base::FieldTrialList::FindFullName(kBrowserBlacklistTrialName) ==
+ kBrowserBlacklistTrialEnabledGroupName) {
+ BrowserBlacklistBeaconSetup();
+ } else {
+ // Disable the blacklist for all future runs by removing the beacon.
+ base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER);
+ blacklist_registry_key.DeleteKey(blacklist::kRegistryBeaconPath);
+ }
+}
+
+void BrowserBlacklistBeaconSetup() {
+ base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER,
+ blacklist::kRegistryBeaconPath,
+ KEY_QUERY_VALUE | KEY_SET_VALUE);
+
+ // Find the last recorded blacklist version and the current version.
+ base::string16 blacklist_version;
+ 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
+ &blacklist_version);
+
+ chrome::VersionInfo version_info;
+ base::string16 current_version(base::UTF8ToUTF16(version_info.Version()));
+ if (blacklist_version != current_version) {
+ // The blacklist hasn't run for this version yet, so enable it.
+ blacklist_registry_key.WriteValue(blacklist::kBeaconVersion,
+ current_version.c_str());
+
+ blacklist_registry_key.WriteValue(blacklist::kBeaconState,
+ blacklist::BLACKLIST_ENABLED);
+
+ RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED);
+
+ // Don't try to record if the blacklist setup succeeded or failed in the
+ // run since it could have been from either this version or the previous
+ // version (since crashes occur before we set the version in the registry).
+ } else {
+ // The blacklist version didn't change, so record the results of the
+ // latest setup.
+ DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX;
+ blacklist_registry_key.ReadValueDW(blacklist::kBeaconState,
+ &blacklist_state);
+
+ // Record the results of the latest blacklist setup.
+ if (blacklist_state == blacklist::BLACKLIST_ENABLED) {
+ RecordBlacklistSetupEvent(BLACKLIST_SETUP_RAN_SUCCESSFULLY);
+ } else if (blacklist_state == blacklist::BLACKLIST_SETUP_RUNNING) {
+ RecordBlacklistSetupEvent(BLACKLIST_SETUP_FAILED);
+
+ // Since the setup failed, mark the blacklist as disabled so we don't
+ // try it again for this version.
+ blacklist_registry_key.WriteValue(blacklist::kBeaconState,
+ blacklist::BLACKLIST_DISABLED);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698