michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/process.h" michael@0: #include "base/logging.h" michael@0: #include "base/process_util.h" michael@0: #include "base/scoped_ptr.h" michael@0: michael@0: namespace base { michael@0: michael@0: void Process::Close() { michael@0: if (!process_) michael@0: return; michael@0: CloseProcessHandle(process_); michael@0: process_ = NULL; michael@0: } michael@0: michael@0: void Process::Terminate(int result_code) { michael@0: if (!process_) michael@0: return; michael@0: ::TerminateProcess(process_, result_code); michael@0: } michael@0: michael@0: bool Process::IsProcessBackgrounded() const { michael@0: DCHECK(process_); michael@0: DWORD priority = GetPriorityClass(process_); michael@0: if (priority == 0) michael@0: return false; // Failure case. michael@0: return priority == BELOW_NORMAL_PRIORITY_CLASS; michael@0: } michael@0: michael@0: bool Process::SetProcessBackgrounded(bool value) { michael@0: DCHECK(process_); michael@0: DWORD priority = value ? BELOW_NORMAL_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS; michael@0: return (SetPriorityClass(process_, priority) != 0); michael@0: } michael@0: michael@0: bool Process::EmptyWorkingSet() { michael@0: if (!process_) michael@0: return false; michael@0: michael@0: BOOL rv = SetProcessWorkingSetSize(process_, -1, -1); michael@0: return rv == TRUE; michael@0: } michael@0: michael@0: ProcessId Process::pid() const { michael@0: if (process_ == 0) michael@0: return 0; michael@0: michael@0: return GetProcId(process_); michael@0: } michael@0: michael@0: bool Process::is_current() const { michael@0: return process_ == GetCurrentProcess(); michael@0: } michael@0: michael@0: // static michael@0: Process Process::Current() { michael@0: return Process(GetCurrentProcess()); michael@0: } michael@0: michael@0: } // namespace base