• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 #include <stddef.h>
8 
9 #include "build/build_config.h"
10 #include "ipc/attachment_broker.h"
11 
12 namespace IPC {
13 
14 // BrokerableAttachment::AttachmentId ------------------------------------------
15 #if !USE_ATTACHMENT_BROKER
16 // static
17 BrokerableAttachment::AttachmentId
CreateIdWithRandomNonce()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();
22 }
23 #endif
24 
AttachmentId()25 BrokerableAttachment::AttachmentId::AttachmentId() {
26   for (size_t i = 0; i < BrokerableAttachment::kNonceSize; ++i)
27     nonce[i] = 0;
28 }
29 
AttachmentId(const char * start_address,size_t size)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 
SerializeToBuffer(char * start_address,size_t size)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 
44 // BrokerableAttachment::BrokerableAttachment ----------------------------------
45 
BrokerableAttachment()46 BrokerableAttachment::BrokerableAttachment()
47     : id_(AttachmentId::CreateIdWithRandomNonce()) {}
48 
BrokerableAttachment(const AttachmentId & id)49 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id) : id_(id) {}
50 
~BrokerableAttachment()51 BrokerableAttachment::~BrokerableAttachment() {}
52 
GetIdentifier() const53 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const {
54   return id_;
55 }
56 
NeedsBrokering() const57 bool BrokerableAttachment::NeedsBrokering() const {
58   return GetBrokerableType() == PLACEHOLDER;
59 }
60 
GetType() const61 BrokerableAttachment::Type BrokerableAttachment::GetType() const {
62   return TYPE_BROKERABLE_ATTACHMENT;
63 }
64 
65 #if defined(OS_POSIX)
TakePlatformFile()66 base::PlatformFile BrokerableAttachment::TakePlatformFile() {
67   NOTREACHED();
68   return base::PlatformFile();
69 }
70 #endif  // OS_POSIX
71 
72 }  // namespace IPC
73