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 COMPONENTS_SYNC_DRIVER_DEVICE_INFO_H_
6#define COMPONENTS_SYNC_DRIVER_DEVICE_INFO_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/callback.h"
12#include "sync/protocol/sync.pb.h"
13
14namespace base {
15class DictionaryValue;
16}
17
18namespace sync_driver {
19
20// A class that holds information regarding the properties of a device.
21class DeviceInfo {
22 public:
23  DeviceInfo(const std::string& guid,
24             const std::string& client_name,
25             const std::string& chrome_version,
26             const std::string& sync_user_agent,
27             const sync_pb::SyncEnums::DeviceType device_type,
28             const std::string& signin_scoped_device_id);
29  ~DeviceInfo();
30
31  // Sync specific unique identifier for the device. Note if a device
32  // is wiped and sync is set up again this id WILL be different.
33  // The same device might have more than 1 guid if the device has multiple
34  // accounts syncing.
35  const std::string& guid() const;
36
37  // The host name for the client.
38  const std::string& client_name() const;
39
40  // Chrome version string.
41  const std::string& chrome_version() const;
42
43  // The user agent is the combination of OS type, chrome version and which
44  // channel of chrome(stable or beta). For more information see
45  // |LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi|.
46  const std::string& sync_user_agent() const;
47
48  // Third party visible id for the device. See |public_id_| for more details.
49  const std::string& public_id() const;
50
51  // Device Type.
52  sync_pb::SyncEnums::DeviceType device_type() const;
53
54  // Device_id that is stable until user signs out. This device_id is used for
55  // annotating login scoped refresh token.
56  const std::string& signin_scoped_device_id() const;
57
58  // Gets the OS in string form.
59  std::string GetOSString() const;
60
61  // Gets the device type in string form.
62  std::string GetDeviceTypeString() const;
63
64  // Compares this object's fields with another's.
65  bool Equals(const DeviceInfo& other) const;
66
67  // Apps can set ids for a device that is meaningful to them but
68  // not unique enough so the user can be tracked. Exposing |guid|
69  // would lead to a stable unique id for a device which can potentially
70  // be used for tracking.
71  void set_public_id(std::string id);
72
73  // Converts the |DeviceInfo| values to a JS friendly DictionaryValue,
74  // which extension APIs can expose to third party apps.
75  base::DictionaryValue* ToValue();
76
77 private:
78  const std::string guid_;
79
80  const std::string client_name_;
81
82  const std::string chrome_version_;
83
84  const std::string sync_user_agent_;
85
86  const sync_pb::SyncEnums::DeviceType device_type_;
87
88  std::string signin_scoped_device_id_;
89
90  // Exposing |guid| would lead to a stable unique id for a device which
91  // can potentially be used for tracking. Public ids are privacy safe
92  // ids in that the same device will have different id for different apps
93  // and they are also reset when app/extension is uninstalled.
94  std::string public_id_;
95
96  DISALLOW_COPY_AND_ASSIGN(DeviceInfo);
97};
98
99}  // namespace sync_driver
100
101#endif  // COMPONENTS_SYNC_DRIVER_DEVICE_INFO_H_
102