| 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 a 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 | |
| 34 bool operator==(const AttachmentId& rhs) const { | 25 bool operator==(const AttachmentId& rhs) const { |
| 35 for (size_t i = 0; i < kNonceSize; ++i) { | 26 for (size_t i = 0; i < kNonceSize; ++i) { |
| 36 if (nonce[i] != rhs.nonce[i]) | 27 if (nonce[i] != rhs.nonce[i]) |
| 37 return false; | 28 return false; |
| 38 } | 29 } |
| 39 return true; | 30 return true; |
| 40 } | 31 } |
| 41 | 32 |
| 42 bool operator<(const AttachmentId& rhs) const { | 33 bool operator<(const AttachmentId& rhs) const { |
| 43 for (size_t i = 0; i < kNonceSize; ++i) { | 34 for (size_t i = 0; i < kNonceSize; ++i) { |
| 44 if (nonce[i] < rhs.nonce[i]) | 35 if (nonce[i] < rhs.nonce[i]) |
| 45 return true; | 36 return true; |
| 46 if (nonce[i] > rhs.nonce[i]) | 37 if (nonce[i] > rhs.nonce[i]) |
| 47 return false; | 38 return false; |
| 48 } | 39 } |
| 49 return false; | 40 return false; |
| 50 } | 41 } |
| 51 }; | 42 }; |
| 52 | 43 |
| 53 enum BrokerableType { | 44 enum BrokerableType { |
| 54 PLACEHOLDER, | |
| 55 WIN_HANDLE, | 45 WIN_HANDLE, |
| 56 }; | 46 }; |
| 57 | 47 |
| 58 // The identifier is unique across all Chrome processes. | 48 // The identifier is unique across all Chrome processes. |
| 59 AttachmentId GetIdentifier() const; | 49 AttachmentId GetIdentifier() const; |
| 60 | 50 |
| 61 // Whether the attachment still needs information from the broker before it | 51 // Whether the attachment still needs information from the broker before it |
| 62 // can be used. | 52 // can be used. |
| 63 bool NeedsBrokering() const; | 53 bool NeedsBrokering() const; |
| 64 | 54 |
| 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; |
| 60 |
| 65 // Returns TYPE_BROKERABLE_ATTACHMENT | 61 // Returns TYPE_BROKERABLE_ATTACHMENT |
| 66 Type GetType() const override; | 62 Type GetType() const override; |
| 67 | 63 |
| 68 virtual BrokerableType GetBrokerableType() const = 0; | 64 virtual BrokerableType GetBrokerableType() const = 0; |
| 69 | 65 |
| 70 // MessageAttachment override. | |
| 71 #if defined(OS_POSIX) | |
| 72 base::PlatformFile TakePlatformFile() override; | |
| 73 #endif // OS_POSIX | |
| 74 | |
| 75 protected: | 66 protected: |
| 76 BrokerableAttachment(); | 67 BrokerableAttachment(); |
| 77 BrokerableAttachment(const AttachmentId& id); | 68 BrokerableAttachment(const AttachmentId& id, bool needs_brokering); |
| 78 ~BrokerableAttachment() override; | 69 ~BrokerableAttachment() override; |
| 79 | 70 |
| 71 void SetNeedsBrokering(bool needs_brokering); |
| 72 |
| 80 private: | 73 private: |
| 81 // This member uniquely identifies a BrokerableAttachment across all Chrome | 74 // This member uniquely identifies a BrokerableAttachment across all Chrome |
| 82 // processes. | 75 // processes. |
| 83 const AttachmentId id_; | 76 const AttachmentId id_; |
| 84 | 77 |
| 78 // Whether the attachment still needs to be filled in by an AttachmentBroker. |
| 79 bool needs_brokering_; |
| 85 DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment); | 80 DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment); |
| 86 }; | 81 }; |
| 87 | 82 |
| 88 } // namespace IPC | 83 } // namespace IPC |
| 89 | 84 |
| 90 #endif // IPC_BROKERABLE_ATTACHMENT_H_ | 85 #endif // IPC_BROKERABLE_ATTACHMENT_H_ |
| OLD | NEW |