blob: 7869b886455a9826f968e7a189bcbd27bf020d96 [file] [log] [blame]
[email protected]26fbf802011-03-25 18:48:031// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
[email protected]176aa482008-11-14 03:25:155#ifndef BASE_PROCESS_H_
6#define BASE_PROCESS_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commitd7cae122008-07-26 21:49:388
[email protected]0bea7252011-08-05 15:34:009#include "base/base_export.h"
initial.commitd7cae122008-07-26 21:49:3810#include "base/basictypes.h"
[email protected]57113ea2009-06-18 02:23:1611#include "build/build_config.h"
initial.commitd7cae122008-07-26 21:49:3812
[email protected]43cf3252009-04-01 09:19:3713#include <sys/types.h>
[email protected]b6128aa2010-04-29 17:44:4214#if defined(OS_WIN)
[email protected]61659062008-08-06 01:04:1815#include <windows.h>
16#endif
17
[email protected]176aa482008-11-14 03:25:1518namespace base {
19
initial.commitd7cae122008-07-26 21:49:3820// ProcessHandle is a platform specific type which represents the underlying OS
21// handle to a process.
[email protected]43cf3252009-04-01 09:19:3722// ProcessId is a number which identifies the process in the OS.
[email protected]61659062008-08-06 01:04:1823#if defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:3824typedef HANDLE ProcessHandle;
[email protected]43cf3252009-04-01 09:19:3725typedef DWORD ProcessId;
[email protected]e50130b2010-02-01 03:28:4726typedef HANDLE UserTokenHandle;
[email protected]659f73fa2009-10-13 13:43:4227const ProcessHandle kNullProcessHandle = NULL;
[email protected]38788d92011-04-01 22:05:1328const ProcessId kNullProcessId = 0;
[email protected]61659062008-08-06 01:04:1829#elif defined(OS_POSIX)
[email protected]db717282008-08-27 13:48:0330// On POSIX, our ProcessHandle will just be the PID.
[email protected]43cf3252009-04-01 09:19:3731typedef pid_t ProcessHandle;
32typedef pid_t ProcessId;
[email protected]659f73fa2009-10-13 13:43:4233const ProcessHandle kNullProcessHandle = 0;
[email protected]38788d92011-04-01 22:05:1334const ProcessId kNullProcessId = 0;
[email protected]b6128aa2010-04-29 17:44:4235#endif // defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:3836
[email protected]0bea7252011-08-05 15:34:0037class BASE_EXPORT Process {
initial.commitd7cae122008-07-26 21:49:3838 public:
[email protected]276aa6a2009-10-29 17:43:4439 Process() : process_(kNullProcessHandle) {
[email protected]276aa6a2009-10-29 17:43:4440 }
41
42 explicit Process(ProcessHandle handle) : process_(handle) {
[email protected]276aa6a2009-10-29 17:43:4443 }
initial.commitd7cae122008-07-26 21:49:3844
45 // A handle to the current process.
46 static Process Current();
47
[email protected]8a420802011-12-02 16:14:4648 static bool CanBackgroundProcesses();
49
[email protected]2f15de42008-11-11 22:35:1950 // Get/Set the handle for this process. The handle will be 0 if the process
51 // is no longer running.
52 ProcessHandle handle() const { return process_; }
[email protected]276aa6a2009-10-29 17:43:4453 void set_handle(ProcessHandle handle) {
54 process_ = handle;
[email protected]276aa6a2009-10-29 17:43:4455 }
initial.commitd7cae122008-07-26 21:49:3856
57 // Get the PID for this process.
[email protected]43cf3252009-04-01 09:19:3758 ProcessId pid() const;
initial.commitd7cae122008-07-26 21:49:3859
60 // Is the this process the current process.
61 bool is_current() const;
62
[email protected]176aa482008-11-14 03:25:1563 // Close the process handle. This will not terminate the process.
64 void Close();
65
66 // Terminates the process with extreme prejudice. The given result code will
67 // be the exit code of the process. If the process has already exited, this
68 // will do nothing.
69 void Terminate(int result_code);
initial.commitd7cae122008-07-26 21:49:3870
71 // A process is backgrounded when it's priority is lower than normal.
72 // Return true if this process is backgrounded, false otherwise.
[email protected]2f15de42008-11-11 22:35:1973 bool IsProcessBackgrounded() const;
initial.commitd7cae122008-07-26 21:49:3874
[email protected]276aa6a2009-10-29 17:43:4475 // Set a process as backgrounded. If value is true, the priority
76 // of the process will be lowered. If value is false, the priority
initial.commitd7cae122008-07-26 21:49:3877 // of the process will be made "normal" - equivalent to default
78 // process priority.
79 // Returns true if the priority was changed, false otherwise.
80 bool SetProcessBackgrounded(bool value);
81
[email protected]276aa6a2009-10-29 17:43:4482 // Returns an integer representing the priority of a process. The meaning
83 // of this value is OS dependent.
84 int GetPriority() const;
85
initial.commitd7cae122008-07-26 21:49:3886 private:
87 ProcessHandle process_;
initial.commitd7cae122008-07-26 21:49:3888};
89
[email protected]176aa482008-11-14 03:25:1590} // namespace base
91
92#endif // BASE_PROCESS_H_