Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_PROCESS_H_ |
michael@0 | 6 | #define BASE_PROCESS_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include "base/basictypes.h" |
michael@0 | 9 | |
michael@0 | 10 | #include <sys/types.h> |
michael@0 | 11 | #ifdef OS_WIN |
michael@0 | 12 | #include <windows.h> |
michael@0 | 13 | #endif |
michael@0 | 14 | |
michael@0 | 15 | namespace base { |
michael@0 | 16 | |
michael@0 | 17 | // ProcessHandle is a platform specific type which represents the underlying OS |
michael@0 | 18 | // handle to a process. |
michael@0 | 19 | // ProcessId is a number which identifies the process in the OS. |
michael@0 | 20 | #if defined(OS_WIN) |
michael@0 | 21 | typedef HANDLE ProcessHandle; |
michael@0 | 22 | typedef DWORD ProcessId; |
michael@0 | 23 | #elif defined(OS_POSIX) |
michael@0 | 24 | // On POSIX, our ProcessHandle will just be the PID. |
michael@0 | 25 | typedef pid_t ProcessHandle; |
michael@0 | 26 | typedef pid_t ProcessId; |
michael@0 | 27 | #endif |
michael@0 | 28 | |
michael@0 | 29 | class Process { |
michael@0 | 30 | public: |
michael@0 | 31 | Process() : process_(0), last_working_set_size_(0) {} |
michael@0 | 32 | explicit Process(ProcessHandle handle) : |
michael@0 | 33 | process_(handle), last_working_set_size_(0) {} |
michael@0 | 34 | |
michael@0 | 35 | // A handle to the current process. |
michael@0 | 36 | static Process Current(); |
michael@0 | 37 | |
michael@0 | 38 | // Get/Set the handle for this process. The handle will be 0 if the process |
michael@0 | 39 | // is no longer running. |
michael@0 | 40 | ProcessHandle handle() const { return process_; } |
michael@0 | 41 | void set_handle(ProcessHandle handle) { process_ = handle; } |
michael@0 | 42 | |
michael@0 | 43 | // Get the PID for this process. |
michael@0 | 44 | ProcessId pid() const; |
michael@0 | 45 | |
michael@0 | 46 | // Is the this process the current process. |
michael@0 | 47 | bool is_current() const; |
michael@0 | 48 | |
michael@0 | 49 | // Close the process handle. This will not terminate the process. |
michael@0 | 50 | void Close(); |
michael@0 | 51 | |
michael@0 | 52 | // Terminates the process with extreme prejudice. The given result code will |
michael@0 | 53 | // be the exit code of the process. If the process has already exited, this |
michael@0 | 54 | // will do nothing. |
michael@0 | 55 | void Terminate(int result_code); |
michael@0 | 56 | |
michael@0 | 57 | // A process is backgrounded when it's priority is lower than normal. |
michael@0 | 58 | // Return true if this process is backgrounded, false otherwise. |
michael@0 | 59 | bool IsProcessBackgrounded() const; |
michael@0 | 60 | |
michael@0 | 61 | // Set a prcess as backgrounded. If value is true, the priority |
michael@0 | 62 | // of the process will be lowered. If value is false, the priority |
michael@0 | 63 | // of the process will be made "normal" - equivalent to default |
michael@0 | 64 | // process priority. |
michael@0 | 65 | // Returns true if the priority was changed, false otherwise. |
michael@0 | 66 | bool SetProcessBackgrounded(bool value); |
michael@0 | 67 | |
michael@0 | 68 | // Releases as much of the working set back to the OS as possible. |
michael@0 | 69 | // Returns true if successful, false otherwise. |
michael@0 | 70 | bool EmptyWorkingSet(); |
michael@0 | 71 | |
michael@0 | 72 | private: |
michael@0 | 73 | ProcessHandle process_; |
michael@0 | 74 | size_t last_working_set_size_; |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | } // namespace base |
michael@0 | 78 | |
michael@0 | 79 | #endif // BASE_PROCESS_H_ |