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

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

Issue 1612663002: Use a valid /prefetch argument when launching a process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bit
Patch Set: address comments from gab #10 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
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"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/win/registry.h" 12 #include "base/win/registry.h"
13 #include "components/variations/variations_associated_data.h" 13 #include "components/variations/variations_associated_data.h"
14 14
15 namespace startup_metric_utils { 15 namespace startup_metric_utils {
16 16
17 namespace { 17 namespace {
18 18
19 // Name of the pre-read field trial. This name is used to get the pre-read group 19 // Name of the pre-read field trial. This name is used to get the pre-read group
20 // to use for the next startup from base::FieldTrialList. 20 // to use for the next startup from base::FieldTrialList.
21 const char kPreReadFieldTrialName[] = "PreRead"; 21 const char kPreReadFieldTrialName[] = "PreRead";
22 22
23 // Name of the synthetic pre-read field trial. A synthetic field trial is 23 // Name of the synthetic pre-read field trial. A synthetic field trial is
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. All variations change the
29 // default behavior, i.e. the default is the inverse of the variation. Thus,
30 // variations that cancel something that is done by default have a negative
31 // name.
29 const base::char16 kNoPreReadVariationName[] = L"NoPreRead"; 32 const base::char16 kNoPreReadVariationName[] = L"NoPreRead";
30 const base::char16 kHighPriorityVariationName[] = L"HighPriority"; 33 const base::char16 kHighPriorityVariationName[] = L"HighPriority";
31 const base::char16 kOnlyIfColdVariationName[] = L"OnlyIfCold"; 34 const base::char16 kOnlyIfColdVariationName[] = L"OnlyIfCold";
32 const base::char16 kPrefetchVirtualMemoryVariationName[] = 35 const base::char16 kPrefetchVirtualMemoryVariationName[] =
33 L"PrefetchVirtualMemory"; 36 L"PrefetchVirtualMemory";
37 const base::char16 kNoPrefetchArgumentVariationName[] = L"NoPrefetchArgument";
34 38
35 // Registry key in which the PreRead field trial group is stored. 39 // Registry key in which the PreRead field trial group is stored.
36 const base::char16 kPreReadFieldTrialRegistryKey[] = L"\\PreReadFieldTrial"; 40 const base::char16 kPreReadFieldTrialRegistryKey[] = L"\\PreReadFieldTrial";
37 41
38 // Pre-read options to use for the current process. This is initialized by 42 // Pre-read options to use for the current process. This is initialized by
39 // InitializePreReadOptions(). 43 // InitializePreReadOptions().
40 PreReadOptions g_pre_read_options = {false, false, false, false}; 44 PreReadOptions g_pre_read_options = {false, false, false, false};
41 45
42 // Returns the registry path in which the PreRead group is stored. 46 // Returns the registry path in which the PreRead group is stored.
43 base::string16 GetPreReadRegistryPath( 47 base::string16 GetPreReadRegistryPath(
44 const base::string16& product_registry_path) { 48 const base::string16& product_registry_path) {
45 return product_registry_path + kPreReadFieldTrialRegistryKey; 49 return product_registry_path + kPreReadFieldTrialRegistryKey;
46 } 50 }
47 51
52 // Returns true if |key| has a value named |name| which is not zero.
53 bool ReadBool(const base::win::RegKey& key, const base::char16* name) {
54 DWORD value = 0;
55 return key.ReadValueDW(name, &value) == ERROR_SUCCESS && value != 0;
56 }
57
48 } // namespace 58 } // namespace
49 59
50 void InitializePreReadOptions(const base::string16& product_registry_path) { 60 void InitializePreReadOptions(const base::string16& product_registry_path) {
51 DCHECK(!product_registry_path.empty()); 61 DCHECK(!product_registry_path.empty());
52 62
53 // Open the PreRead field trial's registry key. 63 // Open the PreRead field trial's registry key.
54 const base::string16 registry_path = 64 const base::string16 registry_path =
55 GetPreReadRegistryPath(product_registry_path); 65 GetPreReadRegistryPath(product_registry_path);
56 const base::win::RegKey key(HKEY_CURRENT_USER, registry_path.c_str(), 66 const base::win::RegKey key(HKEY_CURRENT_USER, registry_path.c_str(),
57 KEY_QUERY_VALUE); 67 KEY_QUERY_VALUE);
58 68
59 // Set the PreRead field trial's options. 69 // Set the PreRead field trial's options.
60 struct { 70 g_pre_read_options.pre_read = !ReadBool(key, kNoPreReadVariationName);
61 const base::char16* name; 71 g_pre_read_options.high_priority = ReadBool(key, kHighPriorityVariationName);
62 bool* option; 72 g_pre_read_options.only_if_cold = ReadBool(key, kOnlyIfColdVariationName);
63 } const variations_mappings[] = { 73 g_pre_read_options.prefetch_virtual_memory =
64 {kNoPreReadVariationName, &g_pre_read_options.no_pre_read}, 74 ReadBool(key, kPrefetchVirtualMemoryVariationName);
65 {kHighPriorityVariationName, &g_pre_read_options.high_priority}, 75 g_pre_read_options.use_prefetch_argument =
66 {kOnlyIfColdVariationName, &g_pre_read_options.only_if_cold}, 76 !ReadBool(key, kNoPrefetchArgumentVariationName);
67 {kPrefetchVirtualMemoryVariationName,
68 &g_pre_read_options.prefetch_virtual_memory},
69 };
70
71 for (const auto& mapping : variations_mappings) {
72 // Set the option variable to true if the corresponding value is found in
73 // the registry. Set to false otherwise (default behavior).
74 DWORD value = 0;
75 if (key.ReadValueDW(mapping.name, &value) == ERROR_SUCCESS) {
76 DCHECK_EQ(1U, value);
77 DCHECK(!*mapping.option);
78 *mapping.option = true;
79 }
80 }
81 } 77 }
82 78
83 PreReadOptions GetPreReadOptions() { 79 PreReadOptions GetPreReadOptions() {
84 return g_pre_read_options; 80 return g_pre_read_options;
85 } 81 }
86 82
87 void UpdatePreReadOptions(const base::string16& product_registry_path) { 83 void UpdatePreReadOptions(const base::string16& product_registry_path) {
88 DCHECK(!product_registry_path.empty()); 84 DCHECK(!product_registry_path.empty());
89 85
90 const base::string16 registry_path = 86 const base::string16 registry_path =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 base::string16 group; 137 base::string16 group;
142 key.ReadValue(L"", &group); 138 key.ReadValue(L"", &group);
143 139
144 if (!group.empty()) { 140 if (!group.empty()) {
145 register_synthetic_field_trial.Run(kPreReadSyntheticFieldTrialName, 141 register_synthetic_field_trial.Run(kPreReadSyntheticFieldTrialName,
146 base::UTF16ToUTF8(group)); 142 base::UTF16ToUTF8(group));
147 } 143 }
148 } 144 }
149 145
150 } // namespace startup_metric_utils 146 } // namespace startup_metric_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698