Update V8 to version 4.6.61.
[chromium-blink-merge.git] / ipc / brokerable_attachment.cc
blobf1cc9b2afaa624b7b61d33b9f83539c159b33779
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 "crypto/random.h"
9 namespace IPC {
11 namespace {
13 // In order to prevent mutually untrusted processes from stealing resources from
14 // one another, the nonce must be secret. This generates a 128-bit,
15 // cryptographicaly-strong random number.
16 BrokerableAttachment::AttachmentId GetRandomId() {
17 BrokerableAttachment::AttachmentId id;
18 crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize);
19 return id;
22 } // namespace
24 BrokerableAttachment::BrokerableAttachment()
25 : id_(GetRandomId()), needs_brokering_(false) {}
27 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id,
28 bool needs_brokering)
29 : id_(id), needs_brokering_(needs_brokering) {}
31 BrokerableAttachment::~BrokerableAttachment() {
34 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const {
35 return id_;
38 bool BrokerableAttachment::NeedsBrokering() const {
39 return needs_brokering_;
42 void BrokerableAttachment::SetNeedsBrokering(bool needs_brokering) {
43 needs_brokering_ = needs_brokering;
46 BrokerableAttachment::Type BrokerableAttachment::GetType() const {
47 return TYPE_BROKERABLE_ATTACHMENT;
50 } // namespace IPC