| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_PROCESS_H__ | 5 #ifndef BASE_PROCESS_H_ |
| 6 #define BASE_PROCESS_H__ | 6 #define BASE_PROCESS_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 | 9 |
| 10 #ifdef OS_WIN | 10 #ifdef OS_WIN |
| 11 #include <windows.h> | 11 #include <windows.h> |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 namespace base { |
| 15 |
| 14 // ProcessHandle is a platform specific type which represents the underlying OS | 16 // ProcessHandle is a platform specific type which represents the underlying OS |
| 15 // handle to a process. | 17 // handle to a process. |
| 16 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 17 typedef HANDLE ProcessHandle; | 19 typedef HANDLE ProcessHandle; |
| 18 #elif defined(OS_POSIX) | 20 #elif defined(OS_POSIX) |
| 19 // On POSIX, our ProcessHandle will just be the PID. | 21 // On POSIX, our ProcessHandle will just be the PID. |
| 20 typedef int ProcessHandle; | 22 typedef int ProcessHandle; |
| 21 #endif | 23 #endif |
| 22 | 24 |
| 23 // A Process | |
| 24 // TODO(mbelshe): Replace existing code which uses the ProcessHandle w/ the | |
| 25 // Process object where relevant. | |
| 26 class Process { | 25 class Process { |
| 27 public: | 26 public: |
| 28 Process() : process_(0), last_working_set_size_(0) {} | 27 Process() : process_(0), last_working_set_size_(0) {} |
| 29 explicit Process(ProcessHandle handle) : | 28 explicit Process(ProcessHandle handle) : |
| 30 process_(handle), last_working_set_size_(0) {} | 29 process_(handle), last_working_set_size_(0) {} |
| 31 | 30 |
| 32 // A handle to the current process. | 31 // A handle to the current process. |
| 33 static Process Current(); | 32 static Process Current(); |
| 34 | 33 |
| 35 // Get/Set the handle for this process. The handle will be 0 if the process | 34 // Get/Set the handle for this process. The handle will be 0 if the process |
| 36 // is no longer running. | 35 // is no longer running. |
| 37 ProcessHandle handle() const { return process_; } | 36 ProcessHandle handle() const { return process_; } |
| 38 void set_handle(ProcessHandle handle) { process_ = handle; } | 37 void set_handle(ProcessHandle handle) { process_ = handle; } |
| 39 | 38 |
| 40 // Get the PID for this process. | 39 // Get the PID for this process. |
| 41 int32 pid() const; | 40 int32 pid() const; |
| 42 | 41 |
| 43 // Is the this process the current process. | 42 // Is the this process the current process. |
| 44 bool is_current() const; | 43 bool is_current() const; |
| 45 | 44 |
| 46 // Close the Process Handle. | 45 // Close the process handle. This will not terminate the process. |
| 47 void Close() { | 46 void Close(); |
| 48 #ifdef OS_WIN | 47 |
| 49 CloseHandle(process_); | 48 // Terminates the process with extreme prejudice. The given result code will |
| 50 #endif | 49 // be the exit code of the process. If the process has already exited, this |
| 51 process_ = 0; | 50 // will do nothing. |
| 52 } | 51 void Terminate(int result_code); |
| 53 | 52 |
| 54 // A process is backgrounded when it's priority is lower than normal. | 53 // A process is backgrounded when it's priority is lower than normal. |
| 55 // Return true if this process is backgrounded, false otherwise. | 54 // Return true if this process is backgrounded, false otherwise. |
| 56 bool IsProcessBackgrounded() const; | 55 bool IsProcessBackgrounded() const; |
| 57 | 56 |
| 58 // Set a prcess as backgrounded. If value is true, the priority | 57 // Set a prcess as backgrounded. If value is true, the priority |
| 59 // of the process will be lowered. If value is false, the priority | 58 // of the process will be lowered. If value is false, the priority |
| 60 // of the process will be made "normal" - equivalent to default | 59 // of the process will be made "normal" - equivalent to default |
| 61 // process priority. | 60 // process priority. |
| 62 // Returns true if the priority was changed, false otherwise. | 61 // Returns true if the priority was changed, false otherwise. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 78 | 77 |
| 79 // Releases as much of the working set back to the OS as possible. | 78 // Releases as much of the working set back to the OS as possible. |
| 80 // Returns true if successful, false otherwise. | 79 // Returns true if successful, false otherwise. |
| 81 bool EmptyWorkingSet(); | 80 bool EmptyWorkingSet(); |
| 82 | 81 |
| 83 private: | 82 private: |
| 84 ProcessHandle process_; | 83 ProcessHandle process_; |
| 85 size_t last_working_set_size_; | 84 size_t last_working_set_size_; |
| 86 }; | 85 }; |
| 87 | 86 |
| 88 #endif // BASE_PROCESS_H__ | 87 } // namespace base |
| 89 | 88 |
| 89 #endif // BASE_PROCESS_H_ |
| 90 |
| OLD | NEW |