summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/glue/device_info.h
blob: d94a9bc2b5637156d3206d73259aa6adfc6b29c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_
#define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_

#include <string>

#include "base/basictypes.h"
#include "base/bind.h"
#include "sync/protocol/sync.pb.h"

namespace base {
class DictionaryValue;
}

namespace chrome {
class VersionInfo;
}

namespace browser_sync {

// A class that holds information regarding the properties of a device.
class DeviceInfo {
 public:
  DeviceInfo(const std::string& guid,
             const std::string& client_name,
             const std::string& chrome_version,
             const std::string& sync_user_agent,
             const sync_pb::SyncEnums::DeviceType device_type);
  ~DeviceInfo();

  // Sync specific unique identifier for the device. Note if a device
  // is wiped and sync is set up again this id WILL be different.
  // The same device might have more than 1 guid if the device has multiple
  // accounts syncing.
  const std::string& guid() const;

  // The host name for the client.
  const std::string& client_name() const;

  // Chrome version string.
  const std::string& chrome_version() const;

  // The user agent is the combination of OS type, chrome version and which
  // channel of chrome(stable or beta). For more information see
  // |DeviceInfo::MakeUserAgentForSyncApi|.
  const std::string& sync_user_agent() const;

  // Third party visible id for the device. See |public_id_| for more details.
  const std::string& public_id() const;

  // Device Type.
  sync_pb::SyncEnums::DeviceType device_type() const;

  // Gets the OS in string form.
  std::string GetOSString() const;

  // Gets the device type in string form.
  std::string GetDeviceTypeString() const;

  // Compares this object's fields with another's.
  bool Equals(const DeviceInfo& other) const;

  // Apps can set ids for a device that is meaningful to them but
  // not unique enough so the user can be tracked. Exposing |guid|
  // would lead to a stable unique id for a device which can potentially
  // be used for tracking.
  void set_public_id(std::string id);

  // Converts the |DeviceInfo| values to a JS friendly DictionaryValue,
  // which extension APIs can expose to third party apps.
  base::DictionaryValue* ToValue();

  static sync_pb::SyncEnums::DeviceType GetLocalDeviceType();

  // Creates a |DeviceInfo| object representing the local device and passes
  // it as parameter to the callback.
  static void CreateLocalDeviceInfo(
      const std::string& guid,
      base::Callback<void(const DeviceInfo& local_info)> callback);

  // Gets the local device name and passes it as a parameter to callback.
  static void GetClientName(
      base::Callback<void(const std::string& local_info)> callback);

  // Helper to construct a user agent string (ASCII) suitable for use by
  // the syncapi for any HTTP communication. This string is used by the sync
  // backend for classifying client types when calculating statistics.
  static std::string MakeUserAgentForSyncApi(
      const chrome::VersionInfo& version_info);

 private:
  static void GetClientNameContinuation(
      base::Callback<void(const std::string& local_info)> callback,
      const std::string& session_name);

  static void CreateLocalDeviceInfoContinuation(
      const std::string& guid,
      base::Callback<void(const DeviceInfo& local_info)> callback,
      const std::string& session_name);

  const std::string guid_;

  const std::string client_name_;

  const std::string chrome_version_;

  const std::string sync_user_agent_;

  const sync_pb::SyncEnums::DeviceType device_type_;

  // Exposing |guid| would lead to a stable unique id for a device which
  // can potentially be used for tracking. Public ids are privacy safe
  // ids in that the same device will have different id for different apps
  // and they are also reset when app/extension is uninstalled.
  std::string public_id_;

  DISALLOW_COPY_AND_ASSIGN(DeviceInfo);
};

}  // namespace browser_sync

#endif  // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_