OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ipc/handle_attachment_win.h" | 5 #include "ipc/handle_attachment_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 namespace IPC { | 9 namespace IPC { |
10 namespace internal { | 10 namespace internal { |
11 | 11 |
12 HandleAttachmentWin::HandleAttachmentWin(const HANDLE& handle, | 12 HandleAttachmentWin::HandleAttachmentWin(const HANDLE& handle, |
13 HandleWin::Permissions permissions) | 13 HandleWin::Permissions permissions) |
14 : handle_(handle), permissions_(permissions), owns_handle_(true) {} | 14 : handle_(INVALID_HANDLE_VALUE), |
| 15 permissions_(HandleWin::INVALID), |
| 16 owns_handle_(true) { |
| 17 HANDLE duplicated_handle; |
| 18 BOOL result = |
| 19 ::DuplicateHandle(GetCurrentProcess(), handle, GetCurrentProcess(), |
| 20 &duplicated_handle, 0, FALSE, DUPLICATE_SAME_ACCESS); |
| 21 if (result) { |
| 22 handle_ = duplicated_handle; |
| 23 permissions_ = permissions; |
| 24 } |
| 25 } |
15 | 26 |
16 HandleAttachmentWin::HandleAttachmentWin(const WireFormat& wire_format) | 27 HandleAttachmentWin::HandleAttachmentWin(const WireFormat& wire_format) |
17 : BrokerableAttachment(wire_format.attachment_id), | 28 : BrokerableAttachment(wire_format.attachment_id), |
18 handle_(LongToHandle(wire_format.handle)), | 29 handle_(LongToHandle(wire_format.handle)), |
19 permissions_(wire_format.permissions), owns_handle_(false) {} | 30 permissions_(wire_format.permissions), |
20 | 31 owns_handle_(true) {} |
21 HandleAttachmentWin::HandleAttachmentWin( | |
22 const BrokerableAttachment::AttachmentId& id) | |
23 : BrokerableAttachment(id), | |
24 handle_(INVALID_HANDLE_VALUE), | |
25 permissions_(HandleWin::INVALID), owns_handle_(false) {} | |
26 | 32 |
27 HandleAttachmentWin::~HandleAttachmentWin() { | 33 HandleAttachmentWin::~HandleAttachmentWin() { |
28 if (handle_ != INVALID_HANDLE_VALUE && owns_handle_) | 34 if (handle_ != INVALID_HANDLE_VALUE && owns_handle_) |
29 ::CloseHandle(handle_); | 35 ::CloseHandle(handle_); |
30 } | 36 } |
31 | 37 |
32 HandleAttachmentWin::BrokerableType HandleAttachmentWin::GetBrokerableType() | 38 HandleAttachmentWin::BrokerableType HandleAttachmentWin::GetBrokerableType() |
33 const { | 39 const { |
34 return WIN_HANDLE; | 40 return WIN_HANDLE; |
35 } | 41 } |
36 | 42 |
37 HandleAttachmentWin::WireFormat HandleAttachmentWin::GetWireFormat( | 43 HandleAttachmentWin::WireFormat HandleAttachmentWin::GetWireFormat( |
38 const base::ProcessId& destination) const { | 44 const base::ProcessId& destination) const { |
39 return WireFormat(HandleToLong(handle_), destination, permissions_, | 45 return WireFormat(HandleToLong(handle_), destination, permissions_, |
40 GetIdentifier()); | 46 GetIdentifier()); |
41 } | 47 } |
42 | 48 |
43 } // namespace internal | 49 } // namespace internal |
44 } // namespace IPC | 50 } // namespace IPC |
OLD | NEW |