Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Unified Diff: ipc/brokerable_attachment.cc

Issue 1286253002: IPC: Add attachment brokering support to the message header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix more #ifs Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698