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> | 5 #include <windows.h> |
6 #include <shlwapi.h> | 6 #include <shlwapi.h> |
7 | 7 |
| 8 #include "base/base_paths.h" |
8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
10 #include "base/environment.h" | 11 #include "base/environment.h" |
11 #include "base/file_version_info.h" | 12 #include "base/file_version_info.h" |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/path_service.h" |
15 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
16 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
19 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
20 #include "base/version.h" | 22 #include "base/version.h" |
21 #include "base/win/scoped_handle.h" | 23 #include "base/win/scoped_handle.h" |
22 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
23 #include "chrome/app/chrome_crash_reporter_client.h" | 25 #include "chrome/app/chrome_crash_reporter_client.h" |
24 #include "chrome/app/chrome_watcher_client_win.h" | 26 #include "chrome/app/chrome_watcher_client_win.h" |
25 #include "chrome/app/chrome_watcher_command_line_win.h" | 27 #include "chrome/app/chrome_watcher_command_line_win.h" |
26 #include "chrome/app/client_util.h" | 28 #include "chrome/app/client_util.h" |
27 #include "chrome/app/image_pre_reader_win.h" | 29 #include "chrome/app/image_pre_reader_win.h" |
28 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" | 30 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" |
29 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
| 32 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/chrome_result_codes.h" | 33 #include "chrome/common/chrome_result_codes.h" |
31 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/env_vars.h" | 35 #include "chrome/common/env_vars.h" |
33 #include "chrome/installer/util/google_update_constants.h" | 36 #include "chrome/installer/util/google_update_constants.h" |
34 #include "chrome/installer/util/google_update_settings.h" | 37 #include "chrome/installer/util/google_update_settings.h" |
35 #include "chrome/installer/util/install_util.h" | 38 #include "chrome/installer/util/install_util.h" |
36 #include "chrome/installer/util/util_constants.h" | 39 #include "chrome/installer/util/util_constants.h" |
37 #include "components/crash/app/breakpad_win.h" | 40 #include "components/crash/app/breakpad_win.h" |
38 #include "components/crash/app/crash_reporter_client.h" | 41 #include "components/crash/app/crash_reporter_client.h" |
39 #include "components/metrics/client_info.h" | 42 #include "components/metrics/client_info.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 HMODULE metro_dll = Load(&version, &file); | 175 HMODULE metro_dll = Load(&version, &file); |
173 if (!metro_dll) | 176 if (!metro_dll) |
174 return chrome::RESULT_CODE_MISSING_DATA; | 177 return chrome::RESULT_CODE_MISSING_DATA; |
175 | 178 |
176 InitMetro chrome_metro_main = | 179 InitMetro chrome_metro_main = |
177 reinterpret_cast<InitMetro>(::GetProcAddress(metro_dll, "InitMetro")); | 180 reinterpret_cast<InitMetro>(::GetProcAddress(metro_dll, "InitMetro")); |
178 return chrome_metro_main(); | 181 return chrome_metro_main(); |
179 } | 182 } |
180 | 183 |
181 if (process_type_ == "watcher") { | 184 if (process_type_ == "watcher") { |
| 185 chrome::RegisterPathProvider(); |
| 186 |
182 base::win::ScopedHandle parent_process; | 187 base::win::ScopedHandle parent_process; |
183 base::win::ScopedHandle on_initialized_event; | 188 base::win::ScopedHandle on_initialized_event; |
184 if (!InterpretChromeWatcherCommandLine(cmd_line, &parent_process, | 189 if (!InterpretChromeWatcherCommandLine(cmd_line, &parent_process, |
185 &on_initialized_event)) { | 190 &on_initialized_event)) { |
186 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; | 191 return chrome::RESULT_CODE_UNSUPPORTED_PARAM; |
187 } | 192 } |
188 | 193 |
| 194 base::FilePath watcher_data_directory; |
| 195 if (!PathService::Get(chrome::DIR_WATCHER_DATA, &watcher_data_directory)) |
| 196 return chrome::RESULT_CODE_MISSING_DATA; |
| 197 |
189 // Intentionally leaked. | 198 // Intentionally leaked. |
190 HMODULE watcher_dll = Load(&version, &file); | 199 HMODULE watcher_dll = Load(&version, &file); |
191 if (!watcher_dll) | 200 if (!watcher_dll) |
192 return chrome::RESULT_CODE_MISSING_DATA; | 201 return chrome::RESULT_CODE_MISSING_DATA; |
193 | 202 |
194 ChromeWatcherMainFunction watcher_main = | 203 ChromeWatcherMainFunction watcher_main = |
195 reinterpret_cast<ChromeWatcherMainFunction>( | 204 reinterpret_cast<ChromeWatcherMainFunction>( |
196 ::GetProcAddress(watcher_dll, kChromeWatcherDLLEntrypoint)); | 205 ::GetProcAddress(watcher_dll, kChromeWatcherDLLEntrypoint)); |
197 return watcher_main(chrome::kBrowserExitCodesRegistryPath, | 206 return watcher_main(chrome::kBrowserExitCodesRegistryPath, |
198 parent_process.Take(), on_initialized_event.Take()); | 207 parent_process.Take(), on_initialized_event.Take(), |
| 208 watcher_data_directory.value().c_str()); |
199 } | 209 } |
200 | 210 |
201 // Initialize the sandbox services. | 211 // Initialize the sandbox services. |
202 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 212 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
203 content::InitializeSandboxInfo(&sandbox_info); | 213 content::InitializeSandboxInfo(&sandbox_info); |
204 | 214 |
205 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); | 215 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); |
206 bool exit_now = true; | 216 bool exit_now = true; |
207 if (process_type_.empty()) { | 217 if (process_type_.empty()) { |
208 if (breakpad::ShowRestartDialogIfCrashed(&exit_now)) { | 218 if (breakpad::ShowRestartDialogIfCrashed(&exit_now)) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 int OnBeforeExit(int return_code, const base::FilePath& dll_path) override; | 263 int OnBeforeExit(int return_code, const base::FilePath& dll_path) override; |
254 }; | 264 }; |
255 | 265 |
256 void ChromeDllLoader::OnBeforeLaunch(const std::string& process_type, | 266 void ChromeDllLoader::OnBeforeLaunch(const std::string& process_type, |
257 const base::FilePath& dll_path) { | 267 const base::FilePath& dll_path) { |
258 if (process_type.empty()) { | 268 if (process_type.empty()) { |
259 RecordDidRun(dll_path); | 269 RecordDidRun(dll_path); |
260 | 270 |
261 // Launch the watcher process if stats collection consent has been granted. | 271 // Launch the watcher process if stats collection consent has been granted. |
262 if (g_chrome_crash_client.Get().GetCollectStatsConsent()) { | 272 if (g_chrome_crash_client.Get().GetCollectStatsConsent()) { |
263 base::char16 exe_path[MAX_PATH]; | 273 base::FilePath exe_path; |
264 ::GetModuleFileNameW(nullptr, exe_path, arraysize(exe_path)); | 274 if (PathService::Get(base::FILE_EXE, &exe_path)) { |
265 ChromeWatcherClient watcher_client(base::Bind( | 275 ChromeWatcherClient watcher_client( |
266 &GenerateChromeWatcherCommandLine, base::FilePath(exe_path))); | 276 base::Bind(&GenerateChromeWatcherCommandLine, exe_path)); |
267 watcher_client.LaunchWatcher(); | 277 watcher_client.LaunchWatcher(); |
| 278 } else { |
| 279 NOTREACHED(); |
| 280 } |
268 } | 281 } |
269 } | 282 } |
270 } | 283 } |
271 | 284 |
272 int ChromeDllLoader::OnBeforeExit(int return_code, | 285 int ChromeDllLoader::OnBeforeExit(int return_code, |
273 const base::FilePath& dll_path) { | 286 const base::FilePath& dll_path) { |
274 // NORMAL_EXIT_CANCEL is used for experiments when the user cancels | 287 // NORMAL_EXIT_CANCEL is used for experiments when the user cancels |
275 // so we need to reset the did_run signal so omaha does not count | 288 // so we need to reset the did_run signal so omaha does not count |
276 // this run as active usage. | 289 // this run as active usage. |
277 if (chrome::RESULT_CODE_NORMAL_EXIT_CANCEL == return_code) { | 290 if (chrome::RESULT_CODE_NORMAL_EXIT_CANCEL == return_code) { |
(...skipping 13 matching lines...) Expand all Loading... |
291 } | 304 } |
292 }; | 305 }; |
293 | 306 |
294 MainDllLoader* MakeMainDllLoader() { | 307 MainDllLoader* MakeMainDllLoader() { |
295 #if defined(GOOGLE_CHROME_BUILD) | 308 #if defined(GOOGLE_CHROME_BUILD) |
296 return new ChromeDllLoader(); | 309 return new ChromeDllLoader(); |
297 #else | 310 #else |
298 return new ChromiumDllLoader(); | 311 return new ChromiumDllLoader(); |
299 #endif | 312 #endif |
300 } | 313 } |
OLD | NEW |