Update lzma_sdk to 9.20
[chromium-blink-merge.git] / ipc / ipc_channel.cc
blob5973f722d0d67a9a84d587c4057bf341ebe5c7a6
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 namespace {
16 // Global atomic used to guarantee channel IDs are unique.
17 base::StaticAtomicSequenceNumber g_last_id;
19 } // namespace
21 namespace IPC {
23 // static
24 std::string Channel::GenerateUniqueRandomChannelID() {
25 // Note: the string must start with the current process id, this is how
26 // some child processes determine the pid of the parent.
28 // This is composed of a unique incremental identifier, the process ID of
29 // the creator, an identifier for the child instance, and a strong random
30 // component. The strong random component prevents other processes from
31 // hijacking or squatting on predictable channel names.
33 return base::StringPrintf("%d.%u.%d",
34 base::GetCurrentProcId(),
35 g_last_id.GetNext(),
36 base::RandInt(0, std::numeric_limits<int32>::max()));
39 } // namespace IPC