BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / ipc / brokerable_attachment.h
blobe5a701759e8991b2d9f931cba4876a29b75f54f0
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_
8 #include <stdint.h>
10 #include "base/macros.h"
11 #include "ipc/ipc_export.h"
12 #include "ipc/ipc_message_attachment.h"
14 namespace IPC {
16 // This subclass of MessageAttachment requires an AttachmentBroker to be
17 // attached to a Chrome IPC message.
18 class IPC_EXPORT BrokerableAttachment : public MessageAttachment {
19 public:
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.
26 AttachmentId();
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])
37 return false;
39 return true;
42 bool operator<(const AttachmentId& rhs) const {
43 for (size_t i = 0; i < kNonceSize; ++i) {
44 if (nonce[i] < rhs.nonce[i])
45 return true;
46 if (nonce[i] > rhs.nonce[i])
47 return false;
49 return false;
53 enum BrokerableType {
54 PLACEHOLDER,
55 WIN_HANDLE,
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
62 // can be used.
63 bool NeedsBrokering() const;
65 // Returns TYPE_BROKERABLE_ATTACHMENT
66 Type GetType() const override;
68 virtual BrokerableType GetBrokerableType() const = 0;
70 // MessageAttachment override.
71 #if defined(OS_POSIX)
72 base::PlatformFile TakePlatformFile() override;
73 #endif // OS_POSIX
75 protected:
76 BrokerableAttachment();
77 BrokerableAttachment(const AttachmentId& id);
78 ~BrokerableAttachment() override;
80 private:
81 // This member uniquely identifies a BrokerableAttachment across all Chrome
82 // processes.
83 const AttachmentId id_;
85 DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment);
88 } // namespace IPC
90 #endif // IPC_BROKERABLE_ATTACHMENT_H_