Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / ipc / ipc_channel.cc
bloba6ee14c01fcb10b95cc2d20e5aa3c13ab02f67e7
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/rand_util.h"
11 #include "base/strings/stringprintf.h"
13 #if !defined(OS_NACL)
14 namespace {
16 // Global atomic used to guarantee channel IDs are unique.
17 base::StaticAtomicSequenceNumber g_last_id;
19 } // namespace
20 #endif
22 namespace IPC {
24 // static
25 std::string Channel::GenerateUniqueRandomChannelID() {
26 // Note: the string must start with the current process id, this is how
27 // some child processes determine the pid of the parent.
29 // 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
31 // component. The strong random component prevents other processes from
32 // hijacking or squatting on predictable channel names.
34 int process_id = base::GetCurrentProcId();
35 return base::StringPrintf("%d.%u.%d",
36 process_id,
37 g_last_id.GetNext(),
38 base::RandInt(0, std::numeric_limits<int32>::max()));
41 } // namespace IPC