Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: chrome/common/process_watcher.cc

Issue 10895: Add Terminate() to the Process object, have RenderProcessHost use this to avo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/process_watcher.h ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/object_watcher.h" 8 #include "base/object_watcher.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "chrome/app/result_codes.h" 10 #include "chrome/app/result_codes.h"
11 #include "chrome/common/env_vars.h" 11 #include "chrome/common/env_vars.h"
12 12
13 // Maximum amount of time (in milliseconds) to wait for the process to exit. 13 // Maximum amount of time (in milliseconds) to wait for the process to exit.
14 static const int kWaitInterval = 2000; 14 static const int kWaitInterval = 2000;
15 15
16 namespace { 16 namespace {
17 17
18 class TimerExpiredTask : public Task, public base::ObjectWatcher::Delegate { 18 class TimerExpiredTask : public Task, public base::ObjectWatcher::Delegate {
19 public: 19 public:
20 explicit TimerExpiredTask(ProcessHandle process) : process_(process) { 20 explicit TimerExpiredTask(base::ProcessHandle process) : process_(process) {
21 watcher_.StartWatching(process_, this); 21 watcher_.StartWatching(process_, this);
22 } 22 }
23 23
24 virtual ~TimerExpiredTask() { 24 virtual ~TimerExpiredTask() {
25 if (process_) { 25 if (process_) {
26 KillProcess(); 26 KillProcess();
27 DCHECK(!process_) << "Make sure to close the handle."; 27 DCHECK(!process_) << "Make sure to close the handle.";
28 } 28 }
29 } 29 }
30 30
(...skipping 30 matching lines...) Expand all
61 // terminates. We just care that it eventually terminates, and that's what 61 // terminates. We just care that it eventually terminates, and that's what
62 // TerminateProcess should do for us. Don't check for the result code since 62 // TerminateProcess should do for us. Don't check for the result code since
63 // it fails quite often. This should be investigated eventually. 63 // it fails quite often. This should be investigated eventually.
64 TerminateProcess(process_, ResultCodes::HUNG); 64 TerminateProcess(process_, ResultCodes::HUNG);
65 65
66 // Now, just cleanup as if the process exited normally. 66 // Now, just cleanup as if the process exited normally.
67 OnObjectSignaled(process_); 67 OnObjectSignaled(process_);
68 } 68 }
69 69
70 // The process that we are watching. 70 // The process that we are watching.
71 ProcessHandle process_; 71 base::ProcessHandle process_;
72 72
73 base::ObjectWatcher watcher_; 73 base::ObjectWatcher watcher_;
74 74
75 DISALLOW_EVIL_CONSTRUCTORS(TimerExpiredTask); 75 DISALLOW_EVIL_CONSTRUCTORS(TimerExpiredTask);
76 }; 76 };
77 77
78 } // namespace 78 } // namespace
79 79
80 // static 80 // static
81 void ProcessWatcher::EnsureProcessTerminated(ProcessHandle process) { 81 void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process) {
82 DCHECK(process != GetCurrentProcess()); 82 DCHECK(process != GetCurrentProcess());
83 83
84 // If already signaled, then we are done! 84 // If already signaled, then we are done!
85 if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) { 85 if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) {
86 CloseHandle(process); 86 CloseHandle(process);
87 return; 87 return;
88 } 88 }
89 89
90 MessageLoop::current()->PostDelayedTask(FROM_HERE, 90 MessageLoop::current()->PostDelayedTask(FROM_HERE,
91 new TimerExpiredTask(process), 91 new TimerExpiredTask(process),
92 kWaitInterval); 92 kWaitInterval);
93 } 93 }
94 94
OLDNEW
« no previous file with comments | « chrome/common/process_watcher.h ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698