blob: 0e75f8cf98ac171d21633f73ea387a9c3552842b [file] [log] [blame]
Elly Jonesa44d22d2012-01-05 18:05:56 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Elly Jonese7cb5b32011-12-01 14:18:32 -05002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Alex Vakulenko262be3f2014-07-30 15:25:50 -07005#include "debugd/src/process_with_id.h"
Elly Jonese7cb5b32011-12-01 14:18:32 -05006
Ben Chan92f092e2017-02-15 11:55:47 -08007#include <base/rand_util.h>
Ben Chan9953a592014-02-05 23:32:00 -08008#include <base/strings/string_number_conversions.h>
Elly Jonese7cb5b32011-12-01 14:18:32 -05009
10namespace debugd {
11
Ben Chan92f092e2017-02-15 11:55:47 -080012namespace {
13
14constexpr int kNumRandomBytesInId = 16;
15
16} // namespace
17
Elly Jonese7cb5b32011-12-01 14:18:32 -050018bool ProcessWithId::Init() {
Ben Chan92f092e2017-02-15 11:55:47 -080019 if (SandboxedProcess::Init()) {
20 GenerateId();
21 return true;
22 }
23 return false;
Elly Jonese7cb5b32011-12-01 14:18:32 -050024}
25
Ben Chan92f092e2017-02-15 11:55:47 -080026void ProcessWithId::GenerateId() {
27 std::string random_bytes = base::RandBytesAsString(kNumRandomBytesInId);
28 id_ = base::HexEncode(random_bytes.data(), random_bytes.size());
Elly Jonese7cb5b32011-12-01 14:18:32 -050029}
30
Ben Chana0011d82014-05-13 00:19:29 -070031} // namespace debugd