Port PluginObject fix downstream. See http://trac.webkit.org/changeset/61415/ for...
[chromium-blink-merge.git] / base / process_win.cc
blobcdb9390aa90128ac76056eca39a0449283935f09
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.
5 #include "base/process.h"
6 #include "base/logging.h"
7 #include "base/process_util.h"
8 #include "base/scoped_ptr.h"
10 namespace base {
12 void Process::Close() {
13 if (!process_)
14 return;
15 ::CloseHandle(process_);
16 process_ = NULL;
19 void Process::Terminate(int result_code) {
20 if (!process_)
21 return;
22 ::TerminateProcess(process_, result_code);
25 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;
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);
41 ProcessId Process::pid() const {
42 if (process_ == 0)
43 return 0;
45 return GetProcId(process_);
48 bool Process::is_current() const {
49 return process_ == GetCurrentProcess();
52 // static
53 Process Process::Current() {
54 return Process(GetCurrentProcess());
57 int Process::GetPriority() const {
58 DCHECK(process_);
59 return GetPriorityClass(process_);
62 } // namespace base