erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "ipc/brokerable_attachment.h" |
| 6 | |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
| 9 | #include "build/build_config.h" |
erikchen | 8135275 | 2015-09-04 02:37:22 | [diff] [blame] | 10 | #include "ipc/attachment_broker.h" |
| 11 | |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 12 | namespace IPC { |
| 13 | |
erikchen | 28299a1 | 2015-09-24 00:10:27 | [diff] [blame] | 14 | // BrokerableAttachment::AttachmentId ------------------------------------------ |
erikchen | a5085cda | 2015-09-15 17:26:27 | [diff] [blame] | 15 | #if !USE_ATTACHMENT_BROKER |
erikchen | 28299a1 | 2015-09-24 00:10:27 | [diff] [blame] | 16 | // static |
| 17 | BrokerableAttachment::AttachmentId |
| 18 | BrokerableAttachment::AttachmentId::CreateIdWithRandomNonce() { |
| 19 | CHECK(false) << "Platforms that don't support attachment brokering shouldn't " |
| 20 | "be trying to generating a random nonce."; |
| 21 | return AttachmentId(); |
erikchen | a5085cda | 2015-09-15 17:26:27 | [diff] [blame] | 22 | } |
| 23 | #endif |
| 24 | |
erikchen | 28299a1 | 2015-09-24 00:10:27 | [diff] [blame] | 25 | BrokerableAttachment::AttachmentId::AttachmentId() { |
| 26 | for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i) |
| 27 | nonce[i] = 0; |
| 28 | } |
| 29 | |
erikchen | a5085cda | 2015-09-15 17:26:27 | [diff] [blame] | 30 | BrokerableAttachment::AttachmentId::AttachmentId(const char* start_address, |
| 31 | size_t size) { |
| 32 | DCHECK(size == BrokerableAttachment::kNonceSize); |
| 33 | for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i) |
| 34 | nonce[i] = start_address[i]; |
| 35 | } |
| 36 | |
| 37 | void BrokerableAttachment::AttachmentId::SerializeToBuffer(char* start_address, |
| 38 | size_t size) { |
| 39 | DCHECK(size == BrokerableAttachment::kNonceSize); |
| 40 | for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i) |
| 41 | start_address[i] = nonce[i]; |
| 42 | } |
| 43 | |
erikchen | 28299a1 | 2015-09-24 00:10:27 | [diff] [blame] | 44 | // BrokerableAttachment::BrokerableAttachment ---------------------------------- |
| 45 | |
| 46 | BrokerableAttachment::BrokerableAttachment() |
| 47 | : id_(AttachmentId::CreateIdWithRandomNonce()) {} |
erikchen | a5085cda | 2015-09-15 17:26:27 | [diff] [blame] | 48 | |
erikchen | 87351da | 2015-09-15 19:11:09 | [diff] [blame] | 49 | BrokerableAttachment::BrokerableAttachment(const AttachmentId& id) : id_(id) {} |
erikchen | 06faf0c | 2015-08-27 19:49:58 | [diff] [blame] | 50 | |
erikchen | 87351da | 2015-09-15 19:11:09 | [diff] [blame] | 51 | BrokerableAttachment::~BrokerableAttachment() {} |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 52 | |
| 53 | BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { |
| 54 | return id_; |
| 55 | } |
| 56 | |
erikchen | de9412b8 | 2015-07-27 18:26:14 | [diff] [blame] | 57 | bool BrokerableAttachment::NeedsBrokering() const { |
erikchen | 87351da | 2015-09-15 19:11:09 | [diff] [blame] | 58 | return GetBrokerableType() == PLACEHOLDER; |
erikchen | de9412b8 | 2015-07-27 18:26:14 | [diff] [blame] | 59 | } |
| 60 | |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 61 | BrokerableAttachment::Type BrokerableAttachment::GetType() const { |
| 62 | return TYPE_BROKERABLE_ATTACHMENT; |
| 63 | } |
| 64 | |
erikchen | 87351da | 2015-09-15 19:11:09 | [diff] [blame] | 65 | #if defined(OS_POSIX) |
| 66 | base::PlatformFile BrokerableAttachment::TakePlatformFile() { |
| 67 | NOTREACHED(); |
| 68 | return base::PlatformFile(); |
| 69 | } |
| 70 | #endif // OS_POSIX |
| 71 | |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 72 | } // namespace IPC |