Index: chrome/app/client_util.cc |
diff --git a/chrome/app/client_util.cc b/chrome/app/client_util.cc |
index 4dd632514f023a2dcba704c28b23c5813c084392..a47daeb151f8ad4b120e993311cec473d92f755a 100644 |
--- a/chrome/app/client_util.cc |
+++ b/chrome/app/client_util.cc |
@@ -10,9 +10,11 @@ |
#include "base/debug/trace_event.h" |
#include "base/environment.h" |
#include "base/file_version_info.h" |
+#include "base/files/file_path.h" |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/process/launch.h" |
#include "base/rand_util.h" // For PreRead experiment. |
#include "base/sha1.h" // For PreRead experiment. |
#include "base/strings/string16.h" |
@@ -20,6 +22,8 @@ |
#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/version.h" |
+#include "base/win/scoped_process_information.h" |
+#include "base/win/startup_information.h" |
#include "base/win/windows_version.h" |
#include "chrome/app/chrome_crash_reporter_client.h" |
#include "chrome/app/client_util.h" |
@@ -32,6 +36,8 @@ |
#include "chrome/installer/util/google_update_settings.h" |
#include "chrome/installer/util/install_util.h" |
#include "chrome/installer/util/util_constants.h" |
+#include "components/browser_watcher/watcher_client_win.h" |
+#include "components/browser_watcher/watcher_main_win.h" |
#include "components/crash/app/breakpad_win.h" |
#include "components/crash/app/crash_reporter_client.h" |
#include "components/metrics/client_info.h" |
@@ -235,15 +241,22 @@ HMODULE MainDllLoader::Load(base::string16* version, |
const base::string16 executable_dir(GetExecutablePath()); |
*out_file = executable_dir; |
- const wchar_t* dll_name = metro_mode_ ? |
- installer::kChromeMetroDll : |
-#if !defined(CHROME_MULTIPLE_DLL) |
- installer::kChromeDll; |
+ const wchar_t* dll_name = NULL; |
+ if (metro_mode_) |
+ dll_name = installer::kChromeMetroDll; |
+ |
+ if (process_type_ == "service" || process_type_.empty()) { |
+ dll_name = installer::kChromeDll; |
+ } else if (process_type_ == "watcher") { |
+ dll_name = browser_watcher::kWatcherDll; |
+ } else { |
+#if defined(CHROME_MULTIPLE_DLL) |
+ dll_name = installer::kChromeChildDll; |
#else |
- (process_type_ == "service") || process_type_.empty() ? |
- installer::kChromeDll : |
- installer::kChromeChildDll; |
+ dll_name = installer::kChromeDll; |
#endif |
+ } |
+ |
const bool pre_read = !metro_mode_; |
HMODULE dll = LoadModuleWithDirectory(out_file, dll_name, pre_read); |
if (!dll) { |
@@ -286,6 +299,22 @@ int MainDllLoader::Launch(HINSTANCE instance) { |
return chrome_metro_main(); |
} |
+ if (process_type_ == "watcher") { |
+ HMODULE watcher_dll = Load(&version, &file); |
+ if (watcher_dll) { |
+ browser_watcher::WatcherMainFunction watcher_main = |
+ reinterpret_cast<browser_watcher::WatcherMainFunction>( |
+ ::GetProcAddress(watcher_dll, |
+ browser_watcher::kWatcherDLLEntrypoint)); |
+ |
+ watcher_main(chrome::kBrowserExitCodesRegistryPath); |
+ |
+ return content::RESULT_CODE_NORMAL_EXIT; |
+ } else { |
+ return chrome::RESULT_CODE_MISSING_DATA; |
+ } |
+ } |
+ |
// Initialize the sandbox services. |
sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
content::InitializeSandboxInfo(&sandbox_info); |
@@ -309,7 +338,7 @@ int MainDllLoader::Launch(HINSTANCE instance) { |
scoped_ptr<base::Environment> env(base::Environment::Create()); |
env->SetVar(chrome::kChromeVersionEnvVar, base::WideToUTF8(version)); |
- OnBeforeLaunch(file); |
+ OnBeforeLaunch(process_type_, file); |
DLL_MAIN chrome_main = |
reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); |
int rc = chrome_main(instance, &sandbox_info); |
@@ -336,11 +365,33 @@ void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { |
class ChromeDllLoader : public MainDllLoader { |
protected: |
- virtual void OnBeforeLaunch(const base::string16& dll_path) { |
+ virtual void OnBeforeLaunch(const std::string& process_type, |
+ const base::string16& dll_path) OVERRIDE; |
+ virtual int OnBeforeExit(int return_code, |
+ const base::string16& dll_path) OVERRIDE; |
+}; |
+ |
+void ChromeDllLoader::OnBeforeLaunch(const std::string& process_type, |
+ const base::string16& dll_path) { |
+ if (process_type.empty()) { |
RecordDidRun(dll_path); |
+ |
+ // Launch the watcher process if stats collection consent has been granted. |
+ if (g_chrome_crash_client.Get().GetCollectStatsConsent()) { |
+ wchar_t exe_path[MAX_PATH]; |
+ ::GetModuleFileNameW(NULL, exe_path, MAX_PATH); |
+ |
+ base::CommandLine cmd_line = base::CommandLine(base::FilePath(exe_path)); |
+ cmd_line.AppendSwitchASCII(switches::kProcessType, "watcher"); |
+ browser_watcher::WatcherClient watcher_client(cmd_line); |
+ |
+ watcher_client.LaunchWatcher(); |
+ } |
} |
+} |
- virtual int OnBeforeExit(int return_code, const base::string16& dll_path) { |
+int ChromeDllLoader::OnBeforeExit(int return_code, |
+ const base::string16& dll_path) { |
// NORMAL_EXIT_CANCEL is used for experiments when the user cancels |
// so we need to reset the did_run signal so omaha does not count |
// this run as active usage. |
@@ -349,13 +400,13 @@ class ChromeDllLoader : public MainDllLoader { |
} |
return return_code; |
} |
-}; |
//============================================================================= |
class ChromiumDllLoader : public MainDllLoader { |
protected: |
- virtual void OnBeforeLaunch(const base::string16& dll_path) override { |
+ virtual void OnBeforeLaunch(const std::string& process_type, |
+ const base::string16& dll_path) override { |
} |
virtual int OnBeforeExit(int return_code, |
const base::string16& dll_path) override { |