Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Unified Diff: base/process/process.h

Issue 651253002: Enforce handle ownership in base::Process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add empty line Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/kill_posix.cc ('k') | base/process/process_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process.h
diff --git a/base/process/process.h b/base/process/process.h
index 20e8884b9720f04fad879980107c14a9a3951f31..701947491d7497a29ed2dfac754d0fd96e969083 100644
--- a/base/process/process.h
+++ b/base/process/process.h
@@ -7,53 +7,81 @@
#include "base/base_export.h"
#include "base/basictypes.h"
+#include "base/move.h"
#include "base/process/process_handle.h"
#include "build/build_config.h"
+#if defined(OS_WIN)
+#include "base/win/scoped_handle.h"
+#endif
+
namespace base {
+// Provides a move-only encapsulation of a process.
+//
+// This object is not tied to the lifetime of the underlying process: the
+// process may be killed and this object may still around, and it will still
+// claim to be valid. The actual behavior in that case is OS dependent like so:
+//
+// Windows: The underlying ProcessHandle will be valid after the process dies
+// and can be used to gather some information about that process, but most
+// methods will obviously fail.
+//
+// POSIX: The underlying PorcessHandle is not guaranteed to remain valid after
+// the process dies, and it may be reused by the system, which means that it may
+// end up pointing to the wrong process.
class BASE_EXPORT Process {
+ MOVE_ONLY_TYPE_FOR_CPP_03(Process, RValue)
+
public:
- Process() : process_(kNullProcessHandle) {
- }
+ explicit Process(ProcessHandle handle = kNullProcessHandle);
+
+ // Move constructor for C++03 move emulation of this type.
+ Process(RValue other);
- explicit Process(ProcessHandle handle) : process_(handle) {
- }
+ // The destructor does not terminate the process.
+ ~Process() {}
- // A handle to the current process.
+ // Move operator= for C++03 move emulation of this type.
+ Process& operator=(RValue other);
+
+ // Returns an object for the current process.
static Process Current();
+ // Returns true if processes can be backgrounded.
static bool CanBackgroundProcesses();
- // Get/Set the handle for this process. The handle will be 0 if the process
- // is no longer running.
- ProcessHandle handle() const { return process_; }
- void set_handle(ProcessHandle handle) {
- process_ = handle;
- }
+ // Returns true if this objects represents a valid process.
+ bool IsValid() const;
+
+ // Returns a handle for this process. There is no guarantee about when that
+ // handle becomes invalid because this object retains ownership.
+ ProcessHandle Handle() const;
+
+ // Returns a second object that represents this process.
+ Process Duplicate() const;
// Get the PID for this process.
ProcessId pid() const;
- // Is the this process the current process.
+ // Returns true if this process is the current process.
bool is_current() const;
// 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. If the process has already exited, this
- // will do nothing.
+ // 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);
// A process is backgrounded when it's priority is lower than normal.
// Return true if this process is backgrounded, false otherwise.
bool IsProcessBackgrounded() const;
- // Set a process 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.
+ // Set a process 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(bool value);
@@ -62,7 +90,12 @@ class BASE_EXPORT Process {
int GetPriority() const;
private:
+#if defined(OS_WIN)
+ bool is_current_process_;
+ win::ScopedHandle process_;
+#else
ProcessHandle process_;
+#endif
};
} // namespace base
« no previous file with comments | « base/process/kill_posix.cc ('k') | base/process/process_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698