Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ipc_channel.h" | 5 #include "ipc/ipc_channel.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 | 12 |
| 13 #if !defined(OS_NACL) | |
|
Junichi Uekawa
2014/10/17 10:31:13
This is going to introduce a new object in NaCl ?
hidehiko
2014/10/20 06:02:28
This file is NOT built for the SFI NaCl IRT build
| |
| 14 namespace { | 13 namespace { |
| 15 | 14 |
| 16 // Global atomic used to guarantee channel IDs are unique. | 15 // Global atomic used to guarantee channel IDs are unique. |
| 17 base::StaticAtomicSequenceNumber g_last_id; | 16 base::StaticAtomicSequenceNumber g_last_id; |
| 18 | 17 |
| 19 } // namespace | 18 } // namespace |
| 20 #endif | |
| 21 | 19 |
| 22 namespace IPC { | 20 namespace IPC { |
| 23 | 21 |
| 24 // static | 22 // static |
| 25 std::string Channel::GenerateUniqueRandomChannelID() { | 23 std::string Channel::GenerateUniqueRandomChannelID() { |
| 26 // Note: the string must start with the current process id, this is how | 24 // Note: the string must start with the current process id, this is how |
| 27 // some child processes determine the pid of the parent. | 25 // some child processes determine the pid of the parent. |
| 28 // | 26 // |
| 29 // This is composed of a unique incremental identifier, the process ID of | 27 // This is composed of a unique incremental identifier, the process ID of |
| 30 // the creator, an identifier for the child instance, and a strong random | 28 // the creator, an identifier for the child instance, and a strong random |
| 31 // component. The strong random component prevents other processes from | 29 // component. The strong random component prevents other processes from |
| 32 // hijacking or squatting on predictable channel names. | 30 // hijacking or squatting on predictable channel names. |
| 33 | 31 |
| 34 int process_id = base::GetCurrentProcId(); | 32 int process_id = base::GetCurrentProcId(); |
| 35 return base::StringPrintf("%d.%u.%d", | 33 return base::StringPrintf("%d.%u.%d", |
| 36 process_id, | 34 process_id, |
| 37 g_last_id.GetNext(), | 35 g_last_id.GetNext(), |
| 38 base::RandInt(0, std::numeric_limits<int32>::max())); | 36 base::RandInt(0, std::numeric_limits<int32>::max())); |
| 39 } | 37 } |
| 40 | 38 |
| 41 } // namespace IPC | 39 } // namespace IPC |
| 42 | |
| OLD | NEW |