Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ipc/brokerable_attachment.h" | 5 #include "ipc/brokerable_attachment.h" |
| 6 | 6 |
| 7 #include "crypto/random.h" | 7 #include "crypto/random.h" |
| 8 | 8 |
| 9 namespace IPC { | 9 namespace IPC { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // In order to prevent mutually untrusted processes from stealing resources from | 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, | 14 // one another, the nonce must be secret. This generates a 128-bit, |
| 15 // cryptographicaly-strong random number. | 15 // cryptographicaly-strong random number. |
| 16 BrokerableAttachment::AttachmentId GetRandomId() { | 16 BrokerableAttachment::AttachmentId GetRandomId() { |
| 17 BrokerableAttachment::AttachmentId id; | 17 BrokerableAttachment::AttachmentId id; |
| 18 crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize); | 18 crypto::RandBytes(id.nonce, BrokerableAttachment::kNonceSize); |
| 19 return id; | 19 return id; |
| 20 } | 20 } |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 BrokerableAttachment::BrokerableAttachment() : id_(GetRandomId()) { | 24 BrokerableAttachment::BrokerableAttachment() |
| 25 : id_(GetRandomId()), needs_brokering_(false) { | |
| 25 } | 26 } |
| 26 | 27 |
| 27 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id) : id_(id) { | 28 BrokerableAttachment::BrokerableAttachment(const AttachmentId& id, |
| 29 bool needs_brokering) | |
| 30 : id_(id), needs_brokering_(needs_brokering) { | |
| 28 } | 31 } |
| 29 | 32 |
| 30 BrokerableAttachment::~BrokerableAttachment() { | 33 BrokerableAttachment::~BrokerableAttachment() { |
| 31 } | 34 } |
| 32 | 35 |
| 33 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { | 36 BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { |
| 34 return id_; | 37 return id_; |
| 35 } | 38 } |
| 36 | 39 |
| 40 bool BrokerableAttachment::NeedsBrokering() const { | |
|
Tom Sepez
2015/07/13 18:28:47
Any reason not to just make these inline in the he
erikchen
2015/07/17 18:44:01
I try to keep as much code as possible out of head
| |
| 41 return needs_brokering_; | |
| 42 } | |
| 43 | |
| 44 void BrokerableAttachment::SetNeedsBrokering(bool needs_brokering) { | |
| 45 needs_brokering_ = needs_brokering; | |
| 46 } | |
| 47 | |
| 37 BrokerableAttachment::Type BrokerableAttachment::GetType() const { | 48 BrokerableAttachment::Type BrokerableAttachment::GetType() const { |
| 38 return TYPE_BROKERABLE_ATTACHMENT; | 49 return TYPE_BROKERABLE_ATTACHMENT; |
| 39 } | 50 } |
| 40 | 51 |
| 41 } // namespace IPC | 52 } // namespace IPC |
| OLD | NEW |