Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / ipc / brokerable_attachment.cc
blob764f2b20a4fa3879241e6b7a3d4582056b8f79bc
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() : id_(GetRandomId()) {
27 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id) : id_(id) {
30 BrokerableAttachment::~BrokerableAttachment() {
33 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const {
34 return id_;
37 BrokerableAttachment::Type BrokerableAttachment::GetType() const {
38 return TYPE_BROKERABLE_ATTACHMENT;
41 } // namespace IPC