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
3 // found in the LICENSE file.
5 #include "ipc/handle_win.h"
7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "ipc/handle_attachment_win.h"
14 HandleWin::HandleWin(const HANDLE
& handle
, Permissions permissions
)
15 : handle_(handle
), permissions_(permissions
) {}
18 void ParamTraits
<HandleWin
>::Write(Message
* m
, const param_type
& p
) {
19 scoped_refptr
<IPC::internal::HandleAttachmentWin
> attachment(
20 new IPC::internal::HandleAttachmentWin(p
.get_handle(),
21 p
.get_permissions()));
22 if (!m
->WriteAttachment(attachment
.Pass()))
27 bool ParamTraits
<HandleWin
>::Read(const Message
* m
,
28 base::PickleIterator
* iter
,
30 scoped_refptr
<MessageAttachment
> attachment
;
31 if (!m
->ReadAttachment(iter
, &attachment
))
33 if (attachment
->GetType() != MessageAttachment::TYPE_BROKERABLE_ATTACHMENT
)
35 BrokerableAttachment
* brokerable_attachment
=
36 static_cast<BrokerableAttachment
*>(attachment
.get());
37 if (brokerable_attachment
->GetBrokerableType() !=
38 BrokerableAttachment::WIN_HANDLE
) {
41 IPC::internal::HandleAttachmentWin
* handle_attachment
=
42 static_cast<IPC::internal::HandleAttachmentWin
*>(brokerable_attachment
);
43 r
->set_handle(handle_attachment
->get_handle());
48 void ParamTraits
<HandleWin
>::Log(const param_type
& p
, std::string
* l
) {
49 l
->append(base::StringPrintf("0x%X", p
.get_handle()));
50 l
->append(base::IntToString(p
.get_permissions()));