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> // 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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, true); |
sky
2016/01/12 03:40:51
Looks like this is the only caller of LoadModuleWi
scottmg
2016/01/12 18:24:16
Done.
| |
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 Loading... | |
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 } |
OLD | NEW |