Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / base / process / process.h
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_PROCESS_PROCESS_PROCESS_H_
6 #define BASE_PROCESS_PROCESS_PROCESS_H_
7
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "base/move.h"
11 #include "base/process/process_handle.h"
12 #include "build/build_config.h"
13
14 #if defined(OS_WIN)
15 #include "base/win/scoped_handle.h"
16 #endif
17
18 namespace base {
19
20 // Provides a move-only encapsulation of a process.
21 //
22 // This object is not tied to the lifetime of the underlying process: the
23 // process may be killed and this object may still around, and it will still
24 // claim to be valid. The actual behavior in that case is OS dependent like so:
25 //
26 // Windows: The underlying ProcessHandle will be valid after the process dies
27 // and can be used to gather some information about that process, but most
28 // methods will obviously fail.
29 //
30 // POSIX: The underlying PorcessHandle is not guaranteed to remain valid after
31 // the process dies, and it may be reused by the system, which means that it may
32 // end up pointing to the wrong process.
33 class BASE_EXPORT Process {
34   MOVE_ONLY_TYPE_FOR_CPP_03(Process, RValue)
35
36  public:
37   explicit Process(ProcessHandle handle = kNullProcessHandle);
38
39   // Move constructor for C++03 move emulation of this type.
40   Process(RValue other);
41
42   // The destructor does not terminate the process.
43   ~Process() {}
44
45   // Move operator= for C++03 move emulation of this type.
46   Process& operator=(RValue other);
47
48   // Returns an object for the current process.
49   static Process Current();
50
51   // Returns true if processes can be backgrounded.
52   static bool CanBackgroundProcesses();
53
54   // Returns true if this objects represents a valid process.
55   bool IsValid() const;
56
57   // Returns a handle for this process. There is no guarantee about when that
58   // handle becomes invalid because this object retains ownership.
59   ProcessHandle Handle() const;
60
61   // Returns a second object that represents this process.
62   Process Duplicate() const;
63
64   // Get the PID for this process.
65   ProcessId pid() const;
66
67   // Returns true if this process is the current process.
68   bool is_current() const;
69
70   // Close the process handle. This will not terminate the process.
71   void Close();
72
73   // Terminates the process with extreme prejudice. The given |result_code| will
74   // be the exit code of the process.
75   // NOTE: On POSIX |result_code| is ignored.
76   void Terminate(int result_code);
77
78   // A process is backgrounded when it's priority is lower than normal.
79   // Return true if this process is backgrounded, false otherwise.
80   bool IsProcessBackgrounded() const;
81
82   // Set a process as backgrounded. If value is true, the priority of the
83   // process will be lowered. If value is false, the priority of the process
84   // will be made "normal" - equivalent to default process priority.
85   // Returns true if the priority was changed, false otherwise.
86   bool SetProcessBackgrounded(bool value);
87
88   // Returns an integer representing the priority of a process. The meaning
89   // of this value is OS dependent.
90   int GetPriority() const;
91
92  private:
93 #if defined(OS_WIN)
94   bool is_current_process_;
95   win::ScopedHandle process_;
96 #else
97   ProcessHandle process_;
98 #endif
99 };
100
101 }  // namespace base
102
103 #endif  // BASE_PROCESS_PROCESS_PROCESS_H_