cc: Fix MSAA when threaded GPU rasterization is enabled.
[chromium-blink-merge.git] / base / process / process_posix.cc
blobbc2f3f8bfa628febe97f73a21120525306b6d515
1 // Copyright (c) 2011 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/process.h"
7 #include <sys/resource.h>
8 #include <sys/time.h>
9 #include <sys/types.h>
11 #include "base/logging.h"
12 #include "base/process/kill.h"
14 namespace base {
16 Process::Process(ProcessHandle handle) : process_(handle) {
19 Process::Process(RValue other)
20 : process_(other.object->process_) {
21 other.object->Close();
24 Process& Process::operator=(RValue other) {
25 if (this != other.object) {
26 process_ = other.object->process_;
27 other.object->Close();
29 return *this;
32 // static
33 Process Process::Current() {
34 return Process(GetCurrentProcessHandle());
37 // static
38 Process Process::Open(ProcessId pid) {
39 if (pid == GetCurrentProcId())
40 return Current();
42 // On POSIX process handles are the same as PIDs.
43 return Process(pid);
46 // static
47 Process Process::OpenWithExtraPriviles(ProcessId pid) {
48 // On POSIX there are no privileges to set.
49 return Open(pid);
52 // static
53 Process Process::DeprecatedGetProcessFromHandle(ProcessHandle handle) {
54 DCHECK_NE(handle, GetCurrentProcessHandle());
55 return Process(handle);
58 #if !defined(OS_LINUX)
59 // static
60 bool Process::CanBackgroundProcesses() {
61 return false;
63 #endif // !defined(OS_LINUX)
65 bool Process::IsValid() const {
66 return process_ != kNullProcessHandle;
69 ProcessHandle Process::Handle() const {
70 return process_;
73 Process Process::Duplicate() const {
74 if (is_current())
75 return Current();
77 return Process(process_);
80 ProcessId Process::Pid() const {
81 DCHECK(IsValid());
82 return GetProcId(process_);
85 bool Process::is_current() const {
86 return process_ == GetCurrentProcessHandle();
89 void Process::Close() {
90 process_ = kNullProcessHandle;
91 // if the process wasn't terminated (so we waited) or the state
92 // wasn't already collected w/ a wait from process_utils, we're gonna
93 // end up w/ a zombie when it does finally exit.
96 void Process::Terminate(int result_code) {
97 // result_code isn't supportable.
98 DCHECK(IsValid());
99 // We don't wait here. It's the responsibility of other code to reap the
100 // child.
101 KillProcess(process_, result_code, false);
104 bool Process::WaitForExit(int* exit_code) {
105 // TODO(rvargas) crbug.com/417532: Remove this constant.
106 const int kNoTimeout = -1;
107 return WaitForExitWithTimeout(TimeDelta::FromMilliseconds(kNoTimeout),
108 exit_code);
111 bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) {
112 // TODO(rvargas) crbug.com/417532: Move the implementation here.
113 return base::WaitForExitCodeWithTimeout(Handle(), exit_code, timeout);
116 #if !defined(OS_LINUX)
117 bool Process::IsProcessBackgrounded() const {
118 // See SetProcessBackgrounded().
119 DCHECK(IsValid());
120 return false;
123 bool Process::SetProcessBackgrounded(bool value) {
124 // POSIX only allows lowering the priority of a process, so if we
125 // were to lower it we wouldn't be able to raise it back to its initial
126 // priority.
127 DCHECK(IsValid());
128 return false;
130 #endif // !defined(OS_LINUX)
132 int Process::GetPriority() const {
133 DCHECK(IsValid());
134 return getpriority(PRIO_PROCESS, process_);
137 } // namspace base