Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 #include "base/win/scoped_process_information.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace base { | |
| 10 namespace win { | |
| 11 | |
| 12 ScopedProcessInformation::ScopedProcessInformation() | |
| 13 : process_information_() { | |
| 14 } | |
| 15 | |
| 16 ScopedProcessInformation::~ScopedProcessInformation() { | |
| 17 Close(); | |
| 18 } | |
| 19 | |
| 20 PROCESS_INFORMATION* ScopedProcessInformation::Receive() { | |
| 21 DCHECK(!IsValid()) << "process_information_ must be NULL"; | |
| 22 return &process_information_; | |
| 23 } | |
| 24 | |
| 25 bool ScopedProcessInformation::IsValid() const { | |
| 26 return process_information_.hThread || process_information_.hProcess || | |
| 27 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
| |
| 28 } | |
| 29 | |
| 30 void ScopedProcessInformation::Close() { | |
| 31 if (process_information_.hThread) | |
| 32 ::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.
| |
| 33 if (process_information_.hProcess) | |
| 34 ::CloseHandle(process_information_.hProcess); | |
| 35 Reset(); | |
| 36 } | |
| 37 | |
| 38 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
| |
| 39 PROCESS_INFORMATION process_information = process_information_; | |
| 40 Reset(); | |
| 41 return process_information; | |
| 42 } | |
| 43 | |
| 44 HANDLE ScopedProcessInformation::TakeProcessHandle() { | |
| 45 HANDLE process = process_information_.hProcess; | |
| 46 process_information_.hProcess = NULL; | |
| 47 process_information_.dwProcessId = 0; | |
| 48 return process; | |
| 49 } | |
| 50 | |
| 51 HANDLE ScopedProcessInformation::TakeThreadHandle() { | |
| 52 HANDLE thread = process_information_.hThread; | |
| 53 process_information_.hThread = NULL; | |
| 54 process_information_.dwThreadId = 0; | |
| 55 return thread; | |
| 56 } | |
| 57 | |
| 58 void ScopedProcessInformation::Reset() { | |
| 59 process_information_.hThread = NULL; | |
| 60 process_information_.hProcess = NULL; | |
| 61 process_information_.dwProcessId = 0; | |
| 62 process_information_.dwThreadId = 0; | |
| 63 } | |
| 64 | |
| 65 } // namespace win | |
| 66 } // namespace base | |
| OLD | NEW |