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

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

Issue 717223002: Browser watcher end-end-to-end . (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/lkgr
Patch Set: Address Erik's comments. Created 6 years, 1 month 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
« no previous file with comments | « chrome/app/client_util.h ('k') | chrome/browser/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> 5 #include <windows.h>
6 #include <shlwapi.h> 6 #include <shlwapi.h>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/environment.h" 11 #include "base/environment.h"
12 #include "base/file_version_info.h" 12 #include "base/file_version_info.h"
13 #include "base/files/file_path.h"
13 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/process/launch.h"
16 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
17 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
20 #include "base/version.h" 22 #include "base/version.h"
23 #include "base/win/scoped_process_information.h"
24 #include "base/win/startup_information.h"
21 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
22 #include "chrome/app/chrome_crash_reporter_client.h" 26 #include "chrome/app/chrome_crash_reporter_client.h"
23 #include "chrome/app/client_util.h" 27 #include "chrome/app/client_util.h"
24 #include "chrome/app/image_pre_reader_win.h" 28 #include "chrome/app/image_pre_reader_win.h"
25 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
26 #include "chrome/common/chrome_result_codes.h" 30 #include "chrome/common/chrome_result_codes.h"
27 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/env_vars.h" 32 #include "chrome/common/env_vars.h"
29 #include "chrome/installer/util/google_update_constants.h" 33 #include "chrome/installer/util/google_update_constants.h"
30 #include "chrome/installer/util/google_update_settings.h" 34 #include "chrome/installer/util/google_update_settings.h"
31 #include "chrome/installer/util/install_util.h" 35 #include "chrome/installer/util/install_util.h"
32 #include "chrome/installer/util/util_constants.h" 36 #include "chrome/installer/util/util_constants.h"
37 #include "components/browser_watcher/watcher_client_win.h"
38 #include "components/browser_watcher/watcher_main_api_win.h"
33 #include "components/crash/app/breakpad_win.h" 39 #include "components/crash/app/breakpad_win.h"
34 #include "components/crash/app/crash_reporter_client.h" 40 #include "components/crash/app/crash_reporter_client.h"
35 #include "components/metrics/client_info.h" 41 #include "components/metrics/client_info.h"
36 #include "content/public/app/startup_helper_win.h" 42 #include "content/public/app/startup_helper_win.h"
37 #include "sandbox/win/src/sandbox.h" 43 #include "sandbox/win/src/sandbox.h"
38 44
39 namespace { 45 namespace {
40 // The entry point signature of chrome.dll. 46 // The entry point signature of chrome.dll.
41 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); 47 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*);
42 48
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // current directory to support run-what-you-compile and other development 124 // current directory to support run-what-you-compile and other development
119 // scenarios. 125 // scenarios.
120 // If that fails then we look at the version resource in the current 126 // If that fails then we look at the version resource in the current
121 // module. This is the expected path for chrome.exe browser instances in an 127 // module. This is the expected path for chrome.exe browser instances in an
122 // installed build. 128 // installed build.
123 HMODULE MainDllLoader::Load(base::string16* version, 129 HMODULE MainDllLoader::Load(base::string16* version,
124 base::string16* out_file) { 130 base::string16* out_file) {
125 const base::string16 executable_dir(GetExecutablePath()); 131 const base::string16 executable_dir(GetExecutablePath());
126 *out_file = executable_dir; 132 *out_file = executable_dir;
127 133
128 const wchar_t* dll_name = metro_mode_ ? 134 const wchar_t* dll_name = NULL;
129 installer::kChromeMetroDll : 135 if (metro_mode_)
130 #if !defined(CHROME_MULTIPLE_DLL) 136 dll_name = installer::kChromeMetroDll;
131 installer::kChromeDll; 137
138 if (process_type_ == "service" || process_type_.empty()) {
139 dll_name = installer::kChromeDll;
140 } else if (process_type_ == "watcher") {
141 dll_name = browser_watcher::kWatcherDll;
142 } else {
143 #if defined(CHROME_MULTIPLE_DLL)
144 dll_name = installer::kChromeChildDll;
132 #else 145 #else
133 (process_type_ == "service") || process_type_.empty() ? 146 dll_name = installer::kChromeDll;
134 installer::kChromeDll :
135 installer::kChromeChildDll;
136 #endif 147 #endif
148 }
149
137 const bool pre_read = !metro_mode_; 150 const bool pre_read = !metro_mode_;
138 HMODULE dll = LoadModuleWithDirectory(out_file, dll_name, pre_read); 151 HMODULE dll = LoadModuleWithDirectory(out_file, dll_name, pre_read);
139 if (!dll) { 152 if (!dll) {
140 base::string16 version_string(GetCurrentModuleVersion()); 153 base::string16 version_string(GetCurrentModuleVersion());
141 if (version_string.empty()) { 154 if (version_string.empty()) {
142 LOG(ERROR) << "No valid Chrome version found"; 155 LOG(ERROR) << "No valid Chrome version found";
143 return NULL; 156 return NULL;
144 } 157 }
145 *out_file = executable_dir; 158 *out_file = executable_dir;
146 *version = version_string; 159 *version = version_string;
(...skipping 22 matching lines...) Expand all
169 if (metro_mode_) { 182 if (metro_mode_) {
170 HMODULE metro_dll = Load(&version, &file); 183 HMODULE metro_dll = Load(&version, &file);
171 if (!metro_dll) 184 if (!metro_dll)
172 return chrome::RESULT_CODE_MISSING_DATA; 185 return chrome::RESULT_CODE_MISSING_DATA;
173 186
174 InitMetro chrome_metro_main = 187 InitMetro chrome_metro_main =
175 reinterpret_cast<InitMetro>(::GetProcAddress(metro_dll, "InitMetro")); 188 reinterpret_cast<InitMetro>(::GetProcAddress(metro_dll, "InitMetro"));
176 return chrome_metro_main(); 189 return chrome_metro_main();
177 } 190 }
178 191
192 if (process_type_ == "watcher") {
193 HMODULE watcher_dll = Load(&version, &file);
194 if (watcher_dll) {
195 browser_watcher::WatcherMainFunction watcher_main =
196 reinterpret_cast<browser_watcher::WatcherMainFunction>(
197 ::GetProcAddress(watcher_dll,
198 browser_watcher::kWatcherDLLEntrypoint));
199
200 watcher_main(chrome::kBrowserExitCodesRegistryPath);
201
202 return content::RESULT_CODE_NORMAL_EXIT;
203 } else {
204 return chrome::RESULT_CODE_MISSING_DATA;
205 }
206 }
207
179 // Initialize the sandbox services. 208 // Initialize the sandbox services.
180 sandbox::SandboxInterfaceInfo sandbox_info = {0}; 209 sandbox::SandboxInterfaceInfo sandbox_info = {0};
181 content::InitializeSandboxInfo(&sandbox_info); 210 content::InitializeSandboxInfo(&sandbox_info);
182 211
183 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); 212 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer());
184 bool exit_now = true; 213 bool exit_now = true;
185 if (process_type_.empty()) { 214 if (process_type_.empty()) {
186 if (breakpad::ShowRestartDialogIfCrashed(&exit_now)) { 215 if (breakpad::ShowRestartDialogIfCrashed(&exit_now)) {
187 // We restarted because of a previous crash. Ask user if we should 216 // We restarted because of a previous crash. Ask user if we should
188 // Relaunch. Only for the browser process. See crbug.com/132119. 217 // Relaunch. Only for the browser process. See crbug.com/132119.
189 if (exit_now) 218 if (exit_now)
190 return content::RESULT_CODE_NORMAL_EXIT; 219 return content::RESULT_CODE_NORMAL_EXIT;
191 } 220 }
192 } 221 }
193 breakpad::InitCrashReporter(process_type_); 222 breakpad::InitCrashReporter(process_type_);
194 223
195 dll_ = Load(&version, &file); 224 dll_ = Load(&version, &file);
196 if (!dll_) 225 if (!dll_)
197 return chrome::RESULT_CODE_MISSING_DATA; 226 return chrome::RESULT_CODE_MISSING_DATA;
198 227
199 scoped_ptr<base::Environment> env(base::Environment::Create()); 228 scoped_ptr<base::Environment> env(base::Environment::Create());
200 env->SetVar(chrome::kChromeVersionEnvVar, base::WideToUTF8(version)); 229 env->SetVar(chrome::kChromeVersionEnvVar, base::WideToUTF8(version));
201 230
202 OnBeforeLaunch(file); 231 OnBeforeLaunch(process_type_, file);
203 DLL_MAIN chrome_main = 232 DLL_MAIN chrome_main =
204 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); 233 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain"));
205 int rc = chrome_main(instance, &sandbox_info); 234 int rc = chrome_main(instance, &sandbox_info);
206 return OnBeforeExit(rc, file); 235 return OnBeforeExit(rc, file);
207 } 236 }
208 237
209 void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { 238 void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
210 if (!dll_) 239 if (!dll_)
211 return; 240 return;
212 241
213 RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function = 242 RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function =
214 reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>( 243 reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>(
215 ::GetProcAddress(dll_, 244 ::GetProcAddress(dll_,
216 "RelaunchChromeBrowserWithNewCommandLineIfNeeded")); 245 "RelaunchChromeBrowserWithNewCommandLineIfNeeded"));
217 if (!relaunch_function) { 246 if (!relaunch_function) {
218 LOG(ERROR) << "Could not find exported function " 247 LOG(ERROR) << "Could not find exported function "
219 << "RelaunchChromeBrowserWithNewCommandLineIfNeeded"; 248 << "RelaunchChromeBrowserWithNewCommandLineIfNeeded";
220 } else { 249 } else {
221 relaunch_function(); 250 relaunch_function();
222 } 251 }
223 } 252 }
224 253
225 //============================================================================= 254 //=============================================================================
226 255
227 class ChromeDllLoader : public MainDllLoader { 256 class ChromeDllLoader : public MainDllLoader {
228 protected: 257 protected:
229 virtual void OnBeforeLaunch(const base::string16& dll_path) { 258 virtual void OnBeforeLaunch(const std::string& process_type,
259 const base::string16& dll_path) override;
260 virtual int OnBeforeExit(int return_code,
261 const base::string16& dll_path) override;
262 };
263
264 void ChromeDllLoader::OnBeforeLaunch(const std::string& process_type,
265 const base::string16& dll_path) {
266 if (process_type.empty()) {
230 RecordDidRun(dll_path); 267 RecordDidRun(dll_path);
268
269 // Launch the watcher process if stats collection consent has been granted.
270 if (g_chrome_crash_client.Get().GetCollectStatsConsent()) {
271 wchar_t exe_path[MAX_PATH];
272 ::GetModuleFileNameW(NULL, exe_path, MAX_PATH);
273
274 base::CommandLine cmd_line = base::CommandLine(base::FilePath(exe_path));
275 cmd_line.AppendSwitchASCII(switches::kProcessType, "watcher");
276 browser_watcher::WatcherClient watcher_client(cmd_line);
277
278 watcher_client.LaunchWatcher();
279 }
280 }
231 } 281 }
232 282
233 virtual int OnBeforeExit(int return_code, const base::string16& dll_path) { 283 int ChromeDllLoader::OnBeforeExit(int return_code,
284 const base::string16& dll_path) {
234 // NORMAL_EXIT_CANCEL is used for experiments when the user cancels 285 // NORMAL_EXIT_CANCEL is used for experiments when the user cancels
235 // so we need to reset the did_run signal so omaha does not count 286 // so we need to reset the did_run signal so omaha does not count
236 // this run as active usage. 287 // this run as active usage.
237 if (chrome::RESULT_CODE_NORMAL_EXIT_CANCEL == return_code) { 288 if (chrome::RESULT_CODE_NORMAL_EXIT_CANCEL == return_code) {
238 ClearDidRun(dll_path); 289 ClearDidRun(dll_path);
239 } 290 }
240 return return_code; 291 return return_code;
241 } 292 }
242 };
243 293
244 //============================================================================= 294 //=============================================================================
245 295
246 class ChromiumDllLoader : public MainDllLoader { 296 class ChromiumDllLoader : public MainDllLoader {
247 protected: 297 protected:
248 virtual void OnBeforeLaunch(const base::string16& dll_path) override { 298 virtual void OnBeforeLaunch(const std::string& process_type,
299 const base::string16& dll_path) override {
249 } 300 }
250 virtual int OnBeforeExit(int return_code, 301 virtual int OnBeforeExit(int return_code,
251 const base::string16& dll_path) override { 302 const base::string16& dll_path) override {
252 return return_code; 303 return return_code;
253 } 304 }
254 }; 305 };
255 306
256 MainDllLoader* MakeMainDllLoader() { 307 MainDllLoader* MakeMainDllLoader() {
257 #if defined(GOOGLE_CHROME_BUILD) 308 #if defined(GOOGLE_CHROME_BUILD)
258 return new ChromeDllLoader(); 309 return new ChromeDllLoader();
259 #else 310 #else
260 return new ChromiumDllLoader(); 311 return new ChromiumDllLoader();
261 #endif 312 #endif
262 } 313 }
OLDNEW
« no previous file with comments | « chrome/app/client_util.h ('k') | chrome/browser/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698