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 #if !defined(OS_NACL_SFI) | |
7 #include <limits> | 8 #include <limits> |
8 | 9 |
9 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
10 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #endif // !defined(OS_NACL_SFI) | |
Tom Sepez
2015/07/30 00:35:47
nit: maybe combine this with line 15
erikchen
2015/07/30 01:38:19
Moving the constructor to the header means these c
| |
12 | 14 |
15 #if !defined(OS_NACL_SFI) | |
13 namespace { | 16 namespace { |
14 | 17 |
15 // Global atomic used to guarantee channel IDs are unique. | 18 // Global atomic used to guarantee channel IDs are unique. |
16 base::StaticAtomicSequenceNumber g_last_id; | 19 base::StaticAtomicSequenceNumber g_last_id; |
17 | 20 |
18 } // namespace | 21 } // namespace |
22 #endif // !defined(OS_NACL_SFI) | |
19 | 23 |
20 namespace IPC { | 24 namespace IPC { |
21 | 25 |
26 Channel::Channel() : attachment_broker_endpoint_(false) {} | |
Tom Sepez
2015/07/30 00:35:47
Hmm. If this were in the header, could we avoid t
erikchen
2015/07/30 01:38:19
Good suggestion! Done.
| |
27 | |
28 #if !defined(OS_NACL_SFI) | |
22 // static | 29 // static |
23 std::string Channel::GenerateUniqueRandomChannelID() { | 30 std::string Channel::GenerateUniqueRandomChannelID() { |
24 // Note: the string must start with the current process id, this is how | 31 // Note: the string must start with the current process id, this is how |
25 // some child processes determine the pid of the parent. | 32 // some child processes determine the pid of the parent. |
26 // | 33 // |
27 // This is composed of a unique incremental identifier, the process ID of | 34 // This is composed of a unique incremental identifier, the process ID of |
28 // the creator, an identifier for the child instance, and a strong random | 35 // the creator, an identifier for the child instance, and a strong random |
29 // component. The strong random component prevents other processes from | 36 // component. The strong random component prevents other processes from |
30 // hijacking or squatting on predictable channel names. | 37 // hijacking or squatting on predictable channel names. |
31 #if defined(OS_NACL_NONSFI) | 38 #if defined(OS_NACL_NONSFI) |
32 // The seccomp sandbox disallows use of getpid(), so we provide a | 39 // The seccomp sandbox disallows use of getpid(), so we provide a |
33 // dummy PID. | 40 // dummy PID. |
34 int process_id = -1; | 41 int process_id = -1; |
35 #else | 42 #else |
36 int process_id = base::GetCurrentProcId(); | 43 int process_id = base::GetCurrentProcId(); |
37 #endif | 44 #endif |
38 return base::StringPrintf("%d.%u.%d", | 45 return base::StringPrintf("%d.%u.%d", |
39 process_id, | 46 process_id, |
40 g_last_id.GetNext(), | 47 g_last_id.GetNext(), |
41 base::RandInt(0, std::numeric_limits<int32>::max())); | 48 base::RandInt(0, std::numeric_limits<int32>::max())); |
42 } | 49 } |
50 #endif // !defined(OS_NACL_SFI) | |
43 | 51 |
44 } // namespace IPC | 52 } // namespace IPC |
OLD | NEW |