• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium Authors
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 
9 #include "base/check.h"
10 #include "base/system/sys_info.h"
11 
12 namespace metrics {
13 
14 // Checks if hardware model name is available.
HasId()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.
GetMachineId()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
31