blob: 96ce5bb6193861a7c100fee0e0fca4fcd6dabd5a [file] [log] [blame]
erikchen151b2f92015-06-16 20:20:511// 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
avi246998d82015-12-22 02:39:047#include <stddef.h>
8
9#include "build/build_config.h"
erikchen81352752015-09-04 02:37:2210#include "ipc/attachment_broker.h"
11
erikchen151b2f92015-06-16 20:20:5112namespace IPC {
13
erikchen28299a12015-09-24 00:10:2714// BrokerableAttachment::AttachmentId ------------------------------------------
erikchena5085cda2015-09-15 17:26:2715#if !USE_ATTACHMENT_BROKER
erikchen28299a12015-09-24 00:10:2716// static
17BrokerableAttachment::AttachmentId
18BrokerableAttachment::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();
erikchena5085cda2015-09-15 17:26:2722}
23#endif
24
erikchen28299a12015-09-24 00:10:2725BrokerableAttachment::AttachmentId::AttachmentId() {
26 for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i)
27 nonce[i] = 0;
28}
29
erikchena5085cda2015-09-15 17:26:2730BrokerableAttachment::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
37void 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
erikchen28299a12015-09-24 00:10:2744// BrokerableAttachment::BrokerableAttachment ----------------------------------
45
46BrokerableAttachment::BrokerableAttachment()
47 : id_(AttachmentId::CreateIdWithRandomNonce()) {}
erikchena5085cda2015-09-15 17:26:2748
erikchen87351da2015-09-15 19:11:0949BrokerableAttachment::BrokerableAttachment(const AttachmentId& id) : id_(id) {}
erikchen06faf0c2015-08-27 19:49:5850
erikchen87351da2015-09-15 19:11:0951BrokerableAttachment::~BrokerableAttachment() {}
erikchen151b2f92015-06-16 20:20:5152
53BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const {
54 return id_;
55}
56
erikchende9412b82015-07-27 18:26:1457bool BrokerableAttachment::NeedsBrokering() const {
erikchen87351da2015-09-15 19:11:0958 return GetBrokerableType() == PLACEHOLDER;
erikchende9412b82015-07-27 18:26:1459}
60
erikcheneece6c32015-07-07 22:13:1161BrokerableAttachment::Type BrokerableAttachment::GetType() const {
62 return TYPE_BROKERABLE_ATTACHMENT;
63}
64
erikchen87351da2015-09-15 19:11:0965#if defined(OS_POSIX)
66base::PlatformFile BrokerableAttachment::TakePlatformFile() {
67 NOTREACHED();
68 return base::PlatformFile();
69}
70#endif // OS_POSIX
71
erikchen151b2f92015-06-16 20:20:5172} // namespace IPC