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

Side by Side Diff: base/memory/scoped_open_process.h

Issue 868543002: Move OpenProcessHandle to Process::Open. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « base/base.gypi ('k') | base/process/process.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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_MEMORY_SCOPED_OPEN_PROCESS_H_
6 #define BASE_MEMORY_SCOPED_OPEN_PROCESS_H_
7
8 #include "base/process/process_handle.h"
9
10 namespace base {
11
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) {
17 }
18
19 // Automatically close the process.
20 ~ScopedOpenProcess() {
21 Close();
22 }
23
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_);
29 }
30
31 // Close the previously opened process.
32 void Close() {
33 if (handle_ == kNullProcessHandle)
34 return;
35
36 CloseProcessHandle(handle_);
37 handle_ = kNullProcessHandle;
38 }
39
40 ProcessHandle handle() const { return handle_; }
41
42 private:
43 ProcessHandle handle_;
44 DISALLOW_COPY_AND_ASSIGN(ScopedOpenProcess);
45 };
46 } // namespace base
47
48 #endif // BASE_MEMORY_SCOPED_OPEN_PROCESS_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/process/process.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698