Simple Cache: a few tests for rare corner cases with CRC check missing.
[chromium-blink-merge.git] / base / process.h
blob84b857935c5da9b542b898c658c0e6684b4ae7fd
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 #ifndef BASE_PROCESS_H_
6 #define BASE_PROCESS_H_
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "build/build_config.h"
12 #include <sys/types.h>
13 #if defined(OS_WIN)
14 #include <windows.h>
15 #endif
17 namespace base {
19 // ProcessHandle is a platform specific type which represents the underlying OS
20 // handle to a process.
21 // ProcessId is a number which identifies the process in the OS.
22 #if defined(OS_WIN)
23 typedef HANDLE ProcessHandle;
24 typedef DWORD ProcessId;
25 typedef HANDLE UserTokenHandle;
26 const ProcessHandle kNullProcessHandle = NULL;
27 const ProcessId kNullProcessId = 0;
28 #elif defined(OS_POSIX)
29 // On POSIX, our ProcessHandle will just be the PID.
30 typedef pid_t ProcessHandle;
31 typedef pid_t ProcessId;
32 const ProcessHandle kNullProcessHandle = 0;
33 const ProcessId kNullProcessId = 0;
34 #endif // defined(OS_WIN)
36 class BASE_EXPORT Process {
37 public:
38 Process() : process_(kNullProcessHandle) {
41 explicit Process(ProcessHandle handle) : process_(handle) {
44 // A handle to the current process.
45 static Process Current();
47 static bool CanBackgroundProcesses();
49 // Get/Set the handle for this process. The handle will be 0 if the process
50 // is no longer running.
51 ProcessHandle handle() const { return process_; }
52 void set_handle(ProcessHandle handle) {
53 process_ = handle;
56 // Get the PID for this process.
57 ProcessId pid() const;
59 // Is the this process the current process.
60 bool is_current() const;
62 // Close the process handle. This will not terminate the process.
63 void Close();
65 // Terminates the process with extreme prejudice. The given result code will
66 // be the exit code of the process. If the process has already exited, this
67 // will do nothing.
68 void Terminate(int result_code);
70 // A process is backgrounded when it's priority is lower than normal.
71 // Return true if this process is backgrounded, false otherwise.
72 bool IsProcessBackgrounded() const;
74 // Set a process as backgrounded. If value is true, the priority
75 // of the process will be lowered. If value is false, the priority
76 // of the process will be made "normal" - equivalent to default
77 // process priority.
78 // Returns true if the priority was changed, false otherwise.
79 bool SetProcessBackgrounded(bool value);
81 // Returns an integer representing the priority of a process. The meaning
82 // of this value is OS dependent.
83 int GetPriority() const;
85 private:
86 ProcessHandle process_;
89 } // namespace base
91 #endif // BASE_PROCESS_H_