OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <windows.h> | 5 #include <windows.h> |
6 #include <shlwapi.h> | 6 #include <shlwapi.h> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
11 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/rand_util.h" // For PreRead experiment. | |
15 #include "base/sha1.h" // For PreRead experiment. | |
14 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
15 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
18 #include "base/version.h" | 20 #include "base/version.h" |
19 #include "base/win/windows_version.h" | 21 #include "base/win/windows_version.h" |
20 #include "chrome/app/breakpad_win.h" | 22 #include "chrome/app/breakpad_win.h" |
21 #include "chrome/app/client_util.h" | 23 #include "chrome/app/client_util.h" |
22 #include "chrome/app/image_pre_reader_win.h" | 24 #include "chrome/app/image_pre_reader_win.h" |
23 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
24 #include "chrome/common/chrome_result_codes.h" | 26 #include "chrome/common/chrome_result_codes.h" |
25 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/env_vars.h" | 28 #include "chrome/common/env_vars.h" |
27 #include "chrome/installer/util/browser_distribution.h" | 29 #include "chrome/installer/util/browser_distribution.h" |
28 #include "chrome/installer/util/channel_info.h" | 30 #include "chrome/installer/util/channel_info.h" |
29 #include "chrome/installer/util/google_update_constants.h" | 31 #include "chrome/installer/util/google_update_constants.h" |
30 #include "chrome/installer/util/google_update_settings.h" | 32 #include "chrome/installer/util/google_update_settings.h" |
31 #include "chrome/installer/util/install_util.h" | 33 #include "chrome/installer/util/install_util.h" |
32 #include "chrome/installer/util/util_constants.h" | 34 #include "chrome/installer/util/util_constants.h" |
33 | 35 |
34 namespace { | 36 namespace { |
35 // The entry point signature of chrome.dll. | 37 // The entry point signature of chrome.dll. |
36 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); | 38 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); |
37 | 39 |
38 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); | 40 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); |
39 | 41 |
42 // Returns true if the build date for this module precedes the expiry date | |
43 // for the pre-read experiment. | |
44 bool PreReadExperimentIsActive() { | |
45 const int kPreReadExpiryYear = 2014; | |
46 const int kPreReadExpiryMonth = 7; | |
47 const int kPreReadExpiryDay = 1; | |
48 const char kBuildTimeStr[] = __DATE__ " " __TIME__; | |
49 | |
50 // Get the timestamp of the build. | |
51 base::Time build_time; | |
52 bool result = base::Time::FromString(kBuildTimeStr, &build_time); | |
53 DCHECK(result); | |
54 | |
55 // Get the timestamp at which the experiment expires. | |
56 base::Time::Exploded exploded = {0}; | |
57 exploded.year = kPreReadExpiryYear; | |
58 exploded.month = kPreReadExpiryMonth; | |
59 exploded.day_of_month = kPreReadExpiryDay; | |
60 base::Time expiration_time = base::Time::FromLocalExploded(exploded); | |
61 | |
62 // Return true if the build time predates the expiration time.. | |
63 return build_time < expiration_time; | |
64 } | |
65 | |
66 // Get random unit values, i.e., in the range (0, 1), denoting a die-toss for | |
67 // being in an experiment population and experimental group thereof. | |
68 void GetPreReadPopulationAndGroup(double* population, double* group) { | |
69 DCHECK(population != NULL); | |
rvargas (doing something else)
2013/09/05 22:18:48
nit: we usually don't dcheck on required arguments
Roger McFarlane (Chromium)
2013/09/11 20:42:54
Done.
| |
70 DCHECK(group != NULL); | |
71 | |
72 // By default we use the metrics id for the user as stable pseudo-random | |
73 // input to a hash. | |
74 base::string16 metrics_id; | |
75 GoogleUpdateSettings::GetMetricsId(&metrics_id); | |
76 | |
77 // If this user has not metrics id, we fall back to a purely random value | |
78 // per browser session. | |
79 const size_t kLength = 16; | |
80 std::string random_value(metrics_id.empty() ? base::RandBytesAsString(kLength) | |
81 : base::WideToUTF8(metrics_id)); | |
82 | |
83 // To interpret the value as a random number we hash it and read the first 8 | |
84 // bytes of the hash as a unit-interval representing a die-toss for being in | |
85 // the experiment population and the second 8 bytes as a die-toss for being | |
86 // in various experiment groups. | |
87 unsigned char sha1_hash[base::kSHA1Length]; | |
88 base::SHA1HashBytes( | |
89 reinterpret_cast<const unsigned char*>(random_value.c_str()), | |
90 random_value.size() * sizeof(random_value[0]), | |
91 sha1_hash); | |
92 COMPILE_ASSERT(2 * sizeof(uint64) < sizeof(sha1_hash), need_more_data); | |
93 const uint64* random_bits = reinterpret_cast<uint64*>(&sha1_hash[0]); | |
94 | |
95 // Convert the bits into unit-intervals and return. | |
96 *population = base::BitsToOpenEndedUnitInterval(random_bits[0]); | |
97 *group = base::BitsToOpenEndedUnitInterval(random_bits[1]); | |
98 } | |
99 | |
100 // Gets the amount of pre-read to use as well as the experiment group in which | |
101 // the user falls. | |
102 size_t InitPreReadPercentage() { | |
103 // By default use the old behaviour: read 100%. | |
104 const uint8 kDefaultPercentage = 100; | |
rvargas (doing something else)
2013/09/05 22:18:48
nit: being just a number, this should be a plain i
Roger McFarlane (Chromium)
2013/09/11 20:42:54
Done.
| |
105 const char kDefaultFormatStr[] = "%d-pct-default"; | |
106 const char kControlFormatStr[] = "%d-pct-control"; | |
107 const char kGroupFormatStr[] = "%d-pct"; | |
108 | |
109 COMPILE_ASSERT(kDefaultPercentage <= 100, default_percentage_too_large); | |
110 COMPILE_ASSERT(kDefaultPercentage % 5 == 0, default_percentage_not_mult_5); | |
111 | |
112 // Roll the dice to determine if this user is in the experiment and if so, | |
113 // in which experimental group. | |
114 double population = 0.0; | |
115 double group = 0.0; | |
116 GetPreReadPopulationAndGroup(&population, &group); | |
117 | |
118 // We limit experiment populations to 1% of the Stable and 10% of each of | |
rvargas (doing something else)
2013/09/05 22:18:48
nit: indentation
Roger McFarlane (Chromium)
2013/09/11 20:42:54
Done.
| |
119 // the other channels. | |
120 const string16 channel(GoogleUpdateSettings::GetChromeChannel( | |
121 GoogleUpdateSettings::IsSystemInstall())); | |
122 double threshold = (channel == installer::kChromeChannelStable) ? 0.01 : 0.10; | |
123 | |
124 // If the experiment has expired use the default pre-read level. Otherwise, | |
125 // those not in the experiment population also use the default pre-read level. | |
126 size_t value = kDefaultPercentage; | |
127 const char* format_str = kDefaultFormatStr; | |
128 if (PreReadExperimentIsActive() && (population <= threshold)) { | |
129 // We divide the experiment population into groups pre-reading at 5 percent | |
130 // increments. This is 21 groups of 5 -- to include the range [100, 105) -- | |
rvargas (doing something else)
2013/09/05 22:18:48
nit: I think it is more clear if you say that valu
Roger McFarlane (Chromium)
2013/09/11 20:42:54
Done.
| |
131 // rounded down to the nearest 5. | |
132 value = static_cast<size_t>(group * 21.0) * 5; | |
133 DCHECK_LE(value, 100u); | |
134 DCHECK_EQ(0u, value % 5); | |
135 format_str = | |
136 (value == kDefaultPercentage) ? kControlFormatStr : kGroupFormatStr; | |
137 } | |
138 | |
139 // Generate the group name corresponding to this percentage value. | |
140 std::string group_name; | |
141 base::SStringPrintf(&group_name, format_str, value); | |
142 | |
143 // Persiste the group name to the environment so that it can be used for | |
cpu_(ooo_6.6-7.5)
2013/09/05 20:21:16
Persist
Roger McFarlane (Chromium)
2013/09/11 20:42:54
Done.
| |
144 // reporting. | |
145 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
146 env->SetVar(chrome::kPreReadEnvironmentVariable, group_name); | |
147 | |
148 // Return the percentage value to be used. | |
149 return value; | |
150 } | |
151 | |
40 // Expects that |dir| has a trailing backslash. |dir| is modified so it | 152 // Expects that |dir| has a trailing backslash. |dir| is modified so it |
41 // contains the full path that was tried. Caller must check for the return | 153 // contains the full path that was tried. Caller must check for the return |
42 // value not being null to determine if this path contains a valid dll. | 154 // value not being null to determine if this path contains a valid dll. |
43 HMODULE LoadChromeWithDirectory(string16* dir) { | 155 HMODULE LoadChromeWithDirectory(string16* dir) { |
44 ::SetCurrentDirectoryW(dir->c_str()); | 156 ::SetCurrentDirectoryW(dir->c_str()); |
45 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); | 157 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
46 #if !defined(CHROME_MULTIPLE_DLL) | 158 #if !defined(CHROME_MULTIPLE_DLL) |
47 const wchar_t* dll_name = installer::kChromeDll; | 159 const wchar_t* dll_name = installer::kChromeDll; |
48 #else | 160 #else |
49 const wchar_t* dll_name = cmd_line.HasSwitch(switches::kProcessType) ? | 161 const wchar_t* dll_name = cmd_line.HasSwitch(switches::kProcessType) ? |
50 installer::kChromeChildDll : installer::kChromeDll; | 162 installer::kChromeChildDll : installer::kChromeDll; |
51 #endif | 163 #endif |
52 dir->append(dll_name); | 164 dir->append(dll_name); |
53 | 165 |
54 #if !defined(WIN_DISABLE_PREREAD) | 166 #if !defined(WIN_DISABLE_PREREAD) |
55 // On Win7 with Syzygy, pre-read is a win. There've very little difference | 167 // On Win7 with Syzygy, pre-read is a win. There've very little difference |
56 // between 25% and 100%. For cold starts, with or without prefetch 25% | 168 // between 25% and 100%. For cold starts, with or without prefetch 25% |
57 // performs slightly better than 100%. On XP, pre-read is generally a | 169 // performs slightly better than 100%. On XP, pre-read is generally a |
rvargas (doing something else)
2013/09/05 22:18:48
I'm curious as to why it looks like we use preread
Roger McFarlane (Chromium)
2013/09/11 20:42:54
My bad, as a pre-experiment, I reverted the value
| |
58 // performance loss. | 170 // performance loss. |
59 if (!cmd_line.HasSwitch(switches::kProcessType)) { | 171 if (!cmd_line.HasSwitch(switches::kProcessType)) { |
60 const size_t kStepSize = 1024 * 1024; | 172 const size_t kStepSize = 1024 * 1024; |
61 // Pre-read 100% of the binary. This was the fallback behaviour for an | 173 size_t percentage = InitPreReadPercentage(); |
62 // expired pre-read experiment as well as the standard behaviour before | 174 ImagePreReader::PartialPreReadImage(dir->c_str(), percentage, kStepSize); |
63 // the pre-read experiment. Performance regressed when the experiment | |
64 // (and fallback to 100%) was removed. See http://crbug/245435 | |
65 // TODO(rogerm): Revive the pre-read experiment under finch. | |
66 uint8 percent = 100; | |
67 ImagePreReader::PartialPreReadImage(dir->c_str(), percent, kStepSize); | |
68 } | 175 } |
69 #endif | 176 #endif |
70 | 177 |
71 return ::LoadLibraryExW(dir->c_str(), NULL, | 178 return ::LoadLibraryExW(dir->c_str(), NULL, |
72 LOAD_WITH_ALTERED_SEARCH_PATH); | 179 LOAD_WITH_ALTERED_SEARCH_PATH); |
73 } | 180 } |
74 | 181 |
75 void RecordDidRun(const string16& dll_path) { | 182 void RecordDidRun(const string16& dll_path) { |
76 bool system_level = !InstallUtil::IsPerUserInstall(dll_path.c_str()); | 183 bool system_level = !InstallUtil::IsPerUserInstall(dll_path.c_str()); |
77 GoogleUpdateSettings::UpdateDidRunState(true, system_level); | 184 GoogleUpdateSettings::UpdateDidRunState(true, system_level); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 } | 350 } |
244 }; | 351 }; |
245 | 352 |
246 MainDllLoader* MakeMainDllLoader() { | 353 MainDllLoader* MakeMainDllLoader() { |
247 #if defined(GOOGLE_CHROME_BUILD) | 354 #if defined(GOOGLE_CHROME_BUILD) |
248 return new ChromeDllLoader(); | 355 return new ChromeDllLoader(); |
249 #else | 356 #else |
250 return new ChromiumDllLoader(); | 357 return new ChromiumDllLoader(); |
251 #endif | 358 #endif |
252 } | 359 } |
OLD | NEW |