Resurrect battery_status_dispatcher_unittest.
[chromium-blink-merge.git] / chrome / common / terminate_on_heap_corruption_experiment_win.cc
bloba4dde265f5ffe2c01e57c24cdd31c664f09edbe5
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.
5 #include "chrome/common/terminate_on_heap_corruption_experiment_win.h"
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "base/win/registry.h"
10 #include "chrome/common/chrome_constants.h"
11 #include "chrome/common/chrome_version_info.h"
13 namespace {
15 const wchar_t* GetBeaconKeyPath() {
16 chrome::VersionInfo::Channel channel = chrome::VersionInfo::CHANNEL_UNKNOWN;
18 // We are called quite early, before the CommandLine is initialized. We don't
19 // want to permanently initialize it because ContentMainRunner::Initialize
20 // sets some locale-related stuff to make sure it is parsed properly. But we
21 // can temporarily initialize it for the purpose of determining if we are
22 // Canary.
23 if (!base::CommandLine::InitializedForCurrentProcess()) {
24 base::CommandLine::Init(0, NULL);
25 channel = chrome::VersionInfo::GetChannel();
26 base::CommandLine::Reset();
27 } else {
28 channel = chrome::VersionInfo::GetChannel();
31 if (channel == chrome::VersionInfo::CHANNEL_CANARY) {
32 return L"SOFTWARE\\" PRODUCT_STRING_PATH
33 L"\\DisableTerminateOnProcessHeapCorruptionSxs";
35 return L"SOFTWARE\\" PRODUCT_STRING_PATH
36 L"\\DisableTerminateOnProcessHeapCorruption";
39 } // namespace
41 bool ShouldExperimentallyDisableTerminateOnHeapCorruption() {
42 base::win::RegKey regkey(
43 HKEY_CURRENT_USER, GetBeaconKeyPath(), KEY_QUERY_VALUE);
44 return regkey.Valid();
47 void InitializeDisableTerminateOnHeapCorruptionExperiment() {
48 base::win::RegKey regkey(HKEY_CURRENT_USER);
50 if (base::FieldTrialList::FindFullName("TerminateOnProcessHeapCorruption") ==
51 "Disabled") {
52 regkey.CreateKey(GetBeaconKeyPath(), KEY_SET_VALUE);
53 } else {
54 regkey.DeleteKey(GetBeaconKeyPath());