OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/process/kill.h" | 5 #include "base/process/kill.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <io.h> | 8 #include <io.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/message_loop/message_loop.h" | |
18 #include "base/process/process_iterator.h" | 17 #include "base/process/process_iterator.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" |
19 #include "base/win/object_watcher.h" | 19 #include "base/win/object_watcher.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // Exit codes with special meanings on Windows. | 25 // Exit codes with special meanings on Windows. |
26 const DWORD kNormalTerminationExitCode = 0; | 26 const DWORD kNormalTerminationExitCode = 0; |
27 const DWORD kDebuggerInactiveExitCode = 0xC0000354; | 27 const DWORD kDebuggerInactiveExitCode = 0xC0000354; |
28 const DWORD kKeyboardInterruptExitCode = 0xC000013A; | 28 const DWORD kKeyboardInterruptExitCode = 0xC000013A; |
(...skipping 10 matching lines...) Expand all Loading... |
39 // Maximum amount of time (in milliseconds) to wait for the process to exit. | 39 // Maximum amount of time (in milliseconds) to wait for the process to exit. |
40 static const int kWaitInterval = 2000; | 40 static const int kWaitInterval = 2000; |
41 | 41 |
42 class TimerExpiredTask : public win::ObjectWatcher::Delegate { | 42 class TimerExpiredTask : public win::ObjectWatcher::Delegate { |
43 public: | 43 public: |
44 explicit TimerExpiredTask(Process process); | 44 explicit TimerExpiredTask(Process process); |
45 ~TimerExpiredTask() override; | 45 ~TimerExpiredTask() override; |
46 | 46 |
47 void TimedOut(); | 47 void TimedOut(); |
48 | 48 |
49 // MessageLoop::Watcher ----------------------------------------------------- | 49 // win::ObjectWatcher::Delegate implementation. |
50 void OnObjectSignaled(HANDLE object) override; | 50 void OnObjectSignaled(HANDLE object) override; |
51 | 51 |
52 private: | 52 private: |
53 void KillProcess(); | 53 void KillProcess(); |
54 | 54 |
55 // The process that we are watching. | 55 // The process that we are watching. |
56 Process process_; | 56 Process process_; |
57 | 57 |
58 win::ObjectWatcher watcher_; | 58 win::ObjectWatcher watcher_; |
59 | 59 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 186 } |
187 | 187 |
188 void EnsureProcessTerminated(Process process) { | 188 void EnsureProcessTerminated(Process process) { |
189 DCHECK(!process.is_current()); | 189 DCHECK(!process.is_current()); |
190 | 190 |
191 // If already signaled, then we are done! | 191 // If already signaled, then we are done! |
192 if (WaitForSingleObject(process.Handle(), 0) == WAIT_OBJECT_0) { | 192 if (WaitForSingleObject(process.Handle(), 0) == WAIT_OBJECT_0) { |
193 return; | 193 return; |
194 } | 194 } |
195 | 195 |
196 MessageLoop::current()->PostDelayedTask( | 196 ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
197 FROM_HERE, Bind(&TimerExpiredTask::TimedOut, | 197 FROM_HERE, Bind(&TimerExpiredTask::TimedOut, |
198 Owned(new TimerExpiredTask(std::move(process)))), | 198 Owned(new TimerExpiredTask(std::move(process)))), |
199 TimeDelta::FromMilliseconds(kWaitInterval)); | 199 TimeDelta::FromMilliseconds(kWaitInterval)); |
200 } | 200 } |
201 | 201 |
202 } // namespace base | 202 } // namespace base |
OLD | NEW |