Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / chrome / common / terminate_on_heap_corruption_experiment_win.cc
blobac88b9ca69782c155d6a9682931eaf447241a2b1
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 #if defined(OS_WIN)
14 #if defined(GOOGLE_CHROME_BUILD)
15 #define PRODUCT_STRING_PATH L"Google\\Chrome"
16 #elif defined(CHROMIUM_BUILD)
17 #define PRODUCT_STRING_PATH L"Chromium"
18 #else
19 #error Unknown branding
20 #endif
21 #endif // defined(OS_WIN)
23 namespace {
25 const wchar_t* GetBeaconKeyPath() {
26 chrome::VersionInfo::Channel channel = chrome::VersionInfo::CHANNEL_UNKNOWN;
28 // We are called quite early, before the CommandLine is initialized. We don't
29 // want to permanently initialize it because ContentMainRunner::Initialize
30 // sets some locale-related stuff to make sure it is parsed properly. But we
31 // can temporarily initialize it for the purpose of determining if we are
32 // Canary.
33 if (!CommandLine::InitializedForCurrentProcess()) {
34 CommandLine::Init(0, NULL);
35 channel = chrome::VersionInfo::GetChannel();
36 CommandLine::Reset();
37 } else {
38 channel = chrome::VersionInfo::GetChannel();
41 if (channel == chrome::VersionInfo::CHANNEL_CANARY) {
42 return L"SOFTWARE\\" PRODUCT_STRING_PATH
43 L"\\DisableTerminateOnProcessHeapCorruptionSxs";
45 return L"SOFTWARE\\" PRODUCT_STRING_PATH
46 L"\\DisableTerminateOnProcessHeapCorruption";
49 } // namespace
51 bool ShouldExperimentallyDisableTerminateOnHeapCorruption() {
52 base::win::RegKey regkey(
53 HKEY_CURRENT_USER, GetBeaconKeyPath(), KEY_QUERY_VALUE);
54 return regkey.Valid();
57 void InitializeDisableTerminateOnHeapCorruptionExperiment() {
58 base::win::RegKey regkey(HKEY_CURRENT_USER);
60 if (base::FieldTrialList::FindFullName("TerminateOnProcessHeapCorruption") ==
61 "Disabled") {
62 regkey.CreateKey(GetBeaconKeyPath(), KEY_SET_VALUE);
63 } else {
64 regkey.DeleteKey(GetBeaconKeyPath());