Chromium Code Reviews| 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 "chrome/app/main_dll_loader_win.h" | 5 #include "chrome/app/main_dll_loader_win.h" |
| 6 | 6 |
| 7 #include <windows.h> // NOLINT | 7 #include <windows.h> // NOLINT |
| 8 #include <shlwapi.h> // NOLINT | 8 #include <shlwapi.h> // NOLINT |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | |
| 10 #include <userenv.h> // NOLINT | 11 #include <userenv.h> // NOLINT |
| 11 | 12 |
| 12 #include <memory> | 13 #include <memory> |
| 13 | 14 |
| 14 #include "base/base_paths.h" | 15 #include "base/base_paths.h" |
| 15 #include "base/base_switches.h" | 16 #include "base/base_switches.h" |
| 16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 17 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 18 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 19 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
| 20 #include "base/logging.h" | 21 #include "base/logging.h" |
| 21 #include "base/macros.h" | 22 #include "base/macros.h" |
| 22 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 23 #include "base/strings/string16.h" | 24 #include "base/strings/string16.h" |
| 24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 25 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 28 #include "base/time/time.h" | |
| 27 #include "base/trace_event/trace_event.h" | 29 #include "base/trace_event/trace_event.h" |
| 28 #include "base/win/scoped_handle.h" | 30 #include "base/win/scoped_handle.h" |
| 29 #include "base/win/windows_version.h" | 31 #include "base/win/windows_version.h" |
| 30 #include "chrome/app/chrome_crash_reporter_client_win.h" | 32 #include "chrome/app/chrome_crash_reporter_client_win.h" |
| 31 #include "chrome/app/chrome_watcher_client_win.h" | 33 #include "chrome/app/chrome_watcher_client_win.h" |
| 32 #include "chrome/app/chrome_watcher_command_line_win.h" | 34 #include "chrome/app/chrome_watcher_command_line_win.h" |
| 33 #include "chrome/app/file_pre_reader_win.h" | 35 #include "chrome/app/file_pre_reader_win.h" |
| 34 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" | 36 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" |
| 35 #include "chrome/common/chrome_constants.h" | 37 #include "chrome/common/chrome_constants.h" |
| 36 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
| 37 #include "chrome/common/chrome_result_codes.h" | 39 #include "chrome/common/chrome_result_codes.h" |
| 38 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
| 39 #include "chrome/common/metrics_constants_util_win.h" | 41 #include "chrome/common/metrics_constants_util_win.h" |
| 40 #include "chrome/installer/util/google_update_constants.h" | 42 #include "chrome/installer/util/google_update_constants.h" |
| 41 #include "chrome/installer/util/google_update_settings.h" | 43 #include "chrome/installer/util/google_update_settings.h" |
| 42 #include "chrome/installer/util/install_util.h" | 44 #include "chrome/installer/util/install_util.h" |
| 43 #include "chrome/installer/util/module_util_win.h" | 45 #include "chrome/installer/util/module_util_win.h" |
| 44 #include "chrome/installer/util/util_constants.h" | 46 #include "chrome/installer/util/util_constants.h" |
| 45 #include "content/public/app/sandbox_helper_win.h" | 47 #include "content/public/app/sandbox_helper_win.h" |
| 46 #include "content/public/common/content_switches.h" | 48 #include "content/public/common/content_switches.h" |
| 47 #include "sandbox/win/src/sandbox.h" | 49 #include "sandbox/win/src/sandbox.h" |
| 48 | 50 |
| 49 namespace { | 51 namespace { |
| 50 // The entry point signature of chrome.dll. | 52 // The entry point signature of chrome.dll. |
| 51 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); | 53 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, int64_t); |
|
fdoray
2016/09/19 17:03:28
base::TimeTicks?
grt (UTC plus 2)
2016/09/19 19:52:46
See comment in chrome_main.cc.
| |
| 52 | 54 |
| 53 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); | 55 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); |
| 54 | 56 |
| 55 // Loads |module| after setting the CWD to |module|'s directory. Returns a | 57 // Loads |module| after setting the CWD to |module|'s directory. Returns a |
| 56 // reference to the loaded module on success, or null on error. | 58 // reference to the loaded module on success, or null on error. |
| 57 HMODULE LoadModuleWithDirectory(const base::FilePath& module) { | 59 HMODULE LoadModuleWithDirectory(const base::FilePath& module) { |
| 58 ::SetCurrentDirectoryW(module.DirName().value().c_str()); | 60 ::SetCurrentDirectoryW(module.DirName().value().c_str()); |
| 59 PreReadFile(module); | 61 PreReadFile(module); |
| 60 return ::LoadLibraryExW(module.value().c_str(), nullptr, | 62 return ::LoadLibraryExW(module.value().c_str(), nullptr, |
| 61 LOAD_WITH_ALTERED_SEARCH_PATH); | 63 LOAD_WITH_ALTERED_SEARCH_PATH); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value(); | 110 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value(); |
| 109 return nullptr; | 111 return nullptr; |
| 110 } | 112 } |
| 111 | 113 |
| 112 DCHECK(dll); | 114 DCHECK(dll); |
| 113 return dll; | 115 return dll; |
| 114 } | 116 } |
| 115 | 117 |
| 116 // Launching is a matter of loading the right dll and calling the entry point. | 118 // Launching is a matter of loading the right dll and calling the entry point. |
| 117 // Derived classes can add custom code in the OnBeforeLaunch callback. | 119 // Derived classes can add custom code in the OnBeforeLaunch callback. |
| 118 int MainDllLoader::Launch(HINSTANCE instance) { | 120 int MainDllLoader::Launch(HINSTANCE instance, |
| 121 const base::TimeTicks& exe_entry_point_ticks) { | |
| 119 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess(); | 122 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess(); |
| 120 process_type_ = cmd_line.GetSwitchValueASCII(switches::kProcessType); | 123 process_type_ = cmd_line.GetSwitchValueASCII(switches::kProcessType); |
| 121 | 124 |
| 122 base::FilePath file; | 125 base::FilePath file; |
| 123 | 126 |
| 124 if (process_type_ == switches::kWatcherProcess) { | 127 if (process_type_ == switches::kWatcherProcess) { |
| 125 chrome::RegisterPathProvider(); | 128 chrome::RegisterPathProvider(); |
| 126 | 129 |
| 127 base::win::ScopedHandle parent_process; | 130 base::win::ScopedHandle parent_process; |
| 128 base::win::ScopedHandle on_initialized_event; | 131 base::win::ScopedHandle on_initialized_event; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 158 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 161 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
| 159 content::InitializeSandboxInfo(&sandbox_info); | 162 content::InitializeSandboxInfo(&sandbox_info); |
| 160 | 163 |
| 161 dll_ = Load(&file); | 164 dll_ = Load(&file); |
| 162 if (!dll_) | 165 if (!dll_) |
| 163 return chrome::RESULT_CODE_MISSING_DATA; | 166 return chrome::RESULT_CODE_MISSING_DATA; |
| 164 | 167 |
| 165 OnBeforeLaunch(process_type_, file); | 168 OnBeforeLaunch(process_type_, file); |
| 166 DLL_MAIN chrome_main = | 169 DLL_MAIN chrome_main = |
| 167 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); | 170 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); |
| 168 int rc = chrome_main(instance, &sandbox_info); | 171 int rc = chrome_main(instance, &sandbox_info, |
| 172 exe_entry_point_ticks.ToInternalValue()); | |
| 169 rc = OnBeforeExit(rc, file); | 173 rc = OnBeforeExit(rc, file); |
| 170 return rc; | 174 return rc; |
| 171 } | 175 } |
| 172 | 176 |
| 173 void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { | 177 void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { |
| 174 if (!dll_) | 178 if (!dll_) |
| 175 return; | 179 return; |
| 176 | 180 |
| 177 RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function = | 181 RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function = |
| 178 reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>( | 182 reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 } | 250 } |
| 247 }; | 251 }; |
| 248 | 252 |
| 249 MainDllLoader* MakeMainDllLoader() { | 253 MainDllLoader* MakeMainDllLoader() { |
| 250 #if defined(GOOGLE_CHROME_BUILD) | 254 #if defined(GOOGLE_CHROME_BUILD) |
| 251 return new ChromeDllLoader(); | 255 return new ChromeDllLoader(); |
| 252 #else | 256 #else |
| 253 return new ChromiumDllLoader(); | 257 return new ChromiumDllLoader(); |
| 254 #endif | 258 #endif |
| 255 } | 259 } |
| OLD | NEW |