Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
adamta | 33cf2a4 | 2020-03-06 17:51:16 | [diff] [blame] | 2 | // 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 Dorwin | 3f503b8 | 2022-04-20 04:07:03 | [diff] [blame] | 9 | #include "base/check.h" |
adamta | 33cf2a4 | 2020-03-06 17:51:16 | [diff] [blame] | 10 | #include "base/system/sys_info.h" |
| 11 | |
| 12 | namespace metrics { |
| 13 | |
| 14 | // Checks if hardware model name is available. |
| 15 | bool 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. |
| 21 | std::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 |