| 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/env_var.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/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 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 42 // When we're called from KillProcess, the ObjectWatcher may still be | 42 // When we're called from KillProcess, the ObjectWatcher may still be |
| 43 // watching. the process handle, so make sure it has stopped. | 43 // watching. the process handle, so make sure it has stopped. |
| 44 watcher_.StopWatching(); | 44 watcher_.StopWatching(); |
| 45 | 45 |
| 46 CloseHandle(process_); | 46 CloseHandle(process_); |
| 47 process_ = NULL; | 47 process_ = NULL; |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 void KillProcess() { | 51 void KillProcess() { |
| 52 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); | 52 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 53 if (env->HasEnv(env_vars::kHeadless)) { | 53 if (env->HasEnv(env_vars::kHeadless)) { |
| 54 // If running the distributed tests, give the renderer a little time | 54 // If running the distributed tests, give the renderer a little time |
| 55 // to figure out that the channel is shutdown and unwind. | 55 // to figure out that the channel is shutdown and unwind. |
| 56 if (WaitForSingleObject(process_, kWaitInterval) == WAIT_OBJECT_0) { | 56 if (WaitForSingleObject(process_, kWaitInterval) == WAIT_OBJECT_0) { |
| 57 OnObjectSignaled(process_); | 57 OnObjectSignaled(process_); |
| 58 return; | 58 return; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 // OK, time to get frisky. We don't actually care when the process | 62 // OK, time to get frisky. We don't actually care when the process |
| (...skipping 23 matching lines...) Expand all Loading... |
| 86 // If already signaled, then we are done! | 86 // If already signaled, then we are done! |
| 87 if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) { | 87 if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) { |
| 88 CloseHandle(process); | 88 CloseHandle(process); |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 | 91 |
| 92 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 92 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 93 new TimerExpiredTask(process), | 93 new TimerExpiredTask(process), |
| 94 kWaitInterval); | 94 kWaitInterval); |
| 95 } | 95 } |
| OLD | NEW |