diff options
Diffstat (limited to 'chromium/base/process/process.h')
-rw-r--r-- | chromium/base/process/process.h | 74 |
1 files changed, 62 insertions, 12 deletions
diff --git a/chromium/base/process/process.h b/chromium/base/process/process.h index 701947491d7..7fb1b69954c 100644 --- a/chromium/base/process/process.h +++ b/chromium/base/process/process.h @@ -1,14 +1,15 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef BASE_PROCESS_PROCESS_PROCESS_H_ -#define BASE_PROCESS_PROCESS_PROCESS_H_ +#ifndef BASE_PROCESS_PROCESS_H_ +#define BASE_PROCESS_PROCESS_H_ #include "base/base_export.h" #include "base/basictypes.h" #include "base/move.h" #include "base/process/process_handle.h" +#include "base/time/time.h" #include "build/build_config.h" #if defined(OS_WIN) @@ -40,7 +41,7 @@ class BASE_EXPORT Process { Process(RValue other); // The destructor does not terminate the process. - ~Process() {} + ~Process(); // Move operator= for C++03 move emulation of this type. Process& operator=(RValue other); @@ -48,6 +49,26 @@ class BASE_EXPORT Process { // Returns an object for the current process. static Process Current(); + // Returns a Process for the given |pid|. + static Process Open(ProcessId pid); + + // Returns a Process for the given |pid|. On Windows the handle is opened + // with more access rights and must only be used by trusted code (can read the + // address space and duplicate handles). + static Process OpenWithExtraPrivileges(ProcessId pid); + +#if defined(OS_WIN) + // Returns a Process for the given |pid|, using some |desired_access|. + // See ::OpenProcess documentation for valid |desired_access|. + static Process OpenWithAccess(ProcessId pid, DWORD desired_access); +#endif + + // Creates an object from a |handle| owned by someone else. + // Don't use this for new code. It is only intended to ease the migration to + // a strict ownership model. + // TODO(rvargas) crbug.com/417532: Remove this code. + static Process DeprecatedGetProcessFromHandle(ProcessHandle handle); + // Returns true if processes can be backgrounded. static bool CanBackgroundProcesses(); @@ -62,7 +83,7 @@ class BASE_EXPORT Process { Process Duplicate() const; // Get the PID for this process. - ProcessId pid() const; + ProcessId Pid() const; // Returns true if this process is the current process. bool is_current() const; @@ -70,11 +91,40 @@ class BASE_EXPORT Process { // Close the process handle. This will not terminate the process. void Close(); - // Terminates the process with extreme prejudice. The given |result_code| will - // be the exit code of the process. - // NOTE: On POSIX |result_code| is ignored. - void Terminate(int result_code); - + // Terminates the process with extreme prejudice. The given |exit_code| will + // be the exit code of the process. If |wait| is true, this method will wait + // for up to one minute for the process to actually terminate. + // Returns true if the process terminates within the allowed time. + // NOTE: On POSIX |exit_code| is ignored. + bool Terminate(int exit_code, bool wait) const; + + // Waits for the process to exit. Returns true on success. + // On POSIX, if the process has been signaled then |exit_code| is set to -1. + // On Linux this must be a child process, however on Mac and Windows it can be + // any process. + bool WaitForExit(int* exit_code); + + // Same as WaitForExit() but only waits for up to |timeout|. + bool WaitForExitWithTimeout(TimeDelta timeout, int* exit_code); + +#if defined(OS_MACOSX) + // The Mac needs a Mach port in order to manipulate a process's priority, + // and there's no good way to get that from base given the pid. These Mac + // variants of the IsProcessBackgrounded and SetProcessBackgrounded API take + // the Mach port for this reason. See crbug.com/460102 + // + // A process is backgrounded when its priority is lower than normal. + // Return true if the process with mach port |task_port| is backgrounded, + // false otherwise. + bool IsProcessBackgrounded(mach_port_t task_port) const; + + // Set the process with the specified mach port as backgrounded. If value is + // true, the priority of the process will be lowered. If value is false, the + // priority of the process will be made "normal" - equivalent to default + // process priority. Returns true if the priority was changed, false + // otherwise. + bool SetProcessBackgrounded(mach_port_t task_port, bool value); +#else // A process is backgrounded when it's priority is lower than normal. // Return true if this process is backgrounded, false otherwise. bool IsProcessBackgrounded() const; @@ -84,7 +134,7 @@ class BASE_EXPORT Process { // will be made "normal" - equivalent to default process priority. // Returns true if the priority was changed, false otherwise. bool SetProcessBackgrounded(bool value); - +#endif // defined(OS_MACOSX) // Returns an integer representing the priority of a process. The meaning // of this value is OS dependent. int GetPriority() const; @@ -100,4 +150,4 @@ class BASE_EXPORT Process { } // namespace base -#endif // BASE_PROCESS_PROCESS_PROCESS_H_ +#endif // BASE_PROCESS_PROCESS_H_ |