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

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

Issue 2345933002: Break chrome_initial's dependence on //components/startup_metric_utils/browser:lib (Closed)
Patch Set: fdoray feedback Created 4 years, 3 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 "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"
(...skipping 21 matching lines...) Expand all
41 #include "chrome/installer/util/google_update_settings.h" 42 #include "chrome/installer/util/google_update_settings.h"
42 #include "chrome/installer/util/install_util.h" 43 #include "chrome/installer/util/install_util.h"
43 #include "chrome/installer/util/module_util_win.h" 44 #include "chrome/installer/util/module_util_win.h"
44 #include "chrome/installer/util/util_constants.h" 45 #include "chrome/installer/util/util_constants.h"
45 #include "content/public/app/sandbox_helper_win.h" 46 #include "content/public/app/sandbox_helper_win.h"
46 #include "content/public/common/content_switches.h" 47 #include "content/public/common/content_switches.h"
47 #include "sandbox/win/src/sandbox.h" 48 #include "sandbox/win/src/sandbox.h"
48 49
49 namespace { 50 namespace {
50 // The entry point signature of chrome.dll. 51 // The entry point signature of chrome.dll.
51 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); 52 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, int64_t);
52 53
53 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); 54 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)();
54 55
55 // Loads |module| after setting the CWD to |module|'s directory. Returns a 56 // Loads |module| after setting the CWD to |module|'s directory. Returns a
56 // reference to the loaded module on success, or null on error. 57 // reference to the loaded module on success, or null on error.
57 HMODULE LoadModuleWithDirectory(const base::FilePath& module) { 58 HMODULE LoadModuleWithDirectory(const base::FilePath& module) {
58 ::SetCurrentDirectoryW(module.DirName().value().c_str()); 59 ::SetCurrentDirectoryW(module.DirName().value().c_str());
59 PreReadFile(module); 60 PreReadFile(module);
60 return ::LoadLibraryExW(module.value().c_str(), nullptr, 61 return ::LoadLibraryExW(module.value().c_str(), nullptr,
61 LOAD_WITH_ALTERED_SEARCH_PATH); 62 LOAD_WITH_ALTERED_SEARCH_PATH);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value(); 109 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value();
109 return nullptr; 110 return nullptr;
110 } 111 }
111 112
112 DCHECK(dll); 113 DCHECK(dll);
113 return dll; 114 return dll;
114 } 115 }
115 116
116 // Launching is a matter of loading the right dll and calling the entry point. 117 // 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. 118 // Derived classes can add custom code in the OnBeforeLaunch callback.
118 int MainDllLoader::Launch(HINSTANCE instance) { 119 int MainDllLoader::Launch(HINSTANCE instance,
120 base::TimeTicks exe_entry_point_ticks) {
119 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess(); 121 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess();
120 process_type_ = cmd_line.GetSwitchValueASCII(switches::kProcessType); 122 process_type_ = cmd_line.GetSwitchValueASCII(switches::kProcessType);
121 123
122 base::FilePath file; 124 base::FilePath file;
123 125
124 if (process_type_ == switches::kWatcherProcess) { 126 if (process_type_ == switches::kWatcherProcess) {
125 chrome::RegisterPathProvider(); 127 chrome::RegisterPathProvider();
126 128
127 base::win::ScopedHandle parent_process; 129 base::win::ScopedHandle parent_process;
128 base::win::ScopedHandle on_initialized_event; 130 base::win::ScopedHandle on_initialized_event;
(...skipping 29 matching lines...) Expand all
158 sandbox::SandboxInterfaceInfo sandbox_info = {0}; 160 sandbox::SandboxInterfaceInfo sandbox_info = {0};
159 content::InitializeSandboxInfo(&sandbox_info); 161 content::InitializeSandboxInfo(&sandbox_info);
160 162
161 dll_ = Load(&file); 163 dll_ = Load(&file);
162 if (!dll_) 164 if (!dll_)
163 return chrome::RESULT_CODE_MISSING_DATA; 165 return chrome::RESULT_CODE_MISSING_DATA;
164 166
165 OnBeforeLaunch(process_type_, file); 167 OnBeforeLaunch(process_type_, file);
166 DLL_MAIN chrome_main = 168 DLL_MAIN chrome_main =
167 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); 169 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain"));
168 int rc = chrome_main(instance, &sandbox_info); 170 int rc = chrome_main(instance, &sandbox_info,
171 exe_entry_point_ticks.ToInternalValue());
169 rc = OnBeforeExit(rc, file); 172 rc = OnBeforeExit(rc, file);
170 return rc; 173 return rc;
171 } 174 }
172 175
173 void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { 176 void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
174 if (!dll_) 177 if (!dll_)
175 return; 178 return;
176 179
177 RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function = 180 RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function =
178 reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>( 181 reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 249 }
247 }; 250 };
248 251
249 MainDllLoader* MakeMainDllLoader() { 252 MainDllLoader* MakeMainDllLoader() {
250 #if defined(GOOGLE_CHROME_BUILD) 253 #if defined(GOOGLE_CHROME_BUILD)
251 return new ChromeDllLoader(); 254 return new ChromeDllLoader();
252 #else 255 #else
253 return new ChromiumDllLoader(); 256 return new ChromiumDllLoader();
254 #endif 257 #endif
255 } 258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698