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_BROKERABLE_ATTACHMENT_H_ | 5 #ifndef IPC_BROKERABLE_ATTACHMENT_H_ |
6 #define IPC_BROKERABLE_ATTACHMENT_H_ | 6 #define IPC_BROKERABLE_ATTACHMENT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "ipc/ipc_export.h" | 11 #include "ipc/ipc_export.h" |
12 #include "ipc/ipc_message_attachment.h" | 12 #include "ipc/ipc_message_attachment.h" |
13 | 13 |
14 namespace IPC { | 14 namespace IPC { |
15 | 15 |
16 // This subclass of MessageAttachment requires an AttachmentBroker to be | 16 // This subclass of MessageAttachment requires an AttachmentBroker to be |
17 // attached to a Chrome IPC message. | 17 // attached to a Chrome IPC message. |
18 class IPC_EXPORT BrokerableAttachment : public MessageAttachment { | 18 class IPC_EXPORT BrokerableAttachment : public MessageAttachment { |
19 public: | 19 public: |
20 static const size_t kNonceSize = 16; | 20 static const size_t kNonceSize = 16; |
21 // An id uniquely identifies an attachment sent via a broker. | 21 // An id uniquely identifies an attachment sent via a broker. |
22 struct IPC_EXPORT AttachmentId { | 22 struct IPC_EXPORT AttachmentId { |
23 uint8_t nonce[kNonceSize]; | 23 uint8_t nonce[kNonceSize]; |
24 | 24 |
| 25 // Default constructor returns an unguessable random nonce. |
| 26 AttachmentId(); |
| 27 |
| 28 // Constructs an AttachmentId from a buffer. |
| 29 AttachmentId(const char* start_address, size_t size); |
| 30 |
| 31 // Writes the nonce into a buffer. |
| 32 void SerializeToBuffer(char* start_address, size_t size); |
| 33 |
25 bool operator==(const AttachmentId& rhs) const { | 34 bool operator==(const AttachmentId& rhs) const { |
26 for (size_t i = 0; i < kNonceSize; ++i) { | 35 for (size_t i = 0; i < kNonceSize; ++i) { |
27 if (nonce[i] != rhs.nonce[i]) | 36 if (nonce[i] != rhs.nonce[i]) |
28 return false; | 37 return false; |
29 } | 38 } |
30 return true; | 39 return true; |
31 } | 40 } |
32 | 41 |
33 bool operator<(const AttachmentId& rhs) const { | 42 bool operator<(const AttachmentId& rhs) const { |
34 for (size_t i = 0; i < kNonceSize; ++i) { | 43 for (size_t i = 0; i < kNonceSize; ++i) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 const AttachmentId id_; | 85 const AttachmentId id_; |
77 | 86 |
78 // Whether the attachment still needs to be filled in by an AttachmentBroker. | 87 // Whether the attachment still needs to be filled in by an AttachmentBroker. |
79 bool needs_brokering_; | 88 bool needs_brokering_; |
80 DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment); | 89 DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment); |
81 }; | 90 }; |
82 | 91 |
83 } // namespace IPC | 92 } // namespace IPC |
84 | 93 |
85 #endif // IPC_BROKERABLE_ATTACHMENT_H_ | 94 #endif // IPC_BROKERABLE_ATTACHMENT_H_ |
OLD | NEW |