Chromium Code Reviews| Index: base/win/scoped_process_information.cc |
| diff --git a/base/win/scoped_process_information.cc b/base/win/scoped_process_information.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4659de1c1aaa495461e45fcf2627e6c2d64cff3e |
| --- /dev/null |
| +++ b/base/win/scoped_process_information.cc |
| @@ -0,0 +1,66 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/win/scoped_process_information.h" |
| + |
| +#include "base/logging.h" |
| + |
| +namespace base { |
| +namespace win { |
| + |
| +ScopedProcessInformation::ScopedProcessInformation() |
| + : process_information_() { |
| +} |
| + |
| +ScopedProcessInformation::~ScopedProcessInformation() { |
| + Close(); |
| +} |
| + |
| +PROCESS_INFORMATION* ScopedProcessInformation::Receive() { |
| + DCHECK(!IsValid()) << "process_information_ must be NULL"; |
| + return &process_information_; |
| +} |
| + |
| +bool ScopedProcessInformation::IsValid() const { |
| + return process_information_.hThread || process_information_.hProcess || |
| + process_information_.dwProcessId || process_information_.dwThreadId; |
|
alexeypa (please no reviews)
2012/03/29 04:51:35
I think that it should test only handles but not t
erikwright (departed)
2012/03/30 17:30:27
The only way for handle and id to not be in the sa
alexeypa (please no reviews)
2012/03/30 18:26:39
There is one example in the accompanying CL (the s
|
| +} |
| + |
| +void ScopedProcessInformation::Close() { |
| + if (process_information_.hThread) |
| + ::CloseHandle(process_information_.hThread); |
|
alexeypa (please no reviews)
2012/03/29 04:51:35
It will be useful for debugging if NOTREACHED() wi
erikwright (departed)
2012/03/30 17:30:27
Done.
|
| + if (process_information_.hProcess) |
| + ::CloseHandle(process_information_.hProcess); |
| + Reset(); |
| +} |
| + |
| +PROCESS_INFORMATION ScopedProcessInformation::Take() { |
|
alexeypa (please no reviews)
2012/03/29 04:51:35
Now, since ScopedProcessInformation is not limited
erikwright (departed)
2012/03/30 17:30:27
Looking through your suggestions on the use of Swa
alexeypa (please no reviews)
2012/03/30 18:26:39
The main reason to get rid of Take() is to reduce
|
| + PROCESS_INFORMATION process_information = process_information_; |
| + Reset(); |
| + return process_information; |
| +} |
| + |
| +HANDLE ScopedProcessInformation::TakeProcessHandle() { |
| + HANDLE process = process_information_.hProcess; |
| + process_information_.hProcess = NULL; |
| + process_information_.dwProcessId = 0; |
| + return process; |
| +} |
| + |
| +HANDLE ScopedProcessInformation::TakeThreadHandle() { |
| + HANDLE thread = process_information_.hThread; |
| + process_information_.hThread = NULL; |
| + process_information_.dwThreadId = 0; |
| + return thread; |
| +} |
| + |
| +void ScopedProcessInformation::Reset() { |
| + process_information_.hThread = NULL; |
| + process_information_.hProcess = NULL; |
| + process_information_.dwProcessId = 0; |
| + process_information_.dwThreadId = 0; |
| +} |
| + |
| +} // namespace win |
| +} // namespace base |