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

Side by Side Diff: chrome/app/main_dll_loader_win.cc

Issue 1581473002: Remove base/win/metro.{cc|h} and some associated code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes 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 (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> // NOLINT 5 #include <windows.h> // NOLINT
6 #include <shlwapi.h> // NOLINT 6 #include <shlwapi.h> // NOLINT
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <userenv.h> // NOLINT 8 #include <userenv.h> // NOLINT
9 9
10 #include "chrome/app/main_dll_loader_win.h" 10 #include "chrome/app/main_dll_loader_win.h"
11 11
12 #include "base/base_paths.h" 12 #include "base/base_paths.h"
13 #include "base/base_switches.h" 13 #include "base/base_switches.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/environment.h" 16 #include "base/environment.h"
17 #include "base/files/memory_mapped_file.h" 17 #include "base/files/memory_mapped_file.h"
18 #include "base/lazy_instance.h" 18 #include "base/lazy_instance.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
22 #include "base/path_service.h" 22 #include "base/path_service.h"
23 #include "base/strings/string16.h" 23 #include "base/strings/string16.h"
24 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
25 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
27 #include "base/threading/platform_thread.h" 27 #include "base/threading/platform_thread.h"
28 #include "base/trace_event/trace_event.h" 28 #include "base/trace_event/trace_event.h"
29 #include "base/win/metro.h"
30 #include "base/win/scoped_handle.h" 29 #include "base/win/scoped_handle.h"
31 #include "base/win/windows_version.h" 30 #include "base/win/windows_version.h"
32 #include "chrome/app/chrome_crash_reporter_client.h" 31 #include "chrome/app/chrome_crash_reporter_client.h"
33 #include "chrome/app/chrome_watcher_client_win.h" 32 #include "chrome/app/chrome_watcher_client_win.h"
34 #include "chrome/app/chrome_watcher_command_line_win.h" 33 #include "chrome/app/chrome_watcher_command_line_win.h"
35 #include "chrome/app/file_pre_reader_win.h" 34 #include "chrome/app/file_pre_reader_win.h"
36 #include "chrome/app/kasko_client.h" 35 #include "chrome/app/kasko_client.h"
37 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" 36 #include "chrome/chrome_watcher/chrome_watcher_main_api.h"
38 #include "chrome/common/chrome_constants.h" 37 #include "chrome/common/chrome_constants.h"
39 #include "chrome/common/chrome_paths.h" 38 #include "chrome/common/chrome_paths.h"
(...skipping 14 matching lines...) Expand all
54 #include "sandbox/win/src/sandbox.h" 53 #include "sandbox/win/src/sandbox.h"
55 54
56 namespace { 55 namespace {
57 // The entry point signature of chrome.dll. 56 // The entry point signature of chrome.dll.
58 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); 57 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*);
59 58
60 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); 59 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)();
61 60
62 // Loads |module| after setting the CWD to |module|'s directory. Returns a 61 // Loads |module| after setting the CWD to |module|'s directory. Returns a
63 // reference to the loaded module on success, or null on error. 62 // reference to the loaded module on success, or null on error.
64 HMODULE LoadModuleWithDirectory(const base::FilePath& module, bool pre_read) { 63 HMODULE LoadModuleWithDirectory(const base::FilePath& module) {
65 ::SetCurrentDirectoryW(module.DirName().value().c_str()); 64 ::SetCurrentDirectoryW(module.DirName().value().c_str());
66 65
67 // Get pre-read options from the PreRead field trial. 66 // Get pre-read options from the PreRead field trial.
68 bool trial_no_pre_read = false; 67 bool trial_no_pre_read = false;
69 bool trial_high_priority = false; 68 bool trial_high_priority = false;
70 bool trial_only_if_cold = false; 69 bool trial_only_if_cold = false;
71 bool trial_prefetch_virtual_memory = false; 70 bool trial_prefetch_virtual_memory = false;
72 startup_metric_utils::GetPreReadOptions( 71 startup_metric_utils::GetPreReadOptions(
73 BrowserDistribution::GetDistribution()->GetRegistryPath(), 72 BrowserDistribution::GetDistribution()->GetRegistryPath(),
74 &trial_no_pre_read, &trial_high_priority, &trial_only_if_cold, 73 &trial_no_pre_read, &trial_high_priority, &trial_only_if_cold,
75 &trial_prefetch_virtual_memory); 74 &trial_prefetch_virtual_memory);
76 75
77 // Pre-read the binary to warm the memory caches (avoids a lot of random IO). 76 // Pre-read the binary to warm the memory caches (avoids a lot of random IO).
78 if (pre_read && !trial_no_pre_read) { 77 if (!trial_no_pre_read) {
79 base::ThreadPriority previous_priority = base::ThreadPriority::NORMAL; 78 base::ThreadPriority previous_priority = base::ThreadPriority::NORMAL;
80 if (trial_high_priority) { 79 if (trial_high_priority) {
81 previous_priority = base::PlatformThread::GetCurrentThreadPriority(); 80 previous_priority = base::PlatformThread::GetCurrentThreadPriority();
82 base::PlatformThread::SetCurrentThreadPriority( 81 base::PlatformThread::SetCurrentThreadPriority(
83 base::ThreadPriority::DISPLAY); 82 base::ThreadPriority::DISPLAY);
84 } 83 }
85 84
86 if (trial_only_if_cold) { 85 if (trial_only_if_cold) {
87 base::MemoryMappedFile module_memory_map; 86 base::MemoryMappedFile module_memory_map;
88 const bool map_initialize_success = module_memory_map.Initialize(module); 87 const bool map_initialize_success = module_memory_map.Initialize(module);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return profile_type; 158 return profile_type;
160 } 159 }
161 160
162 #endif // BUILDFLAG(ENABLE_KASKO) 161 #endif // BUILDFLAG(ENABLE_KASKO)
163 162
164 } // namespace 163 } // namespace
165 164
166 //============================================================================= 165 //=============================================================================
167 166
168 MainDllLoader::MainDllLoader() 167 MainDllLoader::MainDllLoader()
169 : dll_(nullptr), metro_mode_(base::win::IsMetroProcess()) { 168 : dll_(nullptr) {
170 } 169 }
171 170
172 MainDllLoader::~MainDllLoader() { 171 MainDllLoader::~MainDllLoader() {
173 } 172 }
174 173
175 // Loading chrome is an interesting affair. First we try loading from the 174 // Loading chrome is an interesting affair. First we try loading from the
176 // current directory to support run-what-you-compile and other development 175 // current directory to support run-what-you-compile and other development
177 // scenarios. 176 // scenarios.
178 // If that fails then we look at the version resource in the current 177 // If that fails then we look at the version resource in the current
179 // module. This is the expected path for chrome.exe browser instances in an 178 // module. This is the expected path for chrome.exe browser instances in an
180 // installed build. 179 // installed build.
181 HMODULE MainDllLoader::Load(base::string16* version, base::FilePath* module) { 180 HMODULE MainDllLoader::Load(base::string16* version, base::FilePath* module) {
182 const base::char16* dll_name = nullptr; 181 const base::char16* dll_name = nullptr;
183 if (metro_mode_) { 182 if (process_type_ == "service" || process_type_.empty()) {
184 dll_name = installer::kChromeMetroDll;
185 } else if (process_type_ == "service" || process_type_.empty()) {
186 dll_name = installer::kChromeDll; 183 dll_name = installer::kChromeDll;
187 } else if (process_type_ == "watcher") { 184 } else if (process_type_ == "watcher") {
188 dll_name = kChromeWatcherDll; 185 dll_name = kChromeWatcherDll;
189 } else { 186 } else {
190 #if defined(CHROME_MULTIPLE_DLL) 187 #if defined(CHROME_MULTIPLE_DLL)
191 dll_name = installer::kChromeChildDll; 188 dll_name = installer::kChromeChildDll;
192 #else 189 #else
193 dll_name = installer::kChromeDll; 190 dll_name = installer::kChromeDll;
194 #endif 191 #endif
195 } 192 }
196 193
197 *module = installer::GetModulePath(dll_name, version); 194 *module = installer::GetModulePath(dll_name, version);
198 if (module->empty()) { 195 if (module->empty()) {
199 PLOG(ERROR) << "Cannot find module " << dll_name; 196 PLOG(ERROR) << "Cannot find module " << dll_name;
200 return nullptr; 197 return nullptr;
201 } 198 }
202 const bool pre_read = !metro_mode_; 199 HMODULE dll = LoadModuleWithDirectory(*module);
203 HMODULE dll = LoadModuleWithDirectory(*module, pre_read);
204 if (!dll) { 200 if (!dll) {
205 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value(); 201 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value();
206 return nullptr; 202 return nullptr;
207 } 203 }
208 204
209 DCHECK(dll); 205 DCHECK(dll);
210 return dll; 206 return dll;
211 } 207 }
212 208
213 // Launching is a matter of loading the right dll, setting the CHROME_VERSION 209 // Launching is a matter of loading the right dll, setting the CHROME_VERSION
214 // environment variable and just calling the entry point. Derived classes can 210 // environment variable and just calling the entry point. Derived classes can
215 // add custom code in the OnBeforeLaunch callback. 211 // add custom code in the OnBeforeLaunch callback.
216 int MainDllLoader::Launch(HINSTANCE instance) { 212 int MainDllLoader::Launch(HINSTANCE instance) {
217 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess(); 213 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess();
218 process_type_ = cmd_line.GetSwitchValueASCII(switches::kProcessType); 214 process_type_ = cmd_line.GetSwitchValueASCII(switches::kProcessType);
219 215
220 base::string16 version; 216 base::string16 version;
221 base::FilePath file; 217 base::FilePath file;
222 218
223 if (metro_mode_) {
224 HMODULE metro_dll = Load(&version, &file);
225 if (!metro_dll)
226 return chrome::RESULT_CODE_MISSING_DATA;
227
228 InitMetro chrome_metro_main =
229 reinterpret_cast<InitMetro>(::GetProcAddress(metro_dll, "InitMetro"));
230 return chrome_metro_main();
231 }
232
233 if (process_type_ == "watcher") { 219 if (process_type_ == "watcher") {
234 chrome::RegisterPathProvider(); 220 chrome::RegisterPathProvider();
235 221
236 base::win::ScopedHandle parent_process; 222 base::win::ScopedHandle parent_process;
237 base::win::ScopedHandle on_initialized_event; 223 base::win::ScopedHandle on_initialized_event;
238 DWORD main_thread_id = 0; 224 DWORD main_thread_id = 0;
239 if (!InterpretChromeWatcherCommandLine(cmd_line, &parent_process, 225 if (!InterpretChromeWatcherCommandLine(cmd_line, &parent_process,
240 &main_thread_id, 226 &main_thread_id,
241 &on_initialized_event)) { 227 &on_initialized_event)) {
242 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; 228 return chrome::RESULT_CODE_UNSUPPORTED_PARAM;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 390 }
405 }; 391 };
406 392
407 MainDllLoader* MakeMainDllLoader() { 393 MainDllLoader* MakeMainDllLoader() {
408 #if defined(GOOGLE_CHROME_BUILD) 394 #if defined(GOOGLE_CHROME_BUILD)
409 return new ChromeDllLoader(); 395 return new ChromeDllLoader();
410 #else 396 #else
411 return new ChromiumDllLoader(); 397 return new ChromiumDllLoader();
412 #endif 398 #endif
413 } 399 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698