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 #ifndef IPC_ATTACHMENT_BROKER_PRIVILEGED_WIN_H_ | 5 #ifndef IPC_ATTACHMENT_BROKER_PRIVILEGED_WIN_H_ |
6 #define IPC_ATTACHMENT_BROKER_PRIVILEGED_WIN_H_ | 6 #define IPC_ATTACHMENT_BROKER_PRIVILEGED_WIN_H_ |
7 | 7 |
| 8 #include <map> |
| 9 #include <vector> |
| 10 |
8 #include "base/macros.h" | 11 #include "base/macros.h" |
9 #include "ipc/attachment_broker_privileged.h" | 12 #include "ipc/attachment_broker_privileged.h" |
10 #include "ipc/handle_attachment_win.h" | 13 #include "ipc/handle_attachment_win.h" |
11 #include "ipc/ipc_export.h" | 14 #include "ipc/ipc_export.h" |
12 | 15 |
13 namespace IPC { | 16 namespace IPC { |
14 | 17 |
15 // This class is a concrete subclass of AttachmentBrokerPrivileged for the | 18 // This class is a concrete subclass of AttachmentBrokerPrivileged for the |
16 // Windows platform. | 19 // Windows platform. |
17 class IPC_EXPORT AttachmentBrokerPrivilegedWin | 20 class IPC_EXPORT AttachmentBrokerPrivilegedWin |
18 : public AttachmentBrokerPrivileged { | 21 : public AttachmentBrokerPrivileged { |
19 public: | 22 public: |
20 AttachmentBrokerPrivilegedWin(); | 23 AttachmentBrokerPrivilegedWin(); |
21 ~AttachmentBrokerPrivilegedWin() override; | 24 ~AttachmentBrokerPrivilegedWin() override; |
22 | 25 |
23 // IPC::AttachmentBroker overrides. | 26 // IPC::AttachmentBroker overrides. |
24 bool SendAttachmentToProcess( | 27 bool SendAttachmentToProcess( |
25 const scoped_refptr<IPC::BrokerableAttachment>& attachment, | 28 const scoped_refptr<IPC::BrokerableAttachment>& attachment, |
26 base::ProcessId destination_process) override; | 29 base::ProcessId destination_process) override; |
| 30 void ReceivedPeerPid(base::ProcessId peer_pid) override; |
27 | 31 |
28 // IPC::Listener overrides. | 32 // IPC::Listener overrides. |
29 bool OnMessageReceived(const Message& message) override; | 33 bool OnMessageReceived(const Message& message) override; |
30 | 34 |
31 private: | 35 private: |
32 using HandleWireFormat = internal::HandleAttachmentWin::WireFormat; | 36 using HandleWireFormat = internal::HandleAttachmentWin::WireFormat; |
33 // IPC message handlers. | 37 // IPC message handlers. |
34 void OnDuplicateWinHandle(const Message& message); | 38 void OnDuplicateWinHandle(const Message& message); |
35 | 39 |
36 // Duplicates |wire_Format| from |source_process| into its destination | 40 // Duplicates |wire_Format| from |source_process| into its destination |
37 // process. Closes the original HANDLE. | 41 // process. Closes the original HANDLE. |
38 HandleWireFormat DuplicateWinHandle(const HandleWireFormat& wire_format, | 42 HandleWireFormat DuplicateWinHandle(const HandleWireFormat& wire_format, |
39 base::ProcessId source_process); | 43 base::ProcessId source_process); |
40 | 44 |
41 // Copies an existing |wire_format|, but substitutes in a different handle. | 45 // Copies an existing |wire_format|, but substitutes in a different handle. |
42 HandleWireFormat CopyWireFormat(const HandleWireFormat& wire_format, | 46 HandleWireFormat CopyWireFormat(const HandleWireFormat& wire_format, |
43 int handle); | 47 int handle); |
44 | 48 |
45 // If the HANDLE's destination is this process, queue it and notify the | 49 // If the HANDLE's destination is this process, queue it and notify the |
46 // observers. Otherwise, send it in an IPC to its destination. | 50 // observers. Otherwise, send it in an IPC to its destination. |
47 void RouteDuplicatedHandle(const HandleWireFormat& wire_format); | 51 // If the destination process cannot be found, |store_on_failure| indicates |
| 52 // whether the |wire_format| should be stored, or an error should be emitted. |
| 53 void RouteDuplicatedHandle(const HandleWireFormat& wire_format, |
| 54 bool store_on_failure); |
| 55 |
| 56 // Wire formats that cannot be immediately sent to the destination process |
| 57 // because the connection has not been established. If, for some reason, the |
| 58 // connection is never established, then the assumption is that the |
| 59 // destination process died. The resource itself will be cleaned up by the OS, |
| 60 // but the data structure HandleWireFormat will leak. If, at a later point in |
| 61 // time, a new process is created with the same process id, the WireFormats |
| 62 // will be passed to the new process. There is no security problem, since the |
| 63 // resource itself is not being sent. Furthermore, it is unlikely to affect |
| 64 // the functionality of the new process, since AttachmentBroker ids are large, |
| 65 // unguessable nonces. |
| 66 using WireFormats = std::vector<HandleWireFormat>; |
| 67 std::map<base::ProcessId, WireFormats> stored_wire_formats_; |
48 | 68 |
49 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerPrivilegedWin); | 69 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerPrivilegedWin); |
50 }; | 70 }; |
51 | 71 |
52 } // namespace IPC | 72 } // namespace IPC |
53 | 73 |
54 #endif // IPC_ATTACHMENT_BROKER_PRIVILEGED_WIN_H_ | 74 #endif // IPC_ATTACHMENT_BROKER_PRIVILEGED_WIN_H_ |
OLD | NEW |