OLD | NEW |
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 "base/process.h" | 5 #include "base/process.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
11 | 11 |
12 void Process::Close() { | 12 void Process::Close() { |
13 if (!process_) | 13 if (!process_) |
14 return; | 14 return; |
15 ::CloseHandle(process_); | 15 ::CloseHandle(process_); |
16 process_ = NULL; | 16 process_ = NULL; |
17 } | 17 } |
18 | 18 |
19 void Process::Terminate(int result_code) { | 19 void Process::Terminate(int result_code) { |
20 if (!process_) | 20 if (!process_) |
21 return; | 21 return; |
22 ::TerminateProcess(process_, result_code); | 22 ::TerminateProcess(process_, result_code); |
23 } | 23 } |
24 | 24 |
25 bool Process::IsProcessBackgrounded() const { | 25 bool Process::IsProcessBackgrounded() const { |
26 DCHECK(process_); | 26 if (!process_) |
| 27 return false; // Failure case. |
27 DWORD priority = GetPriorityClass(process_); | 28 DWORD priority = GetPriorityClass(process_); |
28 if (priority == 0) | 29 if (priority == 0) |
29 return false; // Failure case. | 30 return false; // Failure case. |
30 return priority == BELOW_NORMAL_PRIORITY_CLASS; | 31 return priority == BELOW_NORMAL_PRIORITY_CLASS; |
31 } | 32 } |
32 | 33 |
33 bool Process::SetProcessBackgrounded(bool value) { | 34 bool Process::SetProcessBackgrounded(bool value) { |
34 DCHECK(process_); | 35 if (!process_) |
| 36 return false; |
35 DWORD priority = value ? BELOW_NORMAL_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS; | 37 DWORD priority = value ? BELOW_NORMAL_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS; |
36 return (SetPriorityClass(process_, priority) != 0); | 38 return (SetPriorityClass(process_, priority) != 0); |
37 } | 39 } |
38 | 40 |
39 // According to MSDN, these are the default values which XP | 41 // According to MSDN, these are the default values which XP |
40 // uses to govern working set soft limits. | 42 // uses to govern working set soft limits. |
41 // http://msdn.microsoft.com/en-us/library/ms686234.aspx | 43 // http://msdn.microsoft.com/en-us/library/ms686234.aspx |
42 static const int kWinDefaultMinSet = 50 * 4096; | 44 static const int kWinDefaultMinSet = 50 * 4096; |
43 static const int kWinDefaultMaxSet = 345 * 4096; | 45 static const int kWinDefaultMaxSet = 345 * 4096; |
44 static const int kDampingFactor = 2; | 46 static const int kDampingFactor = 2; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 bool Process::is_current() const { | 119 bool Process::is_current() const { |
118 return process_ == GetCurrentProcess(); | 120 return process_ == GetCurrentProcess(); |
119 } | 121 } |
120 | 122 |
121 // static | 123 // static |
122 Process Process::Current() { | 124 Process Process::Current() { |
123 return Process(GetCurrentProcess()); | 125 return Process(GetCurrentProcess()); |
124 } | 126 } |
125 | 127 |
126 } // namespace base | 128 } // namespace base |
OLD | NEW |