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 "content/common/process_watcher.h" |
6 | 6 |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/environment.h" | |
9 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
10 #include "base/win/object_watcher.h" | 9 #include "base/win/object_watcher.h" |
11 #include "chrome/common/env_vars.h" | 10 #include "content/common/result_codes.h" |
12 #include "chrome/common/result_codes.h" | |
13 | 11 |
14 // Maximum amount of time (in milliseconds) to wait for the process to exit. | 12 // Maximum amount of time (in milliseconds) to wait for the process to exit. |
15 static const int kWaitInterval = 2000; | 13 static const int kWaitInterval = 2000; |
16 | 14 |
17 namespace { | 15 namespace { |
18 | 16 |
19 class TimerExpiredTask : public Task, | 17 class TimerExpiredTask : public Task, |
20 public base::win::ObjectWatcher::Delegate { | 18 public base::win::ObjectWatcher::Delegate { |
21 public: | 19 public: |
22 explicit TimerExpiredTask(base::ProcessHandle process) : process_(process) { | 20 explicit TimerExpiredTask(base::ProcessHandle process) : process_(process) { |
(...skipping 20 matching lines...) Expand all Loading... |
43 // When we're called from KillProcess, the ObjectWatcher may still be | 41 // When we're called from KillProcess, the ObjectWatcher may still be |
44 // watching. the process handle, so make sure it has stopped. | 42 // watching. the process handle, so make sure it has stopped. |
45 watcher_.StopWatching(); | 43 watcher_.StopWatching(); |
46 | 44 |
47 CloseHandle(process_); | 45 CloseHandle(process_); |
48 process_ = NULL; | 46 process_ = NULL; |
49 } | 47 } |
50 | 48 |
51 private: | 49 private: |
52 void KillProcess() { | 50 void KillProcess() { |
53 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
54 if (env->HasVar(env_vars::kHeadless)) { | |
55 // If running the distributed tests, give the renderer a little time | |
56 // to figure out that the channel is shutdown and unwind. | |
57 if (WaitForSingleObject(process_, kWaitInterval) == WAIT_OBJECT_0) { | |
58 OnObjectSignaled(process_); | |
59 return; | |
60 } | |
61 } | |
62 | |
63 // OK, time to get frisky. We don't actually care when the process | 51 // OK, time to get frisky. We don't actually care when the process |
64 // terminates. We just care that it eventually terminates, and that's what | 52 // terminates. We just care that it eventually terminates, and that's what |
65 // TerminateProcess should do for us. Don't check for the result code since | 53 // TerminateProcess should do for us. Don't check for the result code since |
66 // it fails quite often. This should be investigated eventually. | 54 // it fails quite often. This should be investigated eventually. |
67 base::KillProcess(process_, ResultCodes::HUNG, false); | 55 base::KillProcess(process_, ResultCodes::HUNG, false); |
68 | 56 |
69 // Now, just cleanup as if the process exited normally. | 57 // Now, just cleanup as if the process exited normally. |
70 OnObjectSignaled(process_); | 58 OnObjectSignaled(process_); |
71 } | 59 } |
72 | 60 |
(...skipping 14 matching lines...) Expand all Loading... |
87 // If already signaled, then we are done! | 75 // If already signaled, then we are done! |
88 if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) { | 76 if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) { |
89 CloseHandle(process); | 77 CloseHandle(process); |
90 return; | 78 return; |
91 } | 79 } |
92 | 80 |
93 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 81 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
94 new TimerExpiredTask(process), | 82 new TimerExpiredTask(process), |
95 kWaitInterval); | 83 kWaitInterval); |
96 } | 84 } |
OLD | NEW |