Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: components/startup_metric_utils/common/pre_read_field_trial_utils_win.cc

Issue 1610733002: Store PreRead options obtained from the registry in a global variable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: don't return a const ref Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/startup_metric_utils/common/pre_read_field_trial_utils_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 PreReadOptions g_pre_read_options = {false, false, false, false};
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);
53 DCHECK(high_priority);
54 DCHECK(only_if_cold);
55 DCHECK(prefetch_virtual_memory);
56 52
57 // Open the PreRead field trial's registry key. 53 // Open the PreRead field trial's registry key.
58 const base::string16 registry_path = 54 const base::string16 registry_path =
59 GetPreReadRegistryPath(product_registry_path); 55 GetPreReadRegistryPath(product_registry_path);
60 const base::win::RegKey key(HKEY_CURRENT_USER, registry_path.c_str(), 56 const base::win::RegKey key(HKEY_CURRENT_USER, registry_path.c_str(),
61 KEY_QUERY_VALUE); 57 KEY_QUERY_VALUE);
62 58
63 // Set the PreRead field trial's options. 59 // Set the PreRead field trial's options.
64 struct VariationMapping { 60 struct {
65 const base::char16* name; 61 const base::char16* name;
66 bool* variable; 62 bool* option;
67 } const variations_mappings[] = { 63 } const variations_mappings[] = {
68 {kNoPreReadVariationName, no_pre_read}, 64 {kNoPreReadVariationName, &g_pre_read_options.no_pre_read},
69 {kHighPriorityVariationName, high_priority}, 65 {kHighPriorityVariationName, &g_pre_read_options.high_priority},
70 {kOnlyIfColdVariationName, only_if_cold}, 66 {kOnlyIfColdVariationName, &g_pre_read_options.only_if_cold},
71 {kPrefetchVirtualMemoryVariationName, prefetch_virtual_memory}, 67 {kPrefetchVirtualMemoryVariationName,
68 &g_pre_read_options.prefetch_virtual_memory},
72 }; 69 };
73 70
74 for (const auto& mapping : variations_mappings) { 71 for (const auto& mapping : variations_mappings) {
75 // Set the option variable to true if the corresponding value is found in 72 // Set the option variable to true if the corresponding value is found in
76 // the registry. Set to false otherwise (default behavior). 73 // the registry. Set to false otherwise (default behavior).
77 DWORD value = 0; 74 DWORD value = 0;
78 *mapping.variable = key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS; 75 if (key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS) {
79 DCHECK(!*mapping.variable || value == 1); 76 DCHECK_EQ(1U, value);
77 DCHECK(!*mapping.option);
78 *mapping.option = true;
79 }
80 } 80 }
81 } 81 }
82 82
83 PreReadOptions GetPreReadOptions() {
84 return g_pre_read_options;
85 }
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 =
87 GetPreReadRegistryPath(product_registry_path); 91 GetPreReadRegistryPath(product_registry_path);
88 92
89 // Clear the experiment key. That way, when the trial is shut down, the 93 // Clear the experiment key. That way, when the trial is shut down, the
90 // registry will be cleaned automatically. Also, this prevents variation 94 // registry will be cleaned automatically. Also, this prevents variation
91 // params from the previous group to stay in the registry when the group is 95 // params from the previous group to stay in the registry when the group is
92 // updated. 96 // updated.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « components/startup_metric_utils/common/pre_read_field_trial_utils_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698