process_win.cc revision c7f5f8508d98d5952d42ed7648c2a8f30a4da156
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 10namespace base { 11 12void Process::Close() { 13 if (!process_) 14 return; 15 ::CloseHandle(process_); 16 process_ = NULL; 17} 18 19void Process::Terminate(int result_code) { 20 if (!process_) 21 return; 22 ::TerminateProcess(process_, result_code); 23} 24 25bool 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 34bool 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 41ProcessId Process::pid() const { 42 if (process_ == 0) 43 return 0; 44 45 return GetProcId(process_); 46} 47 48bool Process::is_current() const { 49 return process_ == GetCurrentProcess(); 50} 51 52// static 53Process Process::Current() { 54 return Process(GetCurrentProcess()); 55} 56 57int Process::GetPriority() const { 58 DCHECK(process_); 59 return GetPriorityClass(process_); 60} 61 62} // namespace base 63