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 17 matching lines...) Expand all Loading... | |
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 | 34 |
35 // Registry key in which the PreRead field trial group is stored. | 35 // Registry key in which the PreRead field trial group is stored. |
36 const base::char16 kPreReadFieldTrialRegistryKey[] = L"\\PreReadFieldTrial"; | 36 const base::char16 kPreReadFieldTrialRegistryKey[] = L"\\PreReadFieldTrial"; |
37 | 37 |
38 // Pre-read options to use for the current process. This is initialized by | |
39 // InitializePreReadOptions(). | |
40 int g_pre_read_options = PRE_READ_OPTION_UNINITIALIZED; | |
grt (UTC plus 2)
2016/01/21 04:24:00
if i'm reading the build files correctly, this .cc
fdoray
2016/01/21 16:04:16
Yes. The call in chrome.exe is added by this CL he
| |
41 | |
38 // Returns the registry path in which the PreRead group is stored. | 42 // Returns the registry path in which the PreRead group is stored. |
39 base::string16 GetPreReadRegistryPath( | 43 base::string16 GetPreReadRegistryPath( |
40 const base::string16& product_registry_path) { | 44 const base::string16& product_registry_path) { |
41 return product_registry_path + kPreReadFieldTrialRegistryKey; | 45 return product_registry_path + kPreReadFieldTrialRegistryKey; |
42 } | 46 } |
43 | 47 |
44 } // namespace | 48 } // namespace |
45 | 49 |
46 void GetPreReadOptions(const base::string16& product_registry_path, | 50 void InitializePreReadOptions(const base::string16& product_registry_path) { |
47 bool* no_pre_read, | |
48 bool* high_priority, | |
49 bool* only_if_cold, | |
50 bool* prefetch_virtual_memory) { | |
51 DCHECK(!product_registry_path.empty()); | 51 DCHECK(!product_registry_path.empty()); |
52 DCHECK(no_pre_read); | 52 DCHECK_EQ(g_pre_read_options, PRE_READ_OPTION_UNINITIALIZED); |
grt (UTC plus 2)
2016/01/21 04:24:00
nit: always put the expected value first when usin
fdoray
2016/01/21 16:04:16
Done (I removed this line).
| |
53 DCHECK(high_priority); | 53 |
54 DCHECK(only_if_cold); | 54 g_pre_read_options = 0; |
55 DCHECK(prefetch_virtual_memory); | |
56 | 55 |
57 // Open the PreRead field trial's registry key. | 56 // Open the PreRead field trial's registry key. |
58 const base::string16 registry_path = | 57 const base::string16 registry_path = |
59 GetPreReadRegistryPath(product_registry_path); | 58 GetPreReadRegistryPath(product_registry_path); |
60 const base::win::RegKey key(HKEY_CURRENT_USER, registry_path.c_str(), | 59 const base::win::RegKey key(HKEY_CURRENT_USER, registry_path.c_str(), |
61 KEY_QUERY_VALUE); | 60 KEY_QUERY_VALUE); |
62 | 61 |
63 // Set the PreRead field trial's options. | 62 // Set the PreRead field trial's options. |
64 struct VariationMapping { | 63 struct VariationMapping { |
grt (UTC plus 2)
2016/01/21 04:24:00
nit: make this an anonymous struct since the name
fdoray
2016/01/21 16:04:16
Done.
| |
65 const base::char16* name; | 64 const base::char16* name; |
66 bool* variable; | 65 PreReadOptions bit; |
67 } const variations_mappings[] = { | 66 } const variations_mappings[] = { |
68 {kNoPreReadVariationName, no_pre_read}, | 67 {kNoPreReadVariationName, PRE_READ_OPTION_NO_PRE_READ}, |
69 {kHighPriorityVariationName, high_priority}, | 68 {kHighPriorityVariationName, PRE_READ_OPTION_HIGH_PRIORITY}, |
70 {kOnlyIfColdVariationName, only_if_cold}, | 69 {kOnlyIfColdVariationName, PRE_READ_OPTION_ONLY_IF_COLD}, |
71 {kPrefetchVirtualMemoryVariationName, prefetch_virtual_memory}, | 70 {kPrefetchVirtualMemoryVariationName, |
71 PRE_READ_OPTION_PREFETCH_VIRTUAL_MEMORY}, | |
72 }; | 72 }; |
73 | 73 |
74 for (const auto& mapping : variations_mappings) { | 74 for (const auto& mapping : variations_mappings) { |
75 // Set the option variable to true if the corresponding value is found in | 75 // Set the option variable to true if the corresponding value is found in |
76 // the registry. Set to false otherwise (default behavior). | 76 // the registry. Set to false otherwise (default behavior). |
77 DWORD value = 0; | 77 DWORD value = 0; |
78 *mapping.variable = key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS; | 78 if (key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS) { |
79 DCHECK(!*mapping.variable || value == 1); | 79 DCHECK_EQ(1U, value); |
80 g_pre_read_options &= mapping.bit; | |
grt (UTC plus 2)
2016/01/21 04:24:00
|=
fdoray
2016/01/21 16:04:16
Done (now using a struct).
| |
81 } | |
80 } | 82 } |
81 } | 83 } |
82 | 84 |
85 int GetPreReadOptions() { | |
86 return g_pre_read_options; | |
87 } | |
88 | |
83 void UpdatePreReadOptions(const base::string16& product_registry_path) { | 89 void UpdatePreReadOptions(const base::string16& product_registry_path) { |
84 DCHECK(!product_registry_path.empty()); | 90 DCHECK(!product_registry_path.empty()); |
85 | 91 |
86 const base::string16 registry_path = | 92 const base::string16 registry_path = |
87 GetPreReadRegistryPath(product_registry_path); | 93 GetPreReadRegistryPath(product_registry_path); |
88 | 94 |
89 // Clear the experiment key. That way, when the trial is shut down, the | 95 // Clear the experiment key. That way, when the trial is shut down, the |
90 // registry will be cleaned automatically. Also, this prevents variation | 96 // registry will be cleaned automatically. Also, this prevents variation |
91 // params from the previous group to stay in the registry when the group is | 97 // params from the previous group to stay in the registry when the group is |
92 // updated. | 98 // updated. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 base::string16 group; | 143 base::string16 group; |
138 key.ReadValue(L"", &group); | 144 key.ReadValue(L"", &group); |
139 | 145 |
140 if (!group.empty()) { | 146 if (!group.empty()) { |
141 register_synthetic_field_trial.Run(kPreReadSyntheticFieldTrialName, | 147 register_synthetic_field_trial.Run(kPreReadSyntheticFieldTrialName, |
142 base::UTF16ToUTF8(group)); | 148 base::UTF16ToUTF8(group)); |
143 } | 149 } |
144 } | 150 } |
145 | 151 |
146 } // namespace startup_metric_utils | 152 } // namespace startup_metric_utils |
OLD | NEW |