Roll src/third_party/WebKit dfec292:200a784 (svn 202235:202237)
[chromium-blink-merge.git] / ipc / handle_win.cc
blobea268bd3bdd2f9be1942a69266c1a7ab013eba85
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"
12 namespace IPC {
14 HandleWin::HandleWin(const HANDLE& handle, Permissions permissions)
15 : handle_(handle), permissions_(permissions) {}
17 // static
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()))
23 NOTREACHED();
26 // static
27 bool ParamTraits<HandleWin>::Read(const Message* m,
28 base::PickleIterator* iter,
29 param_type* r) {
30 scoped_refptr<MessageAttachment> attachment;
31 if (!m->ReadAttachment(iter, &attachment))
32 return false;
33 if (attachment->GetType() != MessageAttachment::TYPE_BROKERABLE_ATTACHMENT)
34 return false;
35 BrokerableAttachment* brokerable_attachment =
36 static_cast<BrokerableAttachment*>(attachment.get());
37 if (brokerable_attachment->GetBrokerableType() !=
38 BrokerableAttachment::WIN_HANDLE) {
39 return false;
41 IPC::internal::HandleAttachmentWin* handle_attachment =
42 static_cast<IPC::internal::HandleAttachmentWin*>(brokerable_attachment);
43 r->set_handle(handle_attachment->get_handle());
44 return true;
47 // static
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()));
53 } // namespace IPC