Roll src/third_party/skia b3eb687:c6f3e2c
[chromium-blink-merge.git] / base / memory / scoped_open_process.h
blob8bb19e241ec7921add1c535fc4a68e1e47f639bc
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.
5 #ifndef BASE_MEMORY_SCOPED_OPEN_PROCESS_H_
6 #define BASE_MEMORY_SCOPED_OPEN_PROCESS_H_
8 #include "base/process/process_handle.h"
10 namespace base {
12 // A class that opens a process from its process id and closes it when the
13 // instance goes out of scope.
14 class ScopedOpenProcess {
15 public:
16 ScopedOpenProcess() : handle_(kNullProcessHandle) {
19 // Automatically close the process.
20 ~ScopedOpenProcess() {
21 Close();
24 // Open a new process by pid. Closes any previously opened process (even if
25 // opening the new one fails).
26 bool Open(ProcessId pid) {
27 Close();
28 return OpenProcessHandle(pid, &handle_);
31 // Close the previously opened process.
32 void Close() {
33 if (handle_ == kNullProcessHandle)
34 return;
36 CloseProcessHandle(handle_);
37 handle_ = kNullProcessHandle;
40 ProcessHandle handle() const { return handle_; }
42 private:
43 ProcessHandle handle_;
44 DISALLOW_COPY_AND_ASSIGN(ScopedOpenProcess);
46 } // namespace base
48 #endif // BASE_MEMORY_SCOPED_OPEN_PROCESS_H_