|
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 |
|
3 // found in the LICENSE file. |
|
4 |
|
5 #include "base/process.h" |
|
6 #include "base/logging.h" |
|
7 #include "base/process_util.h" |
|
8 #include "base/scoped_ptr.h" |
|
9 |
|
10 namespace base { |
|
11 |
|
12 void Process::Close() { |
|
13 if (!process_) |
|
14 return; |
|
15 CloseProcessHandle(process_); |
|
16 process_ = NULL; |
|
17 } |
|
18 |
|
19 void Process::Terminate(int result_code) { |
|
20 if (!process_) |
|
21 return; |
|
22 ::TerminateProcess(process_, result_code); |
|
23 } |
|
24 |
|
25 bool Process::IsProcessBackgrounded() const { |
|
26 DCHECK(process_); |
|
27 DWORD priority = GetPriorityClass(process_); |
|
28 if (priority == 0) |
|
29 return false; // Failure case. |
|
30 return priority == BELOW_NORMAL_PRIORITY_CLASS; |
|
31 } |
|
32 |
|
33 bool Process::SetProcessBackgrounded(bool value) { |
|
34 DCHECK(process_); |
|
35 DWORD priority = value ? BELOW_NORMAL_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS; |
|
36 return (SetPriorityClass(process_, priority) != 0); |
|
37 } |
|
38 |
|
39 bool Process::EmptyWorkingSet() { |
|
40 if (!process_) |
|
41 return false; |
|
42 |
|
43 BOOL rv = SetProcessWorkingSetSize(process_, -1, -1); |
|
44 return rv == TRUE; |
|
45 } |
|
46 |
|
47 ProcessId Process::pid() const { |
|
48 if (process_ == 0) |
|
49 return 0; |
|
50 |
|
51 return GetProcId(process_); |
|
52 } |
|
53 |
|
54 bool Process::is_current() const { |
|
55 return process_ == GetCurrentProcess(); |
|
56 } |
|
57 |
|
58 // static |
|
59 Process Process::Current() { |
|
60 return Process(GetCurrentProcess()); |
|
61 } |
|
62 |
|
63 } // namespace base |