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 <userenv.h> // NOLINT | 10 #include <userenv.h> // NOLINT |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
27 #include "base/trace_event/trace_event.h" | 27 #include "base/trace_event/trace_event.h" |
28 #include "base/win/scoped_handle.h" | 28 #include "base/win/scoped_handle.h" |
29 #include "base/win/windows_version.h" | 29 #include "base/win/windows_version.h" |
30 #include "chrome/app/chrome_crash_reporter_client_win.h" | 30 #include "chrome/app/chrome_crash_reporter_client_win.h" |
31 #include "chrome/app/chrome_watcher_client_win.h" | 31 #include "chrome/app/chrome_watcher_client_win.h" |
32 #include "chrome/app/chrome_watcher_command_line_win.h" | 32 #include "chrome/app/chrome_watcher_command_line_win.h" |
33 #include "chrome/app/file_pre_reader_win.h" | 33 #include "chrome/app/file_pre_reader_win.h" |
34 #include "chrome/app/kasko_client.h" | |
35 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" | 34 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" |
36 #include "chrome/common/chrome_constants.h" | 35 #include "chrome/common/chrome_constants.h" |
37 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
38 #include "chrome/common/chrome_result_codes.h" | 37 #include "chrome/common/chrome_result_codes.h" |
39 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
40 #include "chrome/common/metrics_constants_util_win.h" | 39 #include "chrome/common/metrics_constants_util_win.h" |
41 #include "chrome/installer/util/google_update_constants.h" | 40 #include "chrome/installer/util/google_update_constants.h" |
42 #include "chrome/installer/util/google_update_settings.h" | 41 #include "chrome/installer/util/google_update_settings.h" |
43 #include "chrome/installer/util/install_util.h" | 42 #include "chrome/installer/util/install_util.h" |
44 #include "chrome/installer/util/module_util_win.h" | 43 #include "chrome/installer/util/module_util_win.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 204 |
206 class ChromeDllLoader : public MainDllLoader { | 205 class ChromeDllLoader : public MainDllLoader { |
207 protected: | 206 protected: |
208 // MainDllLoader implementation. | 207 // MainDllLoader implementation. |
209 void OnBeforeLaunch(const std::string& process_type, | 208 void OnBeforeLaunch(const std::string& process_type, |
210 const base::FilePath& dll_path) override; | 209 const base::FilePath& dll_path) override; |
211 int OnBeforeExit(int return_code, const base::FilePath& dll_path) override; | 210 int OnBeforeExit(int return_code, const base::FilePath& dll_path) override; |
212 | 211 |
213 private: | 212 private: |
214 std::unique_ptr<ChromeWatcherClient> chrome_watcher_client_; | 213 std::unique_ptr<ChromeWatcherClient> chrome_watcher_client_; |
215 #if BUILDFLAG(ENABLE_KASKO) | |
216 std::unique_ptr<KaskoClient> kasko_client_; | |
217 #endif | |
218 }; | 214 }; |
219 | 215 |
220 void ChromeDllLoader::OnBeforeLaunch(const std::string& process_type, | 216 void ChromeDllLoader::OnBeforeLaunch(const std::string& process_type, |
221 const base::FilePath& dll_path) { | 217 const base::FilePath& dll_path) { |
222 if (process_type.empty()) { | 218 if (process_type.empty()) { |
223 RecordDidRun(dll_path); | 219 RecordDidRun(dll_path); |
224 | |
225 typedef bool (*GetUploadsEnabledFunction)(void); | |
226 static GetUploadsEnabledFunction get_uploads_enabled = nullptr; | |
227 if (!get_uploads_enabled) { | |
228 get_uploads_enabled = reinterpret_cast<GetUploadsEnabledFunction>( | |
229 GetProcAddress(GetModuleHandle(chrome::kChromeElfDllName), | |
230 "GetUploadsEnabled")); | |
231 CHECK(get_uploads_enabled); | |
232 } | |
233 | |
234 // Launch the watcher process if stats collection consent has been granted. | |
235 if (get_uploads_enabled()) { | |
236 base::FilePath exe_path; | |
237 if (PathService::Get(base::FILE_EXE, &exe_path)) { | |
238 chrome_watcher_client_.reset(new ChromeWatcherClient( | |
239 base::Bind(&GenerateChromeWatcherCommandLine, exe_path))); | |
240 if (chrome_watcher_client_->LaunchWatcher()) { | |
241 #if BUILDFLAG(ENABLE_KASKO) | |
242 kasko::api::MinidumpType minidump_type = kasko::api::SMALL_DUMP_TYPE; | |
243 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
244 switches::kFullMemoryCrashReport)) { | |
245 minidump_type = kasko::api::FULL_DUMP_TYPE; | |
246 } else { | |
247 // TODO(scottmg): Point this at the common global one when it's | |
248 // moved back into the .exe. http://crbug.com/546288. | |
249 ChromeCrashReporterClient chrome_crash_client; | |
250 bool is_per_user_install = chrome_crash_client.GetIsPerUserInstall( | |
251 exe_path.value()); | |
252 if (chrome_crash_client.GetShouldDumpLargerDumps( | |
253 is_per_user_install)) { | |
254 minidump_type = kasko::api::LARGER_DUMP_TYPE; | |
255 } | |
256 } | |
257 | |
258 kasko_client_.reset( | |
259 new KaskoClient(chrome_watcher_client_.get(), minidump_type)); | |
260 #endif // BUILDFLAG(ENABLE_KASKO) | |
261 } | |
262 } | |
263 } | |
264 } else { | 220 } else { |
265 // Set non-browser processes up to be killed by the system after the browser | 221 // Set non-browser processes up to be killed by the system after the browser |
266 // goes away. The browser uses the default shutdown order, which is 0x280. | 222 // goes away. The browser uses the default shutdown order, which is 0x280. |
267 // Note that lower numbers here denote "kill later" and higher numbers mean | 223 // Note that lower numbers here denote "kill later" and higher numbers mean |
268 // "kill sooner". | 224 // "kill sooner". |
269 // This gets rid of most of those unsighly sad tabs on logout and shutdown. | 225 // This gets rid of most of those unsighly sad tabs on logout and shutdown. |
270 ::SetProcessShutdownParameters(0x280 - 1, SHUTDOWN_NORETRY); | 226 ::SetProcessShutdownParameters(0x280 - 1, SHUTDOWN_NORETRY); |
271 } | 227 } |
272 } | 228 } |
273 | 229 |
274 int ChromeDllLoader::OnBeforeExit(int return_code, | 230 int ChromeDllLoader::OnBeforeExit(int return_code, |
275 const base::FilePath& dll_path) { | 231 const base::FilePath& dll_path) { |
276 // NORMAL_EXIT_CANCEL is used for experiments when the user cancels | 232 // NORMAL_EXIT_CANCEL is used for experiments when the user cancels |
277 // so we need to reset the did_run signal so omaha does not count | 233 // so we need to reset the did_run signal so omaha does not count |
278 // this run as active usage. | 234 // this run as active usage. |
279 if (chrome::RESULT_CODE_NORMAL_EXIT_CANCEL == return_code) { | 235 if (chrome::RESULT_CODE_NORMAL_EXIT_CANCEL == return_code) { |
280 ClearDidRun(dll_path); | 236 ClearDidRun(dll_path); |
281 } | 237 } |
282 | 238 |
283 #if BUILDFLAG(ENABLE_KASKO) | |
284 kasko_client_.reset(); | |
285 #endif | |
286 chrome_watcher_client_.reset(); | 239 chrome_watcher_client_.reset(); |
287 | 240 |
288 return return_code; | 241 return return_code; |
289 } | 242 } |
290 | 243 |
291 //============================================================================= | 244 //============================================================================= |
292 | 245 |
293 class ChromiumDllLoader : public MainDllLoader { | 246 class ChromiumDllLoader : public MainDllLoader { |
294 protected: | 247 protected: |
295 void OnBeforeLaunch(const std::string& process_type, | 248 void OnBeforeLaunch(const std::string& process_type, |
296 const base::FilePath& dll_path) override {} | 249 const base::FilePath& dll_path) override {} |
297 int OnBeforeExit(int return_code, const base::FilePath& dll_path) override { | 250 int OnBeforeExit(int return_code, const base::FilePath& dll_path) override { |
298 return return_code; | 251 return return_code; |
299 } | 252 } |
300 }; | 253 }; |
301 | 254 |
302 MainDllLoader* MakeMainDllLoader() { | 255 MainDllLoader* MakeMainDllLoader() { |
303 #if defined(GOOGLE_CHROME_BUILD) | 256 #if defined(GOOGLE_CHROME_BUILD) |
304 return new ChromeDllLoader(); | 257 return new ChromeDllLoader(); |
305 #else | 258 #else |
306 return new ChromiumDllLoader(); | 259 return new ChromiumDllLoader(); |
307 #endif | 260 #endif |
308 } | 261 } |
OLD | NEW |