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 #ifndef IPC_BROKERABLE_ATTACHMENT_H_
6 #define IPC_BROKERABLE_ATTACHMENT_H_
10 #include "base/macros.h"
11 #include "ipc/ipc_export.h"
12 #include "ipc/ipc_message_attachment.h"
16 // This subclass of MessageAttachment requires an AttachmentBroker to be
17 // attached to a Chrome IPC message.
18 class IPC_EXPORT BrokerableAttachment
: public MessageAttachment
{
20 static const size_t kNonceSize
= 16;
21 // An id uniquely identifies an attachment sent via a broker.
22 struct IPC_EXPORT AttachmentId
{
23 uint8_t nonce
[kNonceSize
];
25 // Default constructor returns an unguessable random nonce.
28 // Constructs an AttachmentId from a buffer.
29 AttachmentId(const char* start_address
, size_t size
);
31 // Writes the nonce into a buffer.
32 void SerializeToBuffer(char* start_address
, size_t size
);
34 bool operator==(const AttachmentId
& rhs
) const {
35 for (size_t i
= 0; i
< kNonceSize
; ++i
) {
36 if (nonce
[i
] != rhs
.nonce
[i
])
42 bool operator<(const AttachmentId
& rhs
) const {
43 for (size_t i
= 0; i
< kNonceSize
; ++i
) {
44 if (nonce
[i
] < rhs
.nonce
[i
])
46 if (nonce
[i
] > rhs
.nonce
[i
])
58 // The identifier is unique across all Chrome processes.
59 AttachmentId
GetIdentifier() const;
61 // Whether the attachment still needs information from the broker before it
63 bool NeedsBrokering() const;
65 // Returns TYPE_BROKERABLE_ATTACHMENT
66 Type
GetType() const override
;
68 virtual BrokerableType
GetBrokerableType() const = 0;
70 // MessageAttachment override.
72 base::PlatformFile
TakePlatformFile() override
;
76 BrokerableAttachment();
77 BrokerableAttachment(const AttachmentId
& id
);
78 ~BrokerableAttachment() override
;
81 // This member uniquely identifies a BrokerableAttachment across all Chrome
83 const AttachmentId id_
;
85 DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment
);
90 #endif // IPC_BROKERABLE_ATTACHMENT_H_