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/attachment_broker_win.h" | 5 #include "ipc/attachment_broker_win.h" |
6 | 6 |
7 #include "base/process/process.h" | 7 #include "base/process/process.h" |
8 #include "ipc/attachment_broker_messages.h" | 8 #include "ipc/attachment_broker_messages.h" |
9 #include "ipc/brokerable_attachment.h" | 9 #include "ipc/brokerable_attachment.h" |
10 #include "ipc/handle_attachment_win.h" | 10 #include "ipc/handle_attachment_win.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 internal::HandleAttachmentWin::WireFormat format = | 34 internal::HandleAttachmentWin::WireFormat format = |
35 handle_attachment->GetWireFormat(destination_process); | 35 handle_attachment->GetWireFormat(destination_process); |
36 return sender_->Send( | 36 return sender_->Send( |
37 new AttachmentBrokerMsg_DuplicateWinHandle(format)); | 37 new AttachmentBrokerMsg_DuplicateWinHandle(format)); |
38 } | 38 } |
39 return false; | 39 return false; |
40 } | 40 } |
41 | 41 |
42 bool AttachmentBrokerWin::GetAttachmentWithId( | 42 bool AttachmentBrokerWin::GetAttachmentWithId( |
43 BrokerableAttachment::AttachmentId id, | 43 BrokerableAttachment::AttachmentId id, |
44 BrokerableAttachment* attachment) { | 44 scoped_refptr<BrokerableAttachment>* out_attachment) { |
45 // TODO(erikchen): Implement me. http://crbug.com/493414 | 45 for (AttachmentVector::iterator it = attachments_.begin(); |
| 46 it != attachments_.end(); ++it) { |
| 47 if ((*it)->GetIdentifier() == id) { |
| 48 *out_attachment = *it; |
| 49 attachments_.erase(it); |
| 50 return true; |
| 51 } |
| 52 } |
46 return false; | 53 return false; |
47 } | 54 } |
48 | 55 |
49 bool AttachmentBrokerWin::OnMessageReceived(const Message& msg) { | 56 bool AttachmentBrokerWin::OnMessageReceived(const Message& msg) { |
50 bool handled = true; | 57 bool handled = true; |
51 IPC_BEGIN_MESSAGE_MAP(AttachmentBrokerWin, msg) | 58 IPC_BEGIN_MESSAGE_MAP(AttachmentBrokerWin, msg) |
52 IPC_MESSAGE_HANDLER(AttachmentBrokerMsg_WinHandleHasBeenDuplicated, | 59 IPC_MESSAGE_HANDLER(AttachmentBrokerMsg_WinHandleHasBeenDuplicated, |
53 OnWinHandleHasBeenDuplicated) | 60 OnWinHandleHasBeenDuplicated) |
54 IPC_MESSAGE_UNHANDLED(handled = false) | 61 IPC_MESSAGE_UNHANDLED(handled = false) |
55 IPC_END_MESSAGE_MAP() | 62 IPC_END_MESSAGE_MAP() |
56 return handled; | 63 return handled; |
57 } | 64 } |
58 | 65 |
59 void AttachmentBrokerWin::OnWinHandleHasBeenDuplicated( | 66 void AttachmentBrokerWin::OnWinHandleHasBeenDuplicated( |
60 const IPC::internal::HandleAttachmentWin::WireFormat& wire_format) { | 67 const IPC::internal::HandleAttachmentWin::WireFormat& wire_format) { |
61 // The IPC message was intended for a different process. Ignore it. | 68 // The IPC message was intended for a different process. Ignore it. |
62 if (wire_format.destination_process != base::Process::Current().Pid()) | 69 if (wire_format.destination_process != base::Process::Current().Pid()) |
63 return; | 70 return; |
64 | 71 |
65 scoped_refptr<BrokerableAttachment> attachment( | 72 scoped_refptr<BrokerableAttachment> attachment( |
66 new IPC::internal::HandleAttachmentWin(wire_format)); | 73 new IPC::internal::HandleAttachmentWin(wire_format)); |
67 attachments_.push_back(attachment); | 74 attachments_.push_back(attachment); |
| 75 NotifyObservers(attachment->GetIdentifier()); |
68 } | 76 } |
69 | 77 |
70 } // namespace IPC | 78 } // namespace IPC |
OLD | NEW |