ipc/chromium/src/base/process.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/process.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef BASE_PROCESS_H_
     1.9 +#define BASE_PROCESS_H_
    1.10 +
    1.11 +#include "base/basictypes.h"
    1.12 +
    1.13 +#include <sys/types.h>
    1.14 +#ifdef OS_WIN
    1.15 +#include <windows.h>
    1.16 +#endif
    1.17 +
    1.18 +namespace base {
    1.19 +
    1.20 +// ProcessHandle is a platform specific type which represents the underlying OS
    1.21 +// handle to a process.
    1.22 +// ProcessId is a number which identifies the process in the OS.
    1.23 +#if defined(OS_WIN)
    1.24 +typedef HANDLE ProcessHandle;
    1.25 +typedef DWORD ProcessId;
    1.26 +#elif defined(OS_POSIX)
    1.27 +// On POSIX, our ProcessHandle will just be the PID.
    1.28 +typedef pid_t ProcessHandle;
    1.29 +typedef pid_t ProcessId;
    1.30 +#endif
    1.31 +
    1.32 +class Process {
    1.33 + public:
    1.34 +  Process() : process_(0), last_working_set_size_(0) {}
    1.35 +  explicit Process(ProcessHandle handle) :
    1.36 +    process_(handle), last_working_set_size_(0) {}
    1.37 +
    1.38 +  // A handle to the current process.
    1.39 +  static Process Current();
    1.40 +
    1.41 +  // Get/Set the handle for this process. The handle will be 0 if the process
    1.42 +  // is no longer running.
    1.43 +  ProcessHandle handle() const { return process_; }
    1.44 +  void set_handle(ProcessHandle handle) { process_ = handle; }
    1.45 +
    1.46 +  // Get the PID for this process.
    1.47 +  ProcessId pid() const;
    1.48 +
    1.49 +  // Is the this process the current process.
    1.50 +  bool is_current() const;
    1.51 +
    1.52 +  // Close the process handle. This will not terminate the process.
    1.53 +  void Close();
    1.54 +
    1.55 +  // Terminates the process with extreme prejudice. The given result code will
    1.56 +  // be the exit code of the process. If the process has already exited, this
    1.57 +  // will do nothing.
    1.58 +  void Terminate(int result_code);
    1.59 +
    1.60 +  // A process is backgrounded when it's priority is lower than normal.
    1.61 +  // Return true if this process is backgrounded, false otherwise.
    1.62 +  bool IsProcessBackgrounded() const;
    1.63 +
    1.64 +  // Set a prcess as backgrounded.  If value is true, the priority
    1.65 +  // of the process will be lowered.  If value is false, the priority
    1.66 +  // of the process will be made "normal" - equivalent to default
    1.67 +  // process priority.
    1.68 +  // Returns true if the priority was changed, false otherwise.
    1.69 +  bool SetProcessBackgrounded(bool value);
    1.70 +
    1.71 +  // Releases as much of the working set back to the OS as possible.
    1.72 +  // Returns true if successful, false otherwise.
    1.73 +  bool EmptyWorkingSet();
    1.74 +
    1.75 + private:
    1.76 +  ProcessHandle process_;
    1.77 +  size_t last_working_set_size_;
    1.78 +};
    1.79 +
    1.80 +}  // namespace base
    1.81 +
    1.82 +#endif  // BASE_PROCESS_H_

mercurial