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

Side by Side Diff: chrome/app/chrome_exe_main_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: self-review Created 4 years, 10 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <malloc.h> 6 #include <malloc.h>
7 #include <shellscalingapi.h> 7 #include <shellscalingapi.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <tchar.h> 9 #include <tchar.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <string> 12 #include <string>
13 13
14 #include "base/at_exit.h" 14 #include "base/at_exit.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/time/time.h" 22 #include "base/time/time.h"
22 #include "base/win/windows_version.h" 23 #include "base/win/windows_version.h"
23 #include "chrome/app/chrome_crash_reporter_client.h" 24 #include "chrome/app/chrome_crash_reporter_client.h"
24 #include "chrome/app/main_dll_loader_win.h" 25 #include "chrome/app/main_dll_loader_win.h"
26 #include "chrome/app/prefetch_argument_win.h"
25 #include "chrome/browser/chrome_process_finder_win.h" 27 #include "chrome/browser/chrome_process_finder_win.h"
26 #include "chrome/browser/policy/policy_path_parser.h" 28 #include "chrome/browser/policy/policy_path_parser.h"
27 #include "chrome/common/chrome_paths_internal.h" 29 #include "chrome/common/chrome_paths_internal.h"
28 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/installer/util/browser_distribution.h"
29 #include "chrome_elf/chrome_elf_main.h" 32 #include "chrome_elf/chrome_elf_main.h"
30 #include "components/crash/content/app/crash_reporter_client.h" 33 #include "components/crash/content/app/crash_reporter_client.h"
31 #include "components/crash/content/app/crashpad.h" 34 #include "components/crash/content/app/crashpad.h"
32 #include "components/startup_metric_utils/browser/startup_metric_utils.h" 35 #include "components/startup_metric_utils/browser/startup_metric_utils.h"
36 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win. h"
33 #include "content/public/common/content_switches.h" 37 #include "content/public/common/content_switches.h"
34 #include "content/public/common/result_codes.h" 38 #include "content/public/common/result_codes.h"
35 #include "third_party/crashpad/crashpad/handler/handler_main.h" 39 #include "third_party/crashpad/crashpad/handler/handler_main.h"
36 #include "ui/gfx/win/dpi.h" 40 #include "ui/gfx/win/dpi.h"
37 41
38 namespace { 42 namespace {
39 43
40 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = 44 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client =
41 LAZY_INSTANCE_INITIALIZER; 45 LAZY_INSTANCE_INITIALIZER;
42 46
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 argv.erase(std::remove_if(argv.begin(), argv.end(), 149 argv.erase(std::remove_if(argv.begin(), argv.end(),
146 [&process_type](const base::string16& str) { 150 [&process_type](const base::string16& str) {
147 return str.compare(0, process_type.size(), 151 return str.compare(0, process_type.size(),
148 process_type) == 0; 152 process_type) == 0;
149 }), 153 }),
150 argv.end()); 154 argv.end());
151 155
152 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); 156 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]);
153 std::vector<std::string> storage; 157 std::vector<std::string> storage;
154 storage.reserve(argv.size()); 158 storage.reserve(argv.size());
159
160 size_t arg_append_index = 0;
155 for (size_t i = 0; i < argv.size(); ++i) { 161 for (size_t i = 0; i < argv.size(); ++i) {
162 // Remove the /prefetch:# argument as it is not supported by Crashpad.
163 if (base::StartsWith(argv[i], L"/prefetch:", base::CompareCase::SENSITIVE))
164 continue;
165
156 storage.push_back(base::UTF16ToUTF8(argv[i])); 166 storage.push_back(base::UTF16ToUTF8(argv[i]));
157 argv_as_utf8[i] = &storage[i][0]; 167 argv_as_utf8[arg_append_index] = &storage[arg_append_index][0];
168 ++arg_append_index;
158 } 169 }
159 argv_as_utf8[argv.size()] = nullptr; 170 DCHECK_EQ(storage.size(), arg_append_index);
gab 2016/01/26 21:40:25 Don't think this DCHECK is necessary, it's pretty
fdoray 2016/01/27 20:12:19 Done.
160 return crashpad::HandlerMain(static_cast<int>(argv.size()), 171 argv_as_utf8[arg_append_index] = nullptr;
172
173 return crashpad::HandlerMain(static_cast<int>(storage.size()),
161 argv_as_utf8.get()); 174 argv_as_utf8.get());
162 } 175 }
163 176
164 } // namespace 177 } // namespace
165 178
166 // This helper is looked up in the browser to retrieve the crash reports. See 179 // This helper is looked up in the browser to retrieve the crash reports. See
167 // CrashUploadListCrashpad. Note that we do not pass an std::vector here, 180 // CrashUploadListCrashpad. Note that we do not pass an std::vector here,
168 // because we do not want to allocate/free in different modules. The returned 181 // because we do not want to allocate/free in different modules. The returned
169 // pointer is read-only. 182 // pointer is read-only.
170 extern "C" __declspec(dllexport) void GetUploadedReportsImpl( 183 extern "C" __declspec(dllexport) void GetUploadedReportsImpl(
171 const crash_reporter::UploadedReport** reports, 184 const crash_reporter::UploadedReport** reports,
172 size_t* report_count) { 185 size_t* report_count) {
173 crash_reporter::GetUploadedReports(g_uploaded_reports.Pointer()); 186 crash_reporter::GetUploadedReports(g_uploaded_reports.Pointer());
174 *reports = g_uploaded_reports.Pointer()->data(); 187 *reports = g_uploaded_reports.Pointer()->data();
175 *report_count = g_uploaded_reports.Pointer()->size(); 188 *report_count = g_uploaded_reports.Pointer()->size();
176 } 189 }
177 190
178 #if !defined(WIN_CONSOLE_APP) 191 #if !defined(WIN_CONSOLE_APP)
179 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { 192 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) {
180 #else 193 #else
181 int main() { 194 int main() {
182 HINSTANCE instance = GetModuleHandle(nullptr); 195 HINSTANCE instance = GetModuleHandle(nullptr);
183 #endif 196 #endif
184 // Initialize the CommandLine singleton from the environment. 197 // Initialize the CommandLine singleton from the environment.
185 base::CommandLine::Init(0, nullptr); 198 base::CommandLine::Init(0, nullptr);
199 const base::CommandLine* command_line =
200 base::CommandLine::ForCurrentProcess();
186 201
187 std::string process_type = 202 const std::string process_type =
188 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 203 command_line->GetSwitchValueASCII(switches::kProcessType);
189 switches::kProcessType); 204
205 startup_metric_utils::InitializePreReadOptions(
206 BrowserDistribution::GetDistribution()->GetRegistryPath());
207 DCHECK(!startup_metric_utils::GetPreReadOptions().prefetch_argument ||
gab 2016/01/26 21:40:25 Add a comment about what this DCHECK verifies, e.g
gab 2016/01/26 21:40:25 Reading this here makes me realize that |prefetch_
fdoray 2016/01/27 20:12:19 Done.
fdoray 2016/01/27 20:12:19 Done.
208 (process_type.empty() &&
209 !command_line->HasSwitch(switches::kNoStartupWindow)) ||
gab 2016/01/26 21:40:25 This will DCHECK on any existing install which use
fdoray 2016/01/27 20:12:19 Done. Note: According to my debugging, the backgro
gab 2016/01/29 12:46:25 Hmmm, are you sure this code kicks in on every sta
fdoray 2016/01/29 15:33:30 When I have a background app installed, Background
gab 2016/01/29 19:39:28 Interesting, this is certainly unexpected for me a
210 HasValidWindowsPrefetchArgument(*command_line));
190 211
191 if (process_type == switches::kCrashpadHandler) 212 if (process_type == switches::kCrashpadHandler)
192 return RunAsCrashpadHandler(*base::CommandLine::ForCurrentProcess()); 213 return RunAsCrashpadHandler(*base::CommandLine::ForCurrentProcess());
193 214
194 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); 215 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer());
195 crash_reporter::InitializeCrashpad(process_type.empty(), process_type); 216 crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
196 217
197 SwitchToLFHeap(); 218 SwitchToLFHeap();
198 219
199 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); 220 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now());
200 221
201 // Signal Chrome Elf that Chrome has begun to start. 222 // Signal Chrome Elf that Chrome has begun to start.
202 SignalChromeElf(); 223 SignalChromeElf();
203 224
204 // The exit manager is in charge of calling the dtors of singletons. 225 // The exit manager is in charge of calling the dtors of singletons.
205 base::AtExitManager exit_manager; 226 base::AtExitManager exit_manager;
206 227
207 // We don't want to set DPI awareness on pre-Win7 because we don't support 228 // We don't want to set DPI awareness on pre-Win7 because we don't support
208 // DirectWrite there. GDI fonts are kerned very badly, so better to leave 229 // DirectWrite there. GDI fonts are kerned very badly, so better to leave
209 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). 230 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite().
210 if (base::win::GetVersion() >= base::win::VERSION_WIN7) 231 if (base::win::GetVersion() >= base::win::VERSION_WIN7)
211 EnableHighDPISupport(); 232 EnableHighDPISupport();
212 233
213 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) 234 if (AttemptFastNotify(*command_line))
214 return 0; 235 return 0;
215 236
216 // Load and launch the chrome dll. *Everything* happens inside. 237 // Load and launch the chrome dll. *Everything* happens inside.
217 VLOG(1) << "About to load main DLL."; 238 VLOG(1) << "About to load main DLL.";
218 MainDllLoader* loader = MakeMainDllLoader(); 239 MainDllLoader* loader = MakeMainDllLoader();
219 int rc = loader->Launch(instance); 240 int rc = loader->Launch(instance);
220 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); 241 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded();
221 delete loader; 242 delete loader;
222 return rc; 243 return rc;
223 } 244 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698