Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ipc / brokerable_attachment.cc
blob4a1becc218f57823e9e88af3d9a03a609689cef0
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 #include "ipc/brokerable_attachment.h"
7 #include "ipc/attachment_broker.h"
9 #if USE_ATTACHMENT_BROKER
10 #include "crypto/random.h"
11 #endif
13 namespace IPC {
15 #if USE_ATTACHMENT_BROKER
16 BrokerableAttachment::AttachmentId::AttachmentId() {
17 // In order to prevent mutually untrusted processes from stealing resources
18 // from one another, the nonce must be secret. This generates a 128-bit,
19 // cryptographicaly-strong random number.
20 crypto::RandBytes(nonce, BrokerableAttachment::kNonceSize);
22 #else
23 BrokerableAttachment::AttachmentId::AttachmentId() {
24 CHECK(false) << "Not allowed to construct an attachment id if the platform "
25 "does not support attachment brokering.";
27 #endif
29 BrokerableAttachment::AttachmentId::AttachmentId(const char* start_address,
30 size_t size) {
31 DCHECK(size == BrokerableAttachment::kNonceSize);
32 for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i)
33 nonce[i] = start_address[i];
36 void BrokerableAttachment::AttachmentId::SerializeToBuffer(char* start_address,
37 size_t size) {
38 DCHECK(size == BrokerableAttachment::kNonceSize);
39 for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i)
40 start_address[i] = nonce[i];
43 BrokerableAttachment::BrokerableAttachment() {}
45 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id) : id_(id) {}
47 BrokerableAttachment::~BrokerableAttachment() {}
49 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const {
50 return id_;
53 bool BrokerableAttachment::NeedsBrokering() const {
54 return GetBrokerableType() == PLACEHOLDER;
57 BrokerableAttachment::Type BrokerableAttachment::GetType() const {
58 return TYPE_BROKERABLE_ATTACHMENT;
61 #if defined(OS_POSIX)
62 base::PlatformFile BrokerableAttachment::TakePlatformFile() {
63 NOTREACHED();
64 return base::PlatformFile();
66 #endif // OS_POSIX
68 } // namespace IPC