blob: 69a3331ded7c0dc4c90942d4a678e4271d81e222 [file] [log] [blame]
[email protected]34e98172012-10-12 04:01:391// 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
maxboguef1885f7d2016-08-16 19:13:205#ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_
6#define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_
[email protected]34e98172012-10-12 04:01:397
skym6d5ecf82016-10-04 17:43:458#include <memory>
Alex Chau4e13d9b62019-09-30 17:09:599#include <set>
[email protected]34e98172012-10-12 04:01:3910#include <string>
11
stanisc10528752014-09-23 21:52:1912#include "base/callback.h"
avi5dd91f82015-12-25 22:30:4613#include "base/macros.h"
Alex Chau4e13d9b62019-09-30 17:09:5914#include "base/optional.h"
Himanshu Jaju0ddf2c132019-10-10 16:22:2815#include "base/system/sys_info.h"
Sébastien Séguin-Gagnonb7cc9252019-05-09 22:00:3916#include "base/time/time.h"
Max Boguefef332d2016-07-28 22:09:0917#include "components/sync/protocol/sync.pb.h"
[email protected]34e98172012-10-12 04:01:3918
[email protected]648a5662013-07-18 20:45:4519namespace base {
20class DictionaryValue;
21}
22
maxbogue7e006db2016-10-03 19:48:2823namespace syncer {
[email protected]34e98172012-10-12 04:01:3924
25// A class that holds information regarding the properties of a device.
[email protected]34e98172012-10-12 04:01:3926class DeviceInfo {
27 public:
Alex Chau965a5a22019-11-18 16:51:5828 // A struct that holds information regarding to FCM web push.
29 struct SharingTargetInfo {
30 // FCM registration token of device.
31 std::string fcm_token;
32
33 // Public key for Sharing message encryption[RFC8291].
34 std::string p256dh;
35
36 // Auth secret for Sharing message encryption[RFC8291].
37 std::string auth_secret;
38
39 bool operator==(const SharingTargetInfo& other) const;
40 };
41
42 // A struct that holds information regarding to Sharing features.
Alex Chau4e13d9b62019-09-30 17:09:5943 struct SharingInfo {
Alex Chau965a5a22019-11-18 16:51:5844 SharingInfo(SharingTargetInfo vapid_target_info,
45 SharingTargetInfo sharing_target_info,
Alex Chau4e13d9b62019-09-30 17:09:5946 std::set<sync_pb::SharingSpecificFields::EnabledFeatures>
47 enabled_features);
48 SharingInfo(const SharingInfo& other);
49 SharingInfo(SharingInfo&& other);
50 SharingInfo& operator=(const SharingInfo& other);
51 ~SharingInfo();
52
Alex Chau965a5a22019-11-18 16:51:5853 // Target info using VAPID key.
54 // TODO(crbug.com/1012226): Deprecate when VAPID migration is over.
55 SharingTargetInfo vapid_target_info;
Alex Chauf1de5182019-11-14 14:19:1656
Alex Chau965a5a22019-11-18 16:51:5857 // Target info using Sharing sender ID.
58 SharingTargetInfo sender_id_target_info;
Alex Chau4e13d9b62019-09-30 17:09:5959
60 // Set of Sharing features enabled on the device.
61 std::set<sync_pb::SharingSpecificFields::EnabledFeatures> enabled_features;
62
63 bool operator==(const SharingInfo& other) const;
64 };
65
[email protected]1e281a42013-07-16 23:04:0866 DeviceInfo(const std::string& guid,
67 const std::string& client_name,
[email protected]34e98172012-10-12 04:01:3968 const std::string& chrome_version,
69 const std::string& sync_user_agent,
[email protected]e0ec8ba2014-07-18 23:38:0470 const sync_pb::SyncEnums::DeviceType device_type,
Tanya Guptac1dec1c2019-04-18 22:56:0571 const std::string& signin_scoped_device_id,
Himanshu Jaju0ddf2c132019-10-10 16:22:2872 const base::SysInfo::HardwareInfo& hardware_info,
Sébastien Séguin-Gagnonb7cc9252019-05-09 22:00:3973 base::Time last_updated_timestamp,
Alex Chau4e13d9b62019-09-30 17:09:5974 bool send_tab_to_self_receiving_enabled,
75 const base::Optional<SharingInfo>& sharing_info);
[email protected]34e98172012-10-12 04:01:3976 ~DeviceInfo();
77
[email protected]1e281a42013-07-16 23:04:0878 // Sync specific unique identifier for the device. Note if a device
79 // is wiped and sync is set up again this id WILL be different.
80 // The same device might have more than 1 guid if the device has multiple
81 // accounts syncing.
82 const std::string& guid() const;
83
84 // The host name for the client.
[email protected]34e98172012-10-12 04:01:3985 const std::string& client_name() const;
[email protected]1e281a42013-07-16 23:04:0886
87 // Chrome version string.
[email protected]34e98172012-10-12 04:01:3988 const std::string& chrome_version() const;
[email protected]1e281a42013-07-16 23:04:0889
90 // The user agent is the combination of OS type, chrome version and which
91 // channel of chrome(stable or beta). For more information see
stanisc10528752014-09-23 21:52:1992 // |LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi|.
[email protected]34e98172012-10-12 04:01:3993 const std::string& sync_user_agent() const;
[email protected]1e281a42013-07-16 23:04:0894
[email protected]790daf5c2013-07-31 18:42:5795 // Third party visible id for the device. See |public_id_| for more details.
96 const std::string& public_id() const;
97
[email protected]1e281a42013-07-16 23:04:0898 // Device Type.
[email protected]34e98172012-10-12 04:01:3999 sync_pb::SyncEnums::DeviceType device_type() const;
100
[email protected]e0ec8ba2014-07-18 23:38:04101 // Device_id that is stable until user signs out. This device_id is used for
102 // annotating login scoped refresh token.
103 const std::string& signin_scoped_device_id() const;
104
Himanshu Jaju0ddf2c132019-10-10 16:22:28105 const base::SysInfo::HardwareInfo& hardware_info() const;
106
Sébastien Séguin-Gagnonb7cc9252019-05-09 22:00:39107 // Returns the time at which this device was last updated to the sync servers.
108 base::Time last_updated_timestamp() const;
109
Tanya Guptac1dec1c2019-04-18 22:56:05110 // Whether the receiving side of the SendTabToSelf feature is enabled.
111 bool send_tab_to_self_receiving_enabled() const;
112
Alex Chau4e13d9b62019-09-30 17:09:59113 // Returns Sharing related info of the device.
114 const base::Optional<SharingInfo>& sharing_info() const;
115
[email protected]f32d8ce2013-09-24 04:38:40116 // Gets the OS in string form.
117 std::string GetOSString() const;
118
119 // Gets the device type in string form.
120 std::string GetDeviceTypeString() const;
121
[email protected]34e98172012-10-12 04:01:39122 // Compares this object's fields with another's.
123 bool Equals(const DeviceInfo& other) const;
124
[email protected]648a5662013-07-18 20:45:45125 // Apps can set ids for a device that is meaningful to them but
126 // not unique enough so the user can be tracked. Exposing |guid|
127 // would lead to a stable unique id for a device which can potentially
128 // be used for tracking.
ki.stfu939799a42015-09-28 04:41:20129 void set_public_id(const std::string& id);
[email protected]648a5662013-07-18 20:45:45130
Tanya Guptac1dec1c2019-04-18 22:56:05131 void set_send_tab_to_self_receiving_enabled(bool new_value);
132
Alex Chau4e13d9b62019-09-30 17:09:59133 void set_sharing_info(const base::Optional<SharingInfo>& sharing_info);
134
Himanshu Jajuf2c5d732019-10-21 14:52:33135 void set_client_name(const std::string& client_name);
136
[email protected]648a5662013-07-18 20:45:45137 // Converts the |DeviceInfo| values to a JS friendly DictionaryValue,
138 // which extension APIs can expose to third party apps.
dcheng32fd7c42016-08-27 11:16:06139 std::unique_ptr<base::DictionaryValue> ToValue();
[email protected]648a5662013-07-18 20:45:45140
[email protected]34e98172012-10-12 04:01:39141 private:
[email protected]1e281a42013-07-16 23:04:08142 const std::string guid_;
143
Himanshu Jajuf2c5d732019-10-21 14:52:33144 std::string client_name_;
[email protected]1e281a42013-07-16 23:04:08145
[email protected]34e98172012-10-12 04:01:39146 const std::string chrome_version_;
[email protected]1e281a42013-07-16 23:04:08147
[email protected]34e98172012-10-12 04:01:39148 const std::string sync_user_agent_;
[email protected]1e281a42013-07-16 23:04:08149
[email protected]34e98172012-10-12 04:01:39150 const sync_pb::SyncEnums::DeviceType device_type_;
[email protected]16b85e82012-11-21 04:16:33151
[email protected]e0ec8ba2014-07-18 23:38:04152 std::string signin_scoped_device_id_;
153
[email protected]790daf5c2013-07-31 18:42:57154 // Exposing |guid| would lead to a stable unique id for a device which
155 // can potentially be used for tracking. Public ids are privacy safe
156 // ids in that the same device will have different id for different apps
157 // and they are also reset when app/extension is uninstalled.
[email protected]648a5662013-07-18 20:45:45158 std::string public_id_;
159
Himanshu Jaju0ddf2c132019-10-10 16:22:28160 base::SysInfo::HardwareInfo hardware_info_;
161
Sébastien Séguin-Gagnonb7cc9252019-05-09 22:00:39162 const base::Time last_updated_timestamp_;
163
Tanya Guptac1dec1c2019-04-18 22:56:05164 bool send_tab_to_self_receiving_enabled_;
165
Alex Chau4e13d9b62019-09-30 17:09:59166 base::Optional<SharingInfo> sharing_info_;
167
[email protected]16b85e82012-11-21 04:16:33168 DISALLOW_COPY_AND_ASSIGN(DeviceInfo);
[email protected]34e98172012-10-12 04:01:39169};
170
maxbogue7e006db2016-10-03 19:48:28171} // namespace syncer
[email protected]34e98172012-10-12 04:01:39172
maxboguef1885f7d2016-08-16 19:13:20173#endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_