Revert 187575 "Change test_isolation_mode default from noop to c..."
[chromium-blink-merge.git] / ipc / ipc_channel.cc
blob5054fb6a91542cf71333a30a4c972ad697355fde
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
3 // found in the LICENSE file.
5 #include "ipc/ipc_channel.h"
7 #include <limits>
9 #include "base/atomic_sequence_num.h"
10 #include "base/process_util.h"
11 #include "base/rand_util.h"
12 #include "base/stringprintf.h"
14 #if !defined(OS_NACL)
15 namespace {
17 // Global atomic used to guarantee channel IDs are unique.
18 base::StaticAtomicSequenceNumber g_last_id;
20 } // namespace
21 #endif
23 namespace IPC {
25 // static
26 std::string Channel::GenerateUniqueRandomChannelID() {
27 // Note: the string must start with the current process id, this is how
28 // some child processes determine the pid of the parent.
30 // This is composed of a unique incremental identifier, the process ID of
31 // the creator, an identifier for the child instance, and a strong random
32 // component. The strong random component prevents other processes from
33 // hijacking or squatting on predictable channel names.
35 int process_id = base::GetCurrentProcId();
36 return base::StringPrintf("%d.%u.%d",
37 process_id,
38 g_last_id.GetNext(),
39 base::RandInt(0, std::numeric_limits<int32>::max()));
42 } // namespace IPC