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 bool operator==(const AttachmentId
& rhs
) const {
26 for (size_t i
= 0; i
< kNonceSize
; ++i
) {
27 if (nonce
[i
] != rhs
.nonce
[i
])
33 bool operator<(const AttachmentId
& rhs
) const {
34 for (size_t i
= 0; i
< kNonceSize
; ++i
) {
35 if (nonce
[i
] < rhs
.nonce
[i
])
37 if (nonce
[i
] > rhs
.nonce
[i
])
48 // The identifier is unique across all Chrome processes.
49 AttachmentId
GetIdentifier() const;
51 // Whether the attachment still needs information from the broker before it
53 bool NeedsBrokering() const;
55 // Fills in the data of this instance with the data from |attachment|.
56 // This instance must require brokering, |attachment| must be brokered, and
57 // both instances must have the same identifier.
58 virtual void PopulateWithAttachment(
59 const BrokerableAttachment
* attachment
) = 0;
61 // Returns TYPE_BROKERABLE_ATTACHMENT
62 Type
GetType() const override
;
64 virtual BrokerableType
GetBrokerableType() const = 0;
67 BrokerableAttachment();
68 BrokerableAttachment(const AttachmentId
& id
, bool needs_brokering
);
69 ~BrokerableAttachment() override
;
71 void SetNeedsBrokering(bool needs_brokering
);
74 // This member uniquely identifies a BrokerableAttachment across all Chrome
76 const AttachmentId id_
;
78 // Whether the attachment still needs to be filled in by an AttachmentBroker.
79 bool needs_brokering_
;
80 DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment
);
85 #endif // IPC_BROKERABLE_ATTACHMENT_H_