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/template_util.h" | 11 #include "base/template_util.h" |
11 #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" | |
12 #include "components/browser_watcher/watcher_main_api_win.h" | 14 #include "components/browser_watcher/watcher_main_api_win.h" |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 // Use the same log facility as Chrome for convenience. | 18 // Use the same log facility as Chrome for convenience. |
17 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} | 19 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} |
18 const GUID kChromeWatcherTraceProviderName = { | 20 const GUID kChromeWatcherTraceProviderName = { |
19 0x7fe69228, 0x633e, 0x4f06, | 21 0x7fe69228, 0x633e, 0x4f06, |
20 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } }; | 22 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } }; |
21 | 23 |
(...skipping 13 matching lines...) Expand all Loading... | |
35 // chrome.exe in order to report its exit status. | 37 // chrome.exe in order to report its exit status. |
36 // TODO(siggi): Does this (windowless) process need to register a console | 38 // TODO(siggi): Does this (windowless) process need to register a console |
37 // handler too, in order to get notice of logoff events? | 39 // handler too, in order to get notice of logoff events? |
38 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); | 40 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); |
39 | 41 |
40 browser_watcher::ExitCodeWatcher exit_code_watcher(registry_path); | 42 browser_watcher::ExitCodeWatcher exit_code_watcher(registry_path); |
41 int ret = 1; | 43 int ret = 1; |
42 // 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. |
43 if (exit_code_watcher.ParseArguments( | 45 if (exit_code_watcher.ParseArguments( |
44 *base::CommandLine::ForCurrentProcess())) { | 46 *base::CommandLine::ForCurrentProcess())) { |
47 base::ProcessHandle dupe = base::kNullProcessHandle; | |
rvargas (doing something else)
2014/12/13 01:32:53
It would be nice to use base::Process here... but
| |
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 | |
45 // Wait on the process. | 60 // Wait on the process. |
46 exit_code_watcher.WaitForExit(); | 61 exit_code_watcher.WaitForExit(); |
62 | |
63 if (dupe != base::kNullProcessHandle) { | |
64 browser_watcher::ExitFunnel funnel; | |
65 funnel.Init(registry_path, dupe); | |
66 funnel.RecordEvent(L"BrowserExit"); | |
67 | |
68 base::CloseProcessHandle(dupe); | |
69 } | |
70 | |
47 ret = 0; | 71 ret = 0; |
48 } | 72 } |
49 | 73 |
50 // Wind logging down. | 74 // Wind logging down. |
51 logging::LogEventProvider::Uninitialize(); | 75 logging::LogEventProvider::Uninitialize(); |
52 | 76 |
53 return ret; | 77 return ret; |
54 } | 78 } |
55 | 79 |
56 static_assert(base::is_same<decltype(&WatcherMain), | 80 static_assert(base::is_same<decltype(&WatcherMain), |
57 browser_watcher::WatcherMainFunction>::value, | 81 browser_watcher::WatcherMainFunction>::value, |
58 "WatcherMain() has wrong type"); | 82 "WatcherMain() has wrong type"); |
OLD | NEW |