| OLD | NEW | 
|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // This file contains methods to iterate over processes on the system. | 5 // This file contains methods to iterate over processes on the system. | 
| 6 | 6 | 
| 7 #ifndef BASE_PROCESS_PROCESS_ITERATOR_H_ | 7 #ifndef BASE_PROCESS_PROCESS_ITERATOR_H_ | 
| 8 #define BASE_PROCESS_PROCESS_ITERATOR_H_ | 8 #define BASE_PROCESS_PROCESS_ITERATOR_H_ | 
| 9 | 9 | 
| 10 #include <list> | 10 #include <list> | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 29 #endif | 29 #endif | 
| 30 | 30 | 
| 31 namespace base { | 31 namespace base { | 
| 32 | 32 | 
| 33 #if defined(OS_WIN) | 33 #if defined(OS_WIN) | 
| 34 struct ProcessEntry : public PROCESSENTRY32 { | 34 struct ProcessEntry : public PROCESSENTRY32 { | 
| 35   ProcessId pid() const { return th32ProcessID; } | 35   ProcessId pid() const { return th32ProcessID; } | 
| 36   ProcessId parent_pid() const { return th32ParentProcessID; } | 36   ProcessId parent_pid() const { return th32ParentProcessID; } | 
| 37   const wchar_t* exe_file() const { return szExeFile; } | 37   const wchar_t* exe_file() const { return szExeFile; } | 
| 38 }; | 38 }; | 
| 39 |  | 
| 40 // Process access masks. These constants provide platform-independent |  | 
| 41 // definitions for the standard Windows access masks. |  | 
| 42 // See http://msdn.microsoft.com/en-us/library/ms684880(VS.85).aspx for |  | 
| 43 // the specific semantics of each mask value. |  | 
| 44 const uint32 kProcessAccessTerminate              = PROCESS_TERMINATE; |  | 
| 45 const uint32 kProcessAccessCreateThread           = PROCESS_CREATE_THREAD; |  | 
| 46 const uint32 kProcessAccessSetSessionId           = PROCESS_SET_SESSIONID; |  | 
| 47 const uint32 kProcessAccessVMOperation            = PROCESS_VM_OPERATION; |  | 
| 48 const uint32 kProcessAccessVMRead                 = PROCESS_VM_READ; |  | 
| 49 const uint32 kProcessAccessVMWrite                = PROCESS_VM_WRITE; |  | 
| 50 const uint32 kProcessAccessDuplicateHandle        = PROCESS_DUP_HANDLE; |  | 
| 51 const uint32 kProcessAccessCreateProcess          = PROCESS_CREATE_PROCESS; |  | 
| 52 const uint32 kProcessAccessSetQuota               = PROCESS_SET_QUOTA; |  | 
| 53 const uint32 kProcessAccessSetInformation         = PROCESS_SET_INFORMATION; |  | 
| 54 const uint32 kProcessAccessQueryInformation       = PROCESS_QUERY_INFORMATION; |  | 
| 55 const uint32 kProcessAccessSuspendResume          = PROCESS_SUSPEND_RESUME; |  | 
| 56 const uint32 kProcessAccessQueryLimitedInfomation = |  | 
| 57     PROCESS_QUERY_LIMITED_INFORMATION; |  | 
| 58 const uint32 kProcessAccessWaitForTermination     = SYNCHRONIZE; |  | 
| 59 #elif defined(OS_POSIX) | 39 #elif defined(OS_POSIX) | 
| 60 struct BASE_EXPORT ProcessEntry { | 40 struct BASE_EXPORT ProcessEntry { | 
| 61   ProcessEntry(); | 41   ProcessEntry(); | 
| 62   ~ProcessEntry(); | 42   ~ProcessEntry(); | 
| 63 | 43 | 
| 64   ProcessId pid() const { return pid_; } | 44   ProcessId pid() const { return pid_; } | 
| 65   ProcessId parent_pid() const { return ppid_; } | 45   ProcessId parent_pid() const { return ppid_; } | 
| 66   ProcessId gid() const { return gid_; } | 46   ProcessId gid() const { return gid_; } | 
| 67   const char* exe_file() const { return exe_file_.c_str(); } | 47   const char* exe_file() const { return exe_file_.c_str(); } | 
| 68   const std::vector<std::string>& cmd_line_args() const { | 48   const std::vector<std::string>& cmd_line_args() const { | 
| 69     return cmd_line_args_; | 49     return cmd_line_args_; | 
| 70   } | 50   } | 
| 71 | 51 | 
| 72   ProcessId pid_; | 52   ProcessId pid_; | 
| 73   ProcessId ppid_; | 53   ProcessId ppid_; | 
| 74   ProcessId gid_; | 54   ProcessId gid_; | 
| 75   std::string exe_file_; | 55   std::string exe_file_; | 
| 76   std::vector<std::string> cmd_line_args_; | 56   std::vector<std::string> cmd_line_args_; | 
| 77 }; | 57 }; | 
| 78 |  | 
| 79 // Process access masks. They are not used on Posix because access checking |  | 
| 80 // does not happen during handle creation. |  | 
| 81 const uint32 kProcessAccessTerminate              = 0; |  | 
| 82 const uint32 kProcessAccessCreateThread           = 0; |  | 
| 83 const uint32 kProcessAccessSetSessionId           = 0; |  | 
| 84 const uint32 kProcessAccessVMOperation            = 0; |  | 
| 85 const uint32 kProcessAccessVMRead                 = 0; |  | 
| 86 const uint32 kProcessAccessVMWrite                = 0; |  | 
| 87 const uint32 kProcessAccessDuplicateHandle        = 0; |  | 
| 88 const uint32 kProcessAccessCreateProcess          = 0; |  | 
| 89 const uint32 kProcessAccessSetQuota               = 0; |  | 
| 90 const uint32 kProcessAccessSetInformation         = 0; |  | 
| 91 const uint32 kProcessAccessQueryInformation       = 0; |  | 
| 92 const uint32 kProcessAccessSuspendResume          = 0; |  | 
| 93 const uint32 kProcessAccessQueryLimitedInfomation = 0; |  | 
| 94 const uint32 kProcessAccessWaitForTermination     = 0; |  | 
| 95 #endif  // defined(OS_POSIX) | 58 #endif  // defined(OS_POSIX) | 
| 96 | 59 | 
| 97 // Used to filter processes by process ID. | 60 // Used to filter processes by process ID. | 
| 98 class ProcessFilter { | 61 class ProcessFilter { | 
| 99  public: | 62  public: | 
| 100   // Returns true to indicate set-inclusion and false otherwise.  This method | 63   // Returns true to indicate set-inclusion and false otherwise.  This method | 
| 101   // should not have side-effects and should be idempotent. | 64   // should not have side-effects and should be idempotent. | 
| 102   virtual bool Includes(const ProcessEntry& entry) const = 0; | 65   virtual bool Includes(const ProcessEntry& entry) const = 0; | 
| 103 | 66 | 
| 104  protected: | 67  protected: | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 176 | 139 | 
| 177 // Returns the number of processes on the machine that are running from the | 140 // Returns the number of processes on the machine that are running from the | 
| 178 // given executable name.  If filter is non-null, then only processes selected | 141 // given executable name.  If filter is non-null, then only processes selected | 
| 179 // by the filter will be counted. | 142 // by the filter will be counted. | 
| 180 BASE_EXPORT int GetProcessCount(const FilePath::StringType& executable_name, | 143 BASE_EXPORT int GetProcessCount(const FilePath::StringType& executable_name, | 
| 181                                 const ProcessFilter* filter); | 144                                 const ProcessFilter* filter); | 
| 182 | 145 | 
| 183 }  // namespace base | 146 }  // namespace base | 
| 184 | 147 | 
| 185 #endif  // BASE_PROCESS_PROCESS_ITERATOR_H_ | 148 #endif  // BASE_PROCESS_PROCESS_ITERATOR_H_ | 
| OLD | NEW | 
|---|