Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win. h" | 5 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win. h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 // registered so that UMA metrics recorded during the current startup are | 24 // registered so that UMA metrics recorded during the current startup are |
| 25 // annotated with the pre-read group that is actually used during this startup. | 25 // annotated with the pre-read group that is actually used during this startup. |
| 26 const char kPreReadSyntheticFieldTrialName[] = "SyntheticPreRead"; | 26 const char kPreReadSyntheticFieldTrialName[] = "SyntheticPreRead"; |
| 27 | 27 |
| 28 // Variation names for the PreRead field trial. | 28 // Variation names for the PreRead field trial. |
| 29 const base::char16 kNoPreReadVariationName[] = L"NoPreRead"; | 29 const base::char16 kNoPreReadVariationName[] = L"NoPreRead"; |
| 30 const base::char16 kHighPriorityVariationName[] = L"HighPriority"; | 30 const base::char16 kHighPriorityVariationName[] = L"HighPriority"; |
| 31 const base::char16 kOnlyIfColdVariationName[] = L"OnlyIfCold"; | 31 const base::char16 kOnlyIfColdVariationName[] = L"OnlyIfCold"; |
| 32 const base::char16 kPrefetchVirtualMemoryVariationName[] = | 32 const base::char16 kPrefetchVirtualMemoryVariationName[] = |
| 33 L"PrefetchVirtualMemory"; | 33 L"PrefetchVirtualMemory"; |
| 34 const base::char16 kNoPrefetchArgumentVariationName[] = L"NoPrefetchArgument"; | |
|
gab
2016/01/26 21:40:26
It may not be clear to a reader that the reason so
fdoray
2016/01/27 20:12:19
Done.
| |
| 34 | 35 |
| 35 // Registry key in which the PreRead field trial group is stored. | 36 // Registry key in which the PreRead field trial group is stored. |
| 36 const base::char16 kPreReadFieldTrialRegistryKey[] = L"\\PreReadFieldTrial"; | 37 const base::char16 kPreReadFieldTrialRegistryKey[] = L"\\PreReadFieldTrial"; |
| 37 | 38 |
| 38 // Pre-read options to use for the current process. This is initialized by | 39 // Pre-read options to use for the current process. This is initialized by |
| 39 // InitializePreReadOptions(). | 40 // InitializePreReadOptions(). |
| 40 PreReadOptions g_pre_read_options = {false, false, false, false}; | 41 PreReadOptions g_pre_read_options = {false, false, false, false}; |
| 41 | 42 |
| 42 // Returns the registry path in which the PreRead group is stored. | 43 // Returns the registry path in which the PreRead group is stored. |
| 43 base::string16 GetPreReadRegistryPath( | 44 base::string16 GetPreReadRegistryPath( |
| 44 const base::string16& product_registry_path) { | 45 const base::string16& product_registry_path) { |
| 45 return product_registry_path + kPreReadFieldTrialRegistryKey; | 46 return product_registry_path + kPreReadFieldTrialRegistryKey; |
| 46 } | 47 } |
| 47 | 48 |
| 49 // Returns true if |key| has a value named |name| which is not zero. | |
| 50 bool ReadBool(const base::win::RegKey& key, const base::char16* name) { | |
| 51 DWORD value = 0; | |
| 52 return key.ReadValueDW(name, &value) == ERROR_SUCCESS && value != 0; | |
| 53 } | |
| 54 | |
| 48 } // namespace | 55 } // namespace |
| 49 | 56 |
| 50 void InitializePreReadOptions(const base::string16& product_registry_path) { | 57 void InitializePreReadOptions(const base::string16& product_registry_path) { |
| 51 DCHECK(!product_registry_path.empty()); | 58 DCHECK(!product_registry_path.empty()); |
| 52 | 59 |
| 53 // Open the PreRead field trial's registry key. | 60 // Open the PreRead field trial's registry key. |
| 54 const base::string16 registry_path = | 61 const base::string16 registry_path = |
| 55 GetPreReadRegistryPath(product_registry_path); | 62 GetPreReadRegistryPath(product_registry_path); |
| 56 const base::win::RegKey key(HKEY_CURRENT_USER, registry_path.c_str(), | 63 const base::win::RegKey key(HKEY_CURRENT_USER, registry_path.c_str(), |
| 57 KEY_QUERY_VALUE); | 64 KEY_QUERY_VALUE); |
| 58 | 65 |
| 59 // Set the PreRead field trial's options. | 66 // Set the PreRead field trial's options. |
| 60 struct { | 67 g_pre_read_options.pre_read = !ReadBool(key, kNoPreReadVariationName); |
| 61 const base::char16* name; | 68 g_pre_read_options.high_priority = ReadBool(key, kHighPriorityVariationName); |
| 62 bool* option; | 69 g_pre_read_options.only_if_cold = ReadBool(key, kOnlyIfColdVariationName); |
| 63 } const variations_mappings[] = { | 70 g_pre_read_options.prefetch_virtual_memory = |
| 64 {kNoPreReadVariationName, &g_pre_read_options.no_pre_read}, | 71 ReadBool(key, kPrefetchVirtualMemoryVariationName); |
| 65 {kHighPriorityVariationName, &g_pre_read_options.high_priority}, | 72 g_pre_read_options.prefetch_argument = |
| 66 {kOnlyIfColdVariationName, &g_pre_read_options.only_if_cold}, | 73 !ReadBool(key, kNoPrefetchArgumentVariationName); |
| 67 {kPrefetchVirtualMemoryVariationName, | |
| 68 &g_pre_read_options.prefetch_virtual_memory}, | |
| 69 }; | |
| 70 | |
| 71 for (const auto& mapping : variations_mappings) { | |
| 72 // Set the option variable to true if the corresponding value is found in | |
| 73 // the registry. Set to false otherwise (default behavior). | |
| 74 DWORD value = 0; | |
| 75 if (key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS) { | |
| 76 DCHECK_EQ(1U, value); | |
| 77 DCHECK(!*mapping.option); | |
| 78 *mapping.option = true; | |
| 79 } | |
| 80 } | |
| 81 } | 74 } |
| 82 | 75 |
| 83 PreReadOptions GetPreReadOptions() { | 76 PreReadOptions GetPreReadOptions() { |
| 84 return g_pre_read_options; | 77 return g_pre_read_options; |
| 85 } | 78 } |
| 86 | 79 |
| 87 void UpdatePreReadOptions(const base::string16& product_registry_path) { | 80 void UpdatePreReadOptions(const base::string16& product_registry_path) { |
| 88 DCHECK(!product_registry_path.empty()); | 81 DCHECK(!product_registry_path.empty()); |
| 89 | 82 |
| 90 const base::string16 registry_path = | 83 const base::string16 registry_path = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 base::string16 group; | 134 base::string16 group; |
| 142 key.ReadValue(L"", &group); | 135 key.ReadValue(L"", &group); |
| 143 | 136 |
| 144 if (!group.empty()) { | 137 if (!group.empty()) { |
| 145 register_synthetic_field_trial.Run(kPreReadSyntheticFieldTrialName, | 138 register_synthetic_field_trial.Run(kPreReadSyntheticFieldTrialName, |
| 146 base::UTF16ToUTF8(group)); | 139 base::UTF16ToUTF8(group)); |
| 147 } | 140 } |
| 148 } | 141 } |
| 149 | 142 |
| 150 } // namespace startup_metric_utils | 143 } // namespace startup_metric_utils |
| OLD | NEW |