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 kPrefetchArgumentVariationName[] = L"PrefetchArgument"; | |
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 void GetPreReadOptions(const base::string16& product_registry_path, |
47 bool* no_pre_read, | 48 bool* no_pre_read, |
48 bool* high_priority, | 49 bool* high_priority, |
49 bool* only_if_cold, | 50 bool* only_if_cold, |
50 bool* prefetch_virtual_memory) { | 51 bool* prefetch_virtual_memory, |
52 bool* prefetch_argument) { | |
51 DCHECK(!product_registry_path.empty()); | 53 DCHECK(!product_registry_path.empty()); |
52 DCHECK(no_pre_read); | 54 DCHECK(no_pre_read); |
53 DCHECK(high_priority); | 55 DCHECK(high_priority); |
54 DCHECK(only_if_cold); | 56 DCHECK(only_if_cold); |
55 DCHECK(prefetch_virtual_memory); | 57 DCHECK(prefetch_virtual_memory); |
58 DCHECK(prefetch_argument); | |
56 | 59 |
57 // Open the PreRead field trial's registry key. | 60 // Open the PreRead field trial's registry key. |
58 const base::string16 registry_path = | 61 const base::string16 registry_path = |
59 GetPreReadRegistryPath(product_registry_path); | 62 GetPreReadRegistryPath(product_registry_path); |
60 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(), |
61 KEY_QUERY_VALUE); | 64 KEY_QUERY_VALUE); |
62 | 65 |
63 // Set the PreRead field trial's options. | 66 // Set the PreRead field trial's options. |
64 struct VariationMapping { | 67 struct VariationMapping { |
65 const base::char16* name; | 68 const base::char16* name; |
66 bool* variable; | 69 bool* variable; |
67 } const variations_mappings[] = { | 70 } const variations_mappings[] = { |
68 {kNoPreReadVariationName, no_pre_read}, | 71 {kNoPreReadVariationName, no_pre_read}, |
69 {kHighPriorityVariationName, high_priority}, | 72 {kHighPriorityVariationName, high_priority}, |
70 {kOnlyIfColdVariationName, only_if_cold}, | 73 {kOnlyIfColdVariationName, only_if_cold}, |
71 {kPrefetchVirtualMemoryVariationName, prefetch_virtual_memory}, | 74 {kPrefetchVirtualMemoryVariationName, prefetch_virtual_memory}, |
75 {kPrefetchArgumentVariationName, prefetch_argument}, | |
gab
2016/01/18 19:10:52
Actually, /prefetch applies only to processes laun
| |
72 }; | 76 }; |
73 | 77 |
74 for (const auto& mapping : variations_mappings) { | 78 for (const auto& mapping : variations_mappings) { |
75 // Set the option variable to true if the corresponding value is found in | 79 // Set the option variable to true if the corresponding value is found in |
76 // the registry. Set to false otherwise (default behavior). | 80 // the registry. Set to false otherwise (default behavior). |
gab
2016/01/18 19:10:52
Would be nice to see /prefetch in action on the wa
| |
77 DWORD value = 0; | 81 DWORD value = 0; |
78 *mapping.variable = key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS; | 82 *mapping.variable = key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS; |
79 DCHECK(!*mapping.variable || value == 1); | 83 DCHECK(!*mapping.variable || value == 1); |
80 } | 84 } |
81 } | 85 } |
82 | 86 |
83 void UpdatePreReadOptions(const base::string16& product_registry_path) { | 87 void UpdatePreReadOptions(const base::string16& product_registry_path) { |
84 DCHECK(!product_registry_path.empty()); | 88 DCHECK(!product_registry_path.empty()); |
85 | 89 |
86 const base::string16 registry_path = | 90 const base::string16 registry_path = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 base::string16 group; | 141 base::string16 group; |
138 key.ReadValue(L"", &group); | 142 key.ReadValue(L"", &group); |
139 | 143 |
140 if (!group.empty()) { | 144 if (!group.empty()) { |
141 register_synthetic_field_trial.Run(kPreReadSyntheticFieldTrialName, | 145 register_synthetic_field_trial.Run(kPreReadSyntheticFieldTrialName, |
142 base::UTF16ToUTF8(group)); | 146 base::UTF16ToUTF8(group)); |
143 } | 147 } |
144 } | 148 } |
145 | 149 |
146 } // namespace startup_metric_utils | 150 } // namespace startup_metric_utils |
OLD | NEW |