Home | History | Annotate | Download | only in glue
      1 // Copyright (c) 2012 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 CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_
      6 #define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/bind.h"
     12 #include "sync/protocol/sync.pb.h"
     13 
     14 namespace base {
     15 class DictionaryValue;
     16 }
     17 
     18 namespace chrome {
     19 class VersionInfo;
     20 }
     21 
     22 namespace browser_sync {
     23 
     24 // A class that holds information regarding the properties of a device.
     25 class DeviceInfo {
     26  public:
     27   DeviceInfo(const std::string& guid,
     28              const std::string& client_name,
     29              const std::string& chrome_version,
     30              const std::string& sync_user_agent,
     31              const sync_pb::SyncEnums::DeviceType device_type);
     32   ~DeviceInfo();
     33 
     34   // Sync specific unique identifier for the device. Note if a device
     35   // is wiped and sync is set up again this id WILL be different.
     36   // The same device might have more than 1 guid if the device has multiple
     37   // accounts syncing.
     38   const std::string& guid() const;
     39 
     40   // The host name for the client.
     41   const std::string& client_name() const;
     42 
     43   // Chrome version string.
     44   const std::string& chrome_version() const;
     45 
     46   // The user agent is the combination of OS type, chrome version and which
     47   // channel of chrome(stable or beta). For more information see
     48   // |DeviceInfo::MakeUserAgentForSyncApi|.
     49   const std::string& sync_user_agent() const;
     50 
     51   // Third party visible id for the device. See |public_id_| for more details.
     52   const std::string& public_id() const;
     53 
     54   // Device Type.
     55   sync_pb::SyncEnums::DeviceType device_type() const;
     56 
     57   // Gets the OS in string form.
     58   std::string GetOSString() const;
     59 
     60   // Gets the device type in string form.
     61   std::string GetDeviceTypeString() const;
     62 
     63   // Compares this object's fields with another's.
     64   bool Equals(const DeviceInfo& other) const;
     65 
     66   // Apps can set ids for a device that is meaningful to them but
     67   // not unique enough so the user can be tracked. Exposing |guid|
     68   // would lead to a stable unique id for a device which can potentially
     69   // be used for tracking.
     70   void set_public_id(std::string id);
     71 
     72   // Converts the |DeviceInfo| values to a JS friendly DictionaryValue,
     73   // which extension APIs can expose to third party apps.
     74   base::DictionaryValue* ToValue();
     75 
     76   static sync_pb::SyncEnums::DeviceType GetLocalDeviceType();
     77 
     78   // Creates a |DeviceInfo| object representing the local device and passes
     79   // it as parameter to the callback.
     80   static void CreateLocalDeviceInfo(
     81       const std::string& guid,
     82       base::Callback<void(const DeviceInfo& local_info)> callback);
     83 
     84   // Gets the local device name and passes it as a parameter to callback.
     85   static void GetClientName(
     86       base::Callback<void(const std::string& local_info)> callback);
     87 
     88   // Helper to construct a user agent string (ASCII) suitable for use by
     89   // the syncapi for any HTTP communication. This string is used by the sync
     90   // backend for classifying client types when calculating statistics.
     91   static std::string MakeUserAgentForSyncApi(
     92       const chrome::VersionInfo& version_info);
     93 
     94  private:
     95   static void GetClientNameContinuation(
     96       base::Callback<void(const std::string& local_info)> callback,
     97       const std::string& session_name);
     98 
     99   static void CreateLocalDeviceInfoContinuation(
    100       const std::string& guid,
    101       base::Callback<void(const DeviceInfo& local_info)> callback,
    102       const std::string& session_name);
    103 
    104   const std::string guid_;
    105 
    106   const std::string client_name_;
    107 
    108   const std::string chrome_version_;
    109 
    110   const std::string sync_user_agent_;
    111 
    112   const sync_pb::SyncEnums::DeviceType device_type_;
    113 
    114   // Exposing |guid| would lead to a stable unique id for a device which
    115   // can potentially be used for tracking. Public ids are privacy safe
    116   // ids in that the same device will have different id for different apps
    117   // and they are also reset when app/extension is uninstalled.
    118   std::string public_id_;
    119 
    120   DISALLOW_COPY_AND_ASSIGN(DeviceInfo);
    121 };
    122 
    123 }  // namespace browser_sync
    124 
    125 #endif  // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_
    126