OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging_win.h" | 9 #include "base/logging_win.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process.h" |
11 #include "base/template_util.h" | 11 #include "base/template_util.h" |
12 #include "components/browser_watcher/exit_code_watcher_win.h" | 12 #include "components/browser_watcher/exit_code_watcher_win.h" |
13 #include "components/browser_watcher/exit_funnel_win.h" | 13 #include "components/browser_watcher/exit_funnel_win.h" |
14 #include "components/browser_watcher/watcher_main_api_win.h" | 14 #include "components/browser_watcher/watcher_main_api_win.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // Use the same log facility as Chrome for convenience. | 18 // Use the same log facility as Chrome for convenience. |
19 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} | 19 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} |
20 const GUID kChromeWatcherTraceProviderName = { | 20 const GUID kChromeWatcherTraceProviderName = { |
(...skipping 16 matching lines...) Expand all Loading... |
37 // chrome.exe in order to report its exit status. | 37 // chrome.exe in order to report its exit status. |
38 // TODO(siggi): Does this (windowless) process need to register a console | 38 // TODO(siggi): Does this (windowless) process need to register a console |
39 // handler too, in order to get notice of logoff events? | 39 // handler too, in order to get notice of logoff events? |
40 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); | 40 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); |
41 | 41 |
42 browser_watcher::ExitCodeWatcher exit_code_watcher(registry_path); | 42 browser_watcher::ExitCodeWatcher exit_code_watcher(registry_path); |
43 int ret = 1; | 43 int ret = 1; |
44 // Attempt to wait on our parent process, and record its exit status. | 44 // Attempt to wait on our parent process, and record its exit status. |
45 if (exit_code_watcher.ParseArguments( | 45 if (exit_code_watcher.ParseArguments( |
46 *base::CommandLine::ForCurrentProcess())) { | 46 *base::CommandLine::ForCurrentProcess())) { |
47 base::ProcessHandle dupe = base::kNullProcessHandle; | |
48 // Duplicate the process handle for the exit funnel due to the wonky | |
49 // process handle lifetime management in base. | |
50 if (!::DuplicateHandle(base::GetCurrentProcessHandle(), | |
51 exit_code_watcher.process(), | |
52 base::GetCurrentProcessHandle(), | |
53 &dupe, | |
54 0, | |
55 FALSE, | |
56 DUPLICATE_SAME_ACCESS)) { | |
57 dupe = base::kNullProcessHandle; | |
58 } | |
59 | |
60 // Wait on the process. | 47 // Wait on the process. |
61 exit_code_watcher.WaitForExit(); | 48 exit_code_watcher.WaitForExit(); |
62 | 49 |
63 if (dupe != base::kNullProcessHandle) { | 50 browser_watcher::ExitFunnel funnel; |
64 browser_watcher::ExitFunnel funnel; | 51 funnel.Init(registry_path, exit_code_watcher.process().Handle()); |
65 funnel.Init(registry_path, dupe); | 52 funnel.RecordEvent(L"BrowserExit"); |
66 funnel.RecordEvent(L"BrowserExit"); | |
67 | |
68 base::CloseProcessHandle(dupe); | |
69 } | |
70 | 53 |
71 ret = 0; | 54 ret = 0; |
72 } | 55 } |
73 | 56 |
74 // Wind logging down. | 57 // Wind logging down. |
75 logging::LogEventProvider::Uninitialize(); | 58 logging::LogEventProvider::Uninitialize(); |
76 | 59 |
77 return ret; | 60 return ret; |
78 } | 61 } |
79 | 62 |
80 static_assert(base::is_same<decltype(&WatcherMain), | 63 static_assert(base::is_same<decltype(&WatcherMain), |
81 browser_watcher::WatcherMainFunction>::value, | 64 browser_watcher::WatcherMainFunction>::value, |
82 "WatcherMain() has wrong type"); | 65 "WatcherMain() has wrong type"); |
OLD | NEW |