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
])
57 // The identifier is unique across all Chrome processes.
58 AttachmentId
GetIdentifier() const;
60 // Whether the attachment still needs information from the broker before it
62 bool NeedsBrokering() const;
64 // Fills in the data of this instance with the data from |attachment|.
65 // This instance must require brokering, |attachment| must be brokered, and
66 // both instances must have the same identifier.
67 virtual void PopulateWithAttachment(
68 const BrokerableAttachment
* attachment
) = 0;
70 // Returns TYPE_BROKERABLE_ATTACHMENT
71 Type
GetType() const override
;
73 virtual BrokerableType
GetBrokerableType() const = 0;
76 BrokerableAttachment();
77 BrokerableAttachment(const AttachmentId
& id
, bool needs_brokering
);
78 ~BrokerableAttachment() override
;
80 void SetNeedsBrokering(bool needs_brokering
);
83 // This member uniquely identifies a BrokerableAttachment across all Chrome
85 const AttachmentId id_
;
87 // Whether the attachment still needs to be filled in by an AttachmentBroker.
88 bool needs_brokering_
;
89 DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment
);
94 #endif // IPC_BROKERABLE_ATTACHMENT_H_