Chromium Code Reviews| 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; |
|
Tom Sepez
2015/08/17 18:29:39
Why did we lose the initianlizer? should be just c
erikchen
2015/08/18 05:59:46
I looked into this further...the actual problem li
| |
| 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 // The size of this array must match kNonceSize. |
| 24 uint8_t nonce[16]; | |
| 24 | 25 |
| 25 bool operator==(const AttachmentId& rhs) const { | 26 // Default constructor doesn't initialize nonce. |
|
Tom Sepez
2015/08/17 18:29:39
nit: Seems like a mistake to leave it uninitizlize
erikchen
2015/08/18 05:59:46
You're right, I've changed the behavior and update
| |
| 26 for (size_t i = 0; i < kNonceSize; ++i) { | 27 AttachmentId(){}; |
| 27 if (nonce[i] != rhs.nonce[i]) | |
| 28 return false; | |
| 29 } | |
| 30 return true; | |
| 31 } | |
| 32 | 28 |
| 33 bool operator<(const AttachmentId& rhs) const { | 29 // Constructs an AttachmentId from a buffer. |
| 34 for (size_t i = 0; i < kNonceSize; ++i) { | 30 AttachmentId(const char* start_address, size_t size); |
| 35 if (nonce[i] < rhs.nonce[i]) | 31 |
| 36 return true; | 32 // Writes the nonce into a buffer. |
| 37 if (nonce[i] > rhs.nonce[i]) | 33 void SerializeToBuffer(char* start_address, size_t size); |
| 38 return false; | 34 |
| 39 } | 35 bool operator==(const AttachmentId& rhs) const; |
|
Tom Sepez
2015/08/17 18:29:39
probably want to put the code in here to help the
erikchen
2015/08/18 05:59:46
Done.
| |
| 40 return false; | 36 |
| 41 } | 37 bool operator<(const AttachmentId& rhs) const; |
| 42 }; | 38 }; |
| 43 | 39 |
| 44 enum BrokerableType { | 40 enum BrokerableType { |
| 41 PLACEHOLDER, | |
| 45 WIN_HANDLE, | 42 WIN_HANDLE, |
| 46 }; | 43 }; |
| 47 | 44 |
| 48 // The identifier is unique across all Chrome processes. | 45 // The identifier is unique across all Chrome processes. |
| 49 AttachmentId GetIdentifier() const; | 46 AttachmentId GetIdentifier() const; |
| 50 | 47 |
| 51 // Whether the attachment still needs information from the broker before it | 48 // Whether the attachment still needs information from the broker before it |
| 52 // can be used. | 49 // can be used. |
| 53 bool NeedsBrokering() const; | 50 bool NeedsBrokering() const; |
| 54 | 51 |
| 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 | |
| 61 // Returns TYPE_BROKERABLE_ATTACHMENT | 52 // Returns TYPE_BROKERABLE_ATTACHMENT |
| 62 Type GetType() const override; | 53 Type GetType() const override; |
| 63 | 54 |
| 64 virtual BrokerableType GetBrokerableType() const = 0; | 55 virtual BrokerableType GetBrokerableType() const = 0; |
| 65 | 56 |
| 57 // MessageAttachment override. | |
| 58 #if defined(OS_POSIX) | |
| 59 base::PlatformFile TakePlatformFile() override; | |
| 60 #endif // OS_POSIX | |
| 61 | |
| 66 protected: | 62 protected: |
| 67 BrokerableAttachment(); | 63 BrokerableAttachment(); |
| 68 BrokerableAttachment(const AttachmentId& id, bool needs_brokering); | 64 BrokerableAttachment(const AttachmentId& id); |
| 69 ~BrokerableAttachment() override; | 65 ~BrokerableAttachment() override; |
| 70 | 66 |
| 71 void SetNeedsBrokering(bool needs_brokering); | |
| 72 | |
| 73 private: | 67 private: |
| 74 // This member uniquely identifies a BrokerableAttachment across all Chrome | 68 // This member uniquely identifies a BrokerableAttachment across all Chrome |
| 75 // processes. | 69 // processes. |
| 76 const AttachmentId id_; | 70 const AttachmentId id_; |
| 77 | 71 |
| 78 // Whether the attachment still needs to be filled in by an AttachmentBroker. | |
| 79 bool needs_brokering_; | |
| 80 DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment); | 72 DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment); |
| 81 }; | 73 }; |
| 82 | 74 |
| 83 } // namespace IPC | 75 } // namespace IPC |
| 84 | 76 |
| 85 #endif // IPC_BROKERABLE_ATTACHMENT_H_ | 77 #endif // IPC_BROKERABLE_ATTACHMENT_H_ |
| OLD | NEW |