| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/common/process_watcher.h" | 5 #include "chrome/common/process_watcher.h" |
| 6 | 6 |
| 7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/environment.h" | 8 #include "base/environment.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/object_watcher.h" | 10 #include "base/win/object_watcher.h" |
| 11 #include "chrome/common/env_vars.h" | 11 #include "chrome/common/env_vars.h" |
| 12 #include "chrome/common/result_codes.h" | 12 #include "chrome/common/result_codes.h" |
| 13 | 13 |
| 14 // Maximum amount of time (in milliseconds) to wait for the process to exit. | 14 // Maximum amount of time (in milliseconds) to wait for the process to exit. |
| 15 static const int kWaitInterval = 2000; | 15 static const int kWaitInterval = 2000; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class TimerExpiredTask : public Task, public base::ObjectWatcher::Delegate { | 19 class TimerExpiredTask : public Task, |
| 20 public base::win::ObjectWatcher::Delegate { |
| 20 public: | 21 public: |
| 21 explicit TimerExpiredTask(base::ProcessHandle process) : process_(process) { | 22 explicit TimerExpiredTask(base::ProcessHandle process) : process_(process) { |
| 22 watcher_.StartWatching(process_, this); | 23 watcher_.StartWatching(process_, this); |
| 23 } | 24 } |
| 24 | 25 |
| 25 virtual ~TimerExpiredTask() { | 26 virtual ~TimerExpiredTask() { |
| 26 if (process_) { | 27 if (process_) { |
| 27 KillProcess(); | 28 KillProcess(); |
| 28 DCHECK(!process_) << "Make sure to close the handle."; | 29 DCHECK(!process_) << "Make sure to close the handle."; |
| 29 } | 30 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // it fails quite often. This should be investigated eventually. | 66 // it fails quite often. This should be investigated eventually. |
| 66 base::KillProcess(process_, ResultCodes::HUNG, false); | 67 base::KillProcess(process_, ResultCodes::HUNG, false); |
| 67 | 68 |
| 68 // Now, just cleanup as if the process exited normally. | 69 // Now, just cleanup as if the process exited normally. |
| 69 OnObjectSignaled(process_); | 70 OnObjectSignaled(process_); |
| 70 } | 71 } |
| 71 | 72 |
| 72 // The process that we are watching. | 73 // The process that we are watching. |
| 73 base::ProcessHandle process_; | 74 base::ProcessHandle process_; |
| 74 | 75 |
| 75 base::ObjectWatcher watcher_; | 76 base::win::ObjectWatcher watcher_; |
| 76 | 77 |
| 77 DISALLOW_COPY_AND_ASSIGN(TimerExpiredTask); | 78 DISALLOW_COPY_AND_ASSIGN(TimerExpiredTask); |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 } // namespace | 81 } // namespace |
| 81 | 82 |
| 82 // static | 83 // static |
| 83 void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process) { | 84 void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process) { |
| 84 DCHECK(process != GetCurrentProcess()); | 85 DCHECK(process != GetCurrentProcess()); |
| 85 | 86 |
| 86 // If already signaled, then we are done! | 87 // If already signaled, then we are done! |
| 87 if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) { | 88 if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) { |
| 88 CloseHandle(process); | 89 CloseHandle(process); |
| 89 return; | 90 return; |
| 90 } | 91 } |
| 91 | 92 |
| 92 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 93 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 93 new TimerExpiredTask(process), | 94 new TimerExpiredTask(process), |
| 94 kWaitInterval); | 95 kWaitInterval); |
| 95 } | 96 } |
| OLD | NEW |