Home | History | Annotate | Download | only in metrics
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef COMPONENTS_METRICS_MACHINE_ID_PROVIDER_H_
      6 #define COMPONENTS_METRICS_MACHINE_ID_PROVIDER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/macros.h"
     11 #include "base/memory/ref_counted.h"
     12 
     13 namespace metrics {
     14 
     15 // Provides machine characteristics used as a machine id. The implementation is
     16 // platform specific with a default implementation that gives an empty id. The
     17 // class is ref-counted thread safe so it can be used to post to the FILE thread
     18 // and communicate back to the UI thread.
     19 // This raw machine id should not be stored or transmitted over the network.
     20 // TODO(jwd): Simplify implementation to get rid of the need for
     21 // RefCountedThreadSafe (crbug.com/354882).
     22 class MachineIdProvider : public base::RefCountedThreadSafe<MachineIdProvider> {
     23  public:
     24   // Get a string containing machine characteristics, to be used as a machine
     25   // id. The implementation is platform specific, with a default implementation
     26   // returning an empty string.
     27   // The return value should not be stored to disk or transmitted.
     28   std::string GetMachineId();
     29 
     30   // Returns a pointer to a new MachineIdProvider or NULL if there is no
     31   // provider implemented on a given platform. This is done to avoid posting a
     32   // task to the FILE thread on platforms with no implementation.
     33   static MachineIdProvider* CreateInstance();
     34 
     35  private:
     36   friend class base::RefCountedThreadSafe<MachineIdProvider>;
     37 
     38   MachineIdProvider();
     39   virtual ~MachineIdProvider();
     40 
     41   DISALLOW_COPY_AND_ASSIGN(MachineIdProvider);
     42 };
     43 
     44 }  //  namespace metrics
     45 
     46 #endif  // COMPONENTS_METRICS_MACHINE_ID_PROVIDER_H_
     47