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"; |
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 // Returns the registry path in which the PreRead group is stored. | 39 // Returns the registry path in which the PreRead group is stored. |
39 base::string16 GetPreReadRegistryPath( | 40 base::string16 GetPreReadRegistryPath( |
40 const base::string16& product_registry_path) { | 41 const base::string16& product_registry_path) { |
41 return product_registry_path + kPreReadFieldTrialRegistryKey; | 42 return product_registry_path + kPreReadFieldTrialRegistryKey; |
42 } | 43 } |
43 | 44 |
44 } // namespace | 45 } // namespace |
45 | 46 |
46 void GetPreReadOptions(const base::string16& product_registry_path, | 47 int GetPreReadOptions(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()); | 48 DCHECK(!product_registry_path.empty()); |
52 DCHECK(no_pre_read); | |
53 DCHECK(high_priority); | |
54 DCHECK(only_if_cold); | |
55 DCHECK(prefetch_virtual_memory); | |
56 | 49 |
57 // Open the PreRead field trial's registry key. | 50 // Open the PreRead field trial's registry key. |
58 const base::string16 registry_path = | 51 const base::string16 registry_path = |
59 GetPreReadRegistryPath(product_registry_path); | 52 GetPreReadRegistryPath(product_registry_path); |
60 const base::win::RegKey key(HKEY_CURRENT_USER, registry_path.c_str(), | 53 const base::win::RegKey key(HKEY_CURRENT_USER, registry_path.c_str(), |
61 KEY_QUERY_VALUE); | 54 KEY_QUERY_VALUE); |
62 | 55 |
63 // Set the PreRead field trial's options. | 56 // Set the PreRead field trial's options. |
64 struct VariationMapping { | 57 struct VariationMapping { |
65 const base::char16* name; | 58 const base::char16* name; |
66 bool* variable; | 59 PreReadOptions bit; |
67 } const variations_mappings[] = { | 60 } const variations_mappings[] = { |
68 {kNoPreReadVariationName, no_pre_read}, | 61 {kNoPreReadVariationName, NO_PRE_READ}, |
69 {kHighPriorityVariationName, high_priority}, | 62 {kHighPriorityVariationName, HIGH_PRIORITY}, |
70 {kOnlyIfColdVariationName, only_if_cold}, | 63 {kOnlyIfColdVariationName, ONLY_IF_COLD}, |
71 {kPrefetchVirtualMemoryVariationName, prefetch_virtual_memory}, | 64 {kPrefetchVirtualMemoryVariationName, PREFETCH_VIRTUAL_MEMORY}, |
| 65 {kNoPrefetchArgumentVariationName, NO_PREFETCH_ARGUMENT}, |
72 }; | 66 }; |
73 | 67 |
| 68 int options = 0; |
| 69 |
74 for (const auto& mapping : variations_mappings) { | 70 for (const auto& mapping : variations_mappings) { |
75 // Set the option variable to true if the corresponding value is found in | 71 // Set the option variable to true if the corresponding value is found in |
76 // the registry. Set to false otherwise (default behavior). | 72 // the registry. Set to false otherwise (default behavior). |
77 DWORD value = 0; | 73 DWORD value = 0; |
78 *mapping.variable = key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS; | 74 if (key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS) { |
79 DCHECK(!*mapping.variable || value == 1); | 75 DCHECK(value == 1); |
| 76 options &= mapping.bit; |
| 77 } |
80 } | 78 } |
| 79 |
| 80 return options; |
81 } | 81 } |
82 | 82 |
83 void UpdatePreReadOptions(const base::string16& product_registry_path) { | 83 void UpdatePreReadOptions(const base::string16& product_registry_path) { |
84 DCHECK(!product_registry_path.empty()); | 84 DCHECK(!product_registry_path.empty()); |
85 | 85 |
86 const base::string16 registry_path = | 86 const base::string16 registry_path = |
87 GetPreReadRegistryPath(product_registry_path); | 87 GetPreReadRegistryPath(product_registry_path); |
88 | 88 |
89 // Clear the experiment key. That way, when the trial is shut down, the | 89 // Clear the experiment key. That way, when the trial is shut down, the |
90 // registry will be cleaned automatically. Also, this prevents variation | 90 // registry will be cleaned automatically. Also, this prevents variation |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 base::string16 group; | 137 base::string16 group; |
138 key.ReadValue(L"", &group); | 138 key.ReadValue(L"", &group); |
139 | 139 |
140 if (!group.empty()) { | 140 if (!group.empty()) { |
141 register_synthetic_field_trial.Run(kPreReadSyntheticFieldTrialName, | 141 register_synthetic_field_trial.Run(kPreReadSyntheticFieldTrialName, |
142 base::UTF16ToUTF8(group)); | 142 base::UTF16ToUTF8(group)); |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 } // namespace startup_metric_utils | 146 } // namespace startup_metric_utils |
OLD | NEW |