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

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

Issue 4079: Porting refactoring changes:... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 2 months 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
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 "chrome/app/result_codes.h" 10 #include "chrome/app/result_codes.h"
10 #include "chrome/common/env_util.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(ProcessHandle process) : process_(process) {
(...skipping 20 matching lines...) Expand all
41 // When we're called from KillProcess, the ObjectWatcher may still be 41 // When we're called from KillProcess, the ObjectWatcher may still be
42 // watching. the process handle, so make sure it has stopped. 42 // watching. the process handle, so make sure it has stopped.
43 watcher_.StopWatching(); 43 watcher_.StopWatching();
44 44
45 CloseHandle(process_); 45 CloseHandle(process_);
46 process_ = NULL; 46 process_ = NULL;
47 } 47 }
48 48
49 private: 49 private:
50 void KillProcess() { 50 void KillProcess() {
51 if (env_util::HasEnvironmentVariable(env_vars::kHeadless)) { 51 if (base::SysInfo::HasEnvironmentVariable(env_vars::kHeadless)) {
52 // If running the distributed tests, give the renderer a little time to fig ure out 52 // If running the distributed tests, give the renderer a little time
53 // that the channel is shutdown and unwind. 53 // to figure out that the channel is shutdown and unwind.
54 if (WaitForSingleObject(process_, kWaitInterval) == WAIT_OBJECT_0) { 54 if (WaitForSingleObject(process_, kWaitInterval) == WAIT_OBJECT_0) {
55 OnObjectSignaled(process_); 55 OnObjectSignaled(process_);
56 return; 56 return;
57 } 57 }
58 } 58 }
59 59
60 // OK, time to get frisky. We don't actually care when the process 60 // OK, time to get frisky. We don't actually care when the process
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.
(...skipping 21 matching lines...) Expand all
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

Powered by Google App Engine
This is Rietveld 408576698