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_win.h" | 5 #include "ipc/handle_win.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "ipc/handle_attachment_win.h" | 13 #include "ipc/handle_attachment_win.h" |
14 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
15 | 15 |
16 namespace IPC { | 16 namespace IPC { |
17 | 17 |
18 HandleWin::HandleWin() : handle_(nullptr), permissions_(INVALID) {} | 18 HandleWin::HandleWin() : handle_(nullptr), permissions_(INVALID) {} |
19 | 19 |
20 HandleWin::HandleWin(const HANDLE& handle, Permissions permissions) | 20 HandleWin::HandleWin(const HANDLE& handle, Permissions permissions) |
21 : handle_(handle), permissions_(permissions) {} | 21 : handle_(handle), permissions_(permissions) {} |
22 | 22 |
23 // static | 23 // static |
24 void ParamTraits<HandleWin>::Write(Message* m, const param_type& p) { | 24 void ParamTraits<HandleWin>::Write(base::Pickle* m, const param_type& p) { |
25 scoped_refptr<IPC::internal::HandleAttachmentWin> attachment( | 25 scoped_refptr<IPC::internal::HandleAttachmentWin> attachment( |
26 new IPC::internal::HandleAttachmentWin(p.get_handle(), | 26 new IPC::internal::HandleAttachmentWin(p.get_handle(), |
27 p.get_permissions())); | 27 p.get_permissions())); |
28 if (!m->WriteAttachment(std::move(attachment))) | 28 if (!m->WriteAttachment(std::move(attachment))) |
29 NOTREACHED(); | 29 NOTREACHED(); |
30 } | 30 } |
31 | 31 |
32 // static | 32 // static |
33 bool ParamTraits<HandleWin>::Read(const Message* m, | 33 bool ParamTraits<HandleWin>::Read(const base::Pickle* m, |
34 base::PickleIterator* iter, | 34 base::PickleIterator* iter, |
35 param_type* r) { | 35 param_type* r) { |
36 scoped_refptr<MessageAttachment> attachment; | 36 scoped_refptr<base::Pickle::Attachment> base_attachment; |
37 if (!m->ReadAttachment(iter, &attachment)) | 37 if (!m->ReadAttachment(iter, &base_attachment)) |
38 return false; | 38 return false; |
| 39 MessageAttachment* attachment = |
| 40 static_cast<MessageAttachment*>(base_attachment.get()); |
39 if (attachment->GetType() != MessageAttachment::TYPE_BROKERABLE_ATTACHMENT) | 41 if (attachment->GetType() != MessageAttachment::TYPE_BROKERABLE_ATTACHMENT) |
40 return false; | 42 return false; |
41 BrokerableAttachment* brokerable_attachment = | 43 BrokerableAttachment* brokerable_attachment = |
42 static_cast<BrokerableAttachment*>(attachment.get()); | 44 static_cast<BrokerableAttachment*>(attachment); |
43 if (brokerable_attachment->GetBrokerableType() != | 45 if (brokerable_attachment->GetBrokerableType() != |
44 BrokerableAttachment::WIN_HANDLE) { | 46 BrokerableAttachment::WIN_HANDLE) { |
45 return false; | 47 return false; |
46 } | 48 } |
47 IPC::internal::HandleAttachmentWin* handle_attachment = | 49 IPC::internal::HandleAttachmentWin* handle_attachment = |
48 static_cast<IPC::internal::HandleAttachmentWin*>(brokerable_attachment); | 50 static_cast<IPC::internal::HandleAttachmentWin*>(brokerable_attachment); |
49 r->set_handle(handle_attachment->get_handle()); | 51 r->set_handle(handle_attachment->get_handle()); |
50 handle_attachment->reset_handle_ownership(); | 52 handle_attachment->reset_handle_ownership(); |
51 return true; | 53 return true; |
52 } | 54 } |
53 | 55 |
54 // static | 56 // static |
55 void ParamTraits<HandleWin>::Log(const param_type& p, std::string* l) { | 57 void ParamTraits<HandleWin>::Log(const param_type& p, std::string* l) { |
56 l->append(base::StringPrintf("0x%p", p.get_handle())); | 58 l->append(base::StringPrintf("0x%p", p.get_handle())); |
57 l->append(base::IntToString(p.get_permissions())); | 59 l->append(base::IntToString(p.get_permissions())); |
58 } | 60 } |
59 | 61 |
60 } // namespace IPC | 62 } // namespace IPC |
OLD | NEW |