• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
Close()12 void Process::Close() {
13   if (!process_)
14     return;
15   ::CloseHandle(process_);
16   process_ = NULL;
17 }
18 
Terminate(int result_code)19 void Process::Terminate(int result_code) {
20   if (!process_)
21     return;
22   ::TerminateProcess(process_, result_code);
23 }
24 
IsProcessBackgrounded() const25 bool Process::IsProcessBackgrounded() const {
26   if (!process_)
27     return false;  // Failure case.
28   DWORD priority = GetPriority();
29   if (priority == 0)
30     return false;  // Failure case.
31   return priority == BELOW_NORMAL_PRIORITY_CLASS;
32 }
33 
SetProcessBackgrounded(bool value)34 bool Process::SetProcessBackgrounded(bool value) {
35   if (!process_)
36     return false;
37   DWORD priority = value ? BELOW_NORMAL_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS;
38   return (SetPriorityClass(process_, priority) != 0);
39 }
40 
pid() const41 ProcessId Process::pid() const {
42   if (process_ == 0)
43     return 0;
44 
45   return GetProcId(process_);
46 }
47 
is_current() const48 bool Process::is_current() const {
49   return process_ == GetCurrentProcess();
50 }
51 
52 // static
Current()53 Process Process::Current() {
54   return Process(GetCurrentProcess());
55 }
56 
GetPriority() const57 int Process::GetPriority() const {
58   DCHECK(process_);
59   return GetPriorityClass(process_);
60 }
61 
62 }  // namespace base
63