Index: components/startup_metric_utils/common/pre_read_field_trial_utils_win.cc |
diff --git a/components/startup_metric_utils/common/pre_read_field_trial_utils_win.cc b/components/startup_metric_utils/common/pre_read_field_trial_utils_win.cc |
index 6aa82a19d93e59d8da9f80ca767206fe5f438be6..f6d1c4bfb3142af3a2a643d86aadc3b072a8b2df 100644 |
--- a/components/startup_metric_utils/common/pre_read_field_trial_utils_win.cc |
+++ b/components/startup_metric_utils/common/pre_read_field_trial_utils_win.cc |
@@ -35,6 +35,13 @@ const base::char16 kPrefetchVirtualMemoryVariationName[] = |
// Registry key in which the PreRead field trial group is stored. |
const base::char16 kPreReadFieldTrialRegistryKey[] = L"\\PreReadFieldTrial"; |
+// Pre-read options to use for the current process. This is initialized by |
+// InitializePreReadOptions(). |
+int g_pre_read_options = 0; |
+ |
+// True once |g_pre_read_options| has been initialized. |
+bool g_pre_read_options_initialized = false; |
gab
2016/01/20 20:09:39
I'd like to avoid this global in non-dcheck builds
fdoray
2016/01/20 21:58:53
Done, I added a PRE_READ_OPTION_UNINITIALIZED bit.
|
+ |
// Returns the registry path in which the PreRead group is stored. |
base::string16 GetPreReadRegistryPath( |
const base::string16& product_registry_path) { |
@@ -43,16 +50,9 @@ base::string16 GetPreReadRegistryPath( |
} // namespace |
-void GetPreReadOptions(const base::string16& product_registry_path, |
- bool* no_pre_read, |
- bool* high_priority, |
- bool* only_if_cold, |
- bool* prefetch_virtual_memory) { |
+void InitializePreReadOptions(const base::string16& product_registry_path) { |
DCHECK(!product_registry_path.empty()); |
- DCHECK(no_pre_read); |
- DCHECK(high_priority); |
- DCHECK(only_if_cold); |
- DCHECK(prefetch_virtual_memory); |
+ DCHECK(!g_pre_read_options_initialized); |
// Open the PreRead field trial's registry key. |
const base::string16 registry_path = |
@@ -63,21 +63,31 @@ void GetPreReadOptions(const base::string16& product_registry_path, |
// Set the PreRead field trial's options. |
struct VariationMapping { |
const base::char16* name; |
- bool* variable; |
+ PreReadOptions bit; |
} const variations_mappings[] = { |
- {kNoPreReadVariationName, no_pre_read}, |
- {kHighPriorityVariationName, high_priority}, |
- {kOnlyIfColdVariationName, only_if_cold}, |
- {kPrefetchVirtualMemoryVariationName, prefetch_virtual_memory}, |
+ {kNoPreReadVariationName, PRE_READ_OPTION_NO_PRE_READ}, |
+ {kHighPriorityVariationName, PRE_READ_OPTION_HIGH_PRIORITY}, |
+ {kOnlyIfColdVariationName, PRE_READ_OPTION_ONLY_IF_COLD}, |
+ {kPrefetchVirtualMemoryVariationName, |
+ PRE_READ_OPTION_PREFETCH_VIRTUAL_MEMORY}, |
}; |
for (const auto& mapping : variations_mappings) { |
// Set the option variable to true if the corresponding value is found in |
// the registry. Set to false otherwise (default behavior). |
DWORD value = 0; |
- *mapping.variable = key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS; |
- DCHECK(!*mapping.variable || value == 1); |
+ if (key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS) { |
+ DCHECK(value == 1); |
gab
2016/01/20 20:09:40
DCHECK_EQ(1, value)
fdoray
2016/01/20 21:58:53
Done.
|
+ g_pre_read_options &= mapping.bit; |
+ } |
} |
+ |
+ g_pre_read_options_initialized = true; |
+} |
+ |
+int GetPreReadOptions() { |
+ DCHECK(g_pre_read_options_initialized); |
+ return g_pre_read_options; |
} |
void UpdatePreReadOptions(const base::string16& product_registry_path) { |