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. 4 5 #ifndef BASE_PROCESS_PROCESS_PROCESS_H_ 6 #define BASE_PROCESS_PROCESS_PROCESS_H_ 7 8 #include "base/base_export.h" 9 #include "base/basictypes.h" 10 #include "base/process/process_handle.h" 11 #include "build/build_config.h" 12 13 namespace base { 14 15 class BASE_EXPORT Process { 16 public: 17 Process() : process_(kNullProcessHandle) { 18 } 19 20 explicit Process(ProcessHandle handle) : process_(handle) { 21 } 22 23 // A handle to the current process. 24 static Process Current(); 25 26 static bool CanBackgroundProcesses(); 27 28 // Get/Set the handle for this process. The handle will be 0 if the process 29 // is no longer running. 30 ProcessHandle handle() const { return process_; } 31 void set_handle(ProcessHandle handle) { 32 process_ = handle; 33 } 34 35 // Get the PID for this process. 36 ProcessId pid() const; 37 38 // Is the this process the current process. 39 bool is_current() const; 40 41 // Close the process handle. This will not terminate the process. 42 void Close(); 43 44 // Terminates the process with extreme prejudice. The given result code will 45 // be the exit code of the process. If the process has already exited, this 46 // will do nothing. 47 void Terminate(int result_code); 48 49 // A process is backgrounded when it's priority is lower than normal. 50 // Return true if this process is backgrounded, false otherwise. 51 bool IsProcessBackgrounded() const; 52 53 // Set a process as backgrounded. If value is true, the priority 54 // of the process will be lowered. If value is false, the priority 55 // of the process will be made "normal" - equivalent to default 56 // process priority. 57 // Returns true if the priority was changed, false otherwise. 58 bool SetProcessBackgrounded(bool value); 59 60 // Returns an integer representing the priority of a process. The meaning 61 // of this value is OS dependent. 62 int GetPriority() const; 63 64 private: 65 ProcessHandle process_; 66 }; 67 68 } // namespace base 69 70 #endif // BASE_PROCESS_PROCESS_PROCESS_H_ 71