xref: /aosp_15_r20/external/cronet/components/metrics/machine_id_provider.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2014 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef COMPONENTS_METRICS_MACHINE_ID_PROVIDER_H_
6*6777b538SAndroid Build Coastguard Worker #define COMPONENTS_METRICS_MACHINE_ID_PROVIDER_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include <string>
9*6777b538SAndroid Build Coastguard Worker 
10*6777b538SAndroid Build Coastguard Worker namespace metrics {
11*6777b538SAndroid Build Coastguard Worker 
12*6777b538SAndroid Build Coastguard Worker // Provides machine characteristics used as a machine id. The implementation is
13*6777b538SAndroid Build Coastguard Worker // platform specific. GetMachineId() must be called on a thread which allows
14*6777b538SAndroid Build Coastguard Worker // I/O. GetMachineId() must not be called if HasId() returns false on this
15*6777b538SAndroid Build Coastguard Worker // platform.
16*6777b538SAndroid Build Coastguard Worker class MachineIdProvider {
17*6777b538SAndroid Build Coastguard Worker  public:
18*6777b538SAndroid Build Coastguard Worker   MachineIdProvider() = delete;
19*6777b538SAndroid Build Coastguard Worker   MachineIdProvider(const MachineIdProvider&) = delete;
20*6777b538SAndroid Build Coastguard Worker   MachineIdProvider& operator=(const MachineIdProvider&) = delete;
21*6777b538SAndroid Build Coastguard Worker 
22*6777b538SAndroid Build Coastguard Worker   // Returns true if this platform provides a non-empty GetMachineId(). This is
23*6777b538SAndroid Build Coastguard Worker   // useful to avoid an async call to GetMachineId() on platforms with no
24*6777b538SAndroid Build Coastguard Worker   // implementation.
25*6777b538SAndroid Build Coastguard Worker   static bool HasId();
26*6777b538SAndroid Build Coastguard Worker 
27*6777b538SAndroid Build Coastguard Worker   // Get a string containing machine characteristics, to be used as a machine
28*6777b538SAndroid Build Coastguard Worker   // id. The implementation is split into Windows and non-Windows. The former
29*6777b538SAndroid Build Coastguard Worker   // returns the drive serial number and the latter returns the hardware
30*6777b538SAndroid Build Coastguard Worker   // model name. Should not be called if HasId() returns false.
31*6777b538SAndroid Build Coastguard Worker   // The return value should not be stored to disk or transmitted.
32*6777b538SAndroid Build Coastguard Worker   static std::string GetMachineId();
33*6777b538SAndroid Build Coastguard Worker };
34*6777b538SAndroid Build Coastguard Worker 
35*6777b538SAndroid Build Coastguard Worker }  //  namespace metrics
36*6777b538SAndroid Build Coastguard Worker 
37*6777b538SAndroid Build Coastguard Worker #endif  // COMPONENTS_METRICS_MACHINE_ID_PROVIDER_H_
38