blob: c419b312a3f2c2d599e29f0f39843f79af98bd6f [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2020 The Chromium Authors
adamta33cf2a42020-03-06 17:51:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/metrics/machine_id_provider.h"
6
7#include <stdint.h>
8
David Dorwin3f503b82022-04-20 04:07:039#include "base/check.h"
adamta33cf2a42020-03-06 17:51:1610#include "base/system/sys_info.h"
11
12namespace metrics {
13
14// Checks if hardware model name is available.
15bool MachineIdProvider::HasId() {
16 return !base::SysInfo::HardwareModelName().empty();
17}
18
19// On non-windows, the machine id is based on the hardware model name.
20// This will suffice as users are unlikely to change to the same machine model.
21std::string MachineIdProvider::GetMachineId() {
22 // Gets hardware model name. (e.g. 'Macbook Pro 16,1', 'iPhone 9,3')
23 std::string hardware_model_name = base::SysInfo::HardwareModelName();
24
25 // This function should not be called if hardware model name is unavailable.
26 DCHECK(!hardware_model_name.empty());
27
28 return hardware_model_name;
29}
30} // namespace metrics