Rename isSystemLocationEnabled to isLocationEnabled, as per internal review (185995).
[chromium-blink-merge.git] / ipc / ipc_channel.cc
blob5f37a5a4db9290413a45c42abc26955393986427
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 namespace {
15 // Global atomic used to guarantee channel IDs are unique.
16 base::StaticAtomicSequenceNumber g_last_id;
18 } // namespace
20 namespace IPC {
22 // static
23 std::string Channel::GenerateUniqueRandomChannelID() {
24 // Note: the string must start with the current process id, this is how
25 // some child processes determine the pid of the parent.
27 // 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
29 // component. The strong random component prevents other processes from
30 // hijacking or squatting on predictable channel names.
32 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI)
33 // On Linux platform, PID does not play any security role.
34 // In nacl_helper_nonsfi, the seccomp sandbox disallows the use of getpid().
35 // So, for both cases, we provide a dummy PID.
36 int process_id = -1;
37 #else
38 int process_id = base::GetCurrentProcId();
39 #endif
40 return base::StringPrintf("%d.%u.%d",
41 process_id,
42 g_last_id.GetNext(),
43 base::RandInt(0, std::numeric_limits<int32>::max()));
46 } // namespace IPC