Index: ipc/brokerable_attachment.cc |
diff --git a/ipc/brokerable_attachment.cc b/ipc/brokerable_attachment.cc |
index f1cc9b2afaa624b7b61d33b9f83539c159b33779..8802254d3f77a7b2de5453a1bdae5fe86a25e216 100644 |
--- a/ipc/brokerable_attachment.cc |
+++ b/ipc/brokerable_attachment.cc |
@@ -4,7 +4,11 @@ |
#include "ipc/brokerable_attachment.h" |
+#include "ipc/attachment_broker.h" |
+ |
+#if USE_ATTACHMENT_BROKER |
#include "crypto/random.h" |
+#endif |
namespace IPC { |
@@ -15,36 +19,74 @@ namespace { |
// cryptographicaly-strong random number. |
BrokerableAttachment::AttachmentId GetRandomId() { |
BrokerableAttachment::AttachmentId id; |
+#if USE_ATTACHMENT_BROKER |
crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize); |
+#endif |
return id; |
Tom Sepez
2015/08/17 18:29:39
nit: feels wrong to allow this to return a known k
erikchen
2015/08/18 05:59:46
I agree. I've changed the no-parameter constructor
|
} |
} // namespace |
-BrokerableAttachment::BrokerableAttachment() |
- : id_(GetRandomId()), needs_brokering_(false) {} |
+// The size of the nonce array in AttachmentId must match kNonceSize. |
+const size_t BrokerableAttachment::kNonceSize = 16; |
+ |
+BrokerableAttachment::AttachmentId::AttachmentId(const char* start_address, |
+ size_t size) { |
+ DCHECK_EQ(size, BrokerableAttachment::kNonceSize); |
+ for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i) |
+ nonce[i] = start_address[i]; |
+} |
-BrokerableAttachment::BrokerableAttachment(const AttachmentId& id, |
- bool needs_brokering) |
- : id_(id), needs_brokering_(needs_brokering) {} |
+void BrokerableAttachment::AttachmentId::SerializeToBuffer(char* start_address, |
+ size_t size) { |
+ DCHECK_EQ(size, BrokerableAttachment::kNonceSize); |
+ for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i) |
+ start_address[i] = nonce[i]; |
+} |
-BrokerableAttachment::~BrokerableAttachment() { |
+bool BrokerableAttachment::AttachmentId::operator==( |
+ const AttachmentId& rhs) const { |
+ for (size_t i = 0; i < kNonceSize; ++i) { |
+ if (nonce[i] != rhs.nonce[i]) |
+ return false; |
+ } |
+ return true; |
} |
+bool BrokerableAttachment::AttachmentId::operator<( |
+ const AttachmentId& rhs) const { |
+ for (size_t i = 0; i < kNonceSize; ++i) { |
+ if (nonce[i] < rhs.nonce[i]) |
+ return true; |
+ if (nonce[i] > rhs.nonce[i]) |
+ return false; |
+ } |
+ return false; |
+} |
+ |
+BrokerableAttachment::BrokerableAttachment() : id_(GetRandomId()) {} |
+ |
+BrokerableAttachment::BrokerableAttachment(const AttachmentId& id) : id_(id) {} |
+ |
+BrokerableAttachment::~BrokerableAttachment() {} |
+ |
BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { |
return id_; |
} |
bool BrokerableAttachment::NeedsBrokering() const { |
- return needs_brokering_; |
-} |
- |
-void BrokerableAttachment::SetNeedsBrokering(bool needs_brokering) { |
- needs_brokering_ = needs_brokering; |
+ return GetBrokerableType() == PLACEHOLDER; |
} |
BrokerableAttachment::Type BrokerableAttachment::GetType() const { |
return TYPE_BROKERABLE_ATTACHMENT; |
} |
+#if defined(OS_POSIX) |
+base::PlatformFile BrokerableAttachment::TakePlatformFile() { |
+ NOTREACHED(); |
+ return base::PlatformFile(); |
+} |
+#endif // OS_POSIX |
+ |
} // namespace IPC |