| 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> |
| 12 |
| 11 #include "base/bind.h" | 13 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 13 #include "base/logging.h" | 15 #include "base/logging.h" |
| 14 #include "base/macros.h" | 16 #include "base/macros.h" |
| 15 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 16 #include "base/process/process_iterator.h" | 18 #include "base/process/process_iterator.h" |
| 17 #include "base/win/object_watcher.h" | 19 #include "base/win/object_watcher.h" |
| 18 | 20 |
| 19 namespace base { | 21 namespace base { |
| 20 | 22 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 51 void KillProcess(); | 53 void KillProcess(); |
| 52 | 54 |
| 53 // The process that we are watching. | 55 // The process that we are watching. |
| 54 Process process_; | 56 Process process_; |
| 55 | 57 |
| 56 win::ObjectWatcher watcher_; | 58 win::ObjectWatcher watcher_; |
| 57 | 59 |
| 58 DISALLOW_COPY_AND_ASSIGN(TimerExpiredTask); | 60 DISALLOW_COPY_AND_ASSIGN(TimerExpiredTask); |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 TimerExpiredTask::TimerExpiredTask(Process process) : process_(process.Pass()) { | 63 TimerExpiredTask::TimerExpiredTask(Process process) |
| 64 : process_(std::move(process)) { |
| 62 watcher_.StartWatchingOnce(process_.Handle(), this); | 65 watcher_.StartWatchingOnce(process_.Handle(), this); |
| 63 } | 66 } |
| 64 | 67 |
| 65 TimerExpiredTask::~TimerExpiredTask() { | 68 TimerExpiredTask::~TimerExpiredTask() { |
| 66 TimedOut(); | 69 TimedOut(); |
| 67 } | 70 } |
| 68 | 71 |
| 69 void TimerExpiredTask::TimedOut() { | 72 void TimerExpiredTask::TimedOut() { |
| 70 if (process_.IsValid()) | 73 if (process_.IsValid()) |
| 71 KillProcess(); | 74 KillProcess(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 187 |
| 185 void EnsureProcessTerminated(Process process) { | 188 void EnsureProcessTerminated(Process process) { |
| 186 DCHECK(!process.is_current()); | 189 DCHECK(!process.is_current()); |
| 187 | 190 |
| 188 // If already signaled, then we are done! | 191 // If already signaled, then we are done! |
| 189 if (WaitForSingleObject(process.Handle(), 0) == WAIT_OBJECT_0) { | 192 if (WaitForSingleObject(process.Handle(), 0) == WAIT_OBJECT_0) { |
| 190 return; | 193 return; |
| 191 } | 194 } |
| 192 | 195 |
| 193 MessageLoop::current()->PostDelayedTask( | 196 MessageLoop::current()->PostDelayedTask( |
| 194 FROM_HERE, | 197 FROM_HERE, Bind(&TimerExpiredTask::TimedOut, |
| 195 Bind(&TimerExpiredTask::TimedOut, | 198 Owned(new TimerExpiredTask(std::move(process)))), |
| 196 Owned(new TimerExpiredTask(process.Pass()))), | |
| 197 TimeDelta::FromMilliseconds(kWaitInterval)); | 199 TimeDelta::FromMilliseconds(kWaitInterval)); |
| 198 } | 200 } |
| 199 | 201 |
| 200 } // namespace base | 202 } // namespace base |
| OLD | NEW |