Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/bind.h" | 11 #include "base/callback.h" |
| 12 #include "sync/protocol/sync.pb.h" | 12 #include "sync/protocol/sync.pb.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 class DictionaryValue; | 15 class DictionaryValue; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace chrome { | |
| 19 class VersionInfo; | |
| 20 } | |
| 21 | |
| 22 namespace browser_sync { | 18 namespace browser_sync { |
| 23 | 19 |
| 24 // A class that holds information regarding the properties of a device. | 20 // A class that holds information regarding the properties of a device. |
| 25 class DeviceInfo { | 21 class DeviceInfo { |
| 26 public: | 22 public: |
| 27 DeviceInfo(const std::string& guid, | 23 DeviceInfo(const std::string& guid, |
| 28 const std::string& client_name, | 24 const std::string& client_name, |
| 29 const std::string& chrome_version, | 25 const std::string& chrome_version, |
| 30 const std::string& sync_user_agent, | 26 const std::string& sync_user_agent, |
| 31 const sync_pb::SyncEnums::DeviceType device_type, | 27 const sync_pb::SyncEnums::DeviceType device_type, |
| 32 const std::string& signin_scoped_device_id); | 28 const std::string& signin_scoped_device_id); |
| 33 ~DeviceInfo(); | 29 ~DeviceInfo(); |
| 34 | 30 |
| 35 // Sync specific unique identifier for the device. Note if a device | 31 // Sync specific unique identifier for the device. Note if a device |
| 36 // is wiped and sync is set up again this id WILL be different. | 32 // is wiped and sync is set up again this id WILL be different. |
| 37 // The same device might have more than 1 guid if the device has multiple | 33 // The same device might have more than 1 guid if the device has multiple |
| 38 // accounts syncing. | 34 // accounts syncing. |
| 39 const std::string& guid() const; | 35 const std::string& guid() const; |
| 40 | 36 |
| 41 // The host name for the client. | 37 // The host name for the client. |
| 42 const std::string& client_name() const; | 38 const std::string& client_name() const; |
| 43 | 39 |
| 44 // Chrome version string. | 40 // Chrome version string. |
| 45 const std::string& chrome_version() const; | 41 const std::string& chrome_version() const; |
| 46 | 42 |
| 47 // The user agent is the combination of OS type, chrome version and which | 43 // The user agent is the combination of OS type, chrome version and which |
| 48 // channel of chrome(stable or beta). For more information see | 44 // channel of chrome(stable or beta). For more information see |
| 49 // |DeviceInfo::MakeUserAgentForSyncApi|. | 45 // |LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi|. |
| 50 const std::string& sync_user_agent() const; | 46 const std::string& sync_user_agent() const; |
| 51 | 47 |
| 52 // Third party visible id for the device. See |public_id_| for more details. | 48 // Third party visible id for the device. See |public_id_| for more details. |
| 53 const std::string& public_id() const; | 49 const std::string& public_id() const; |
| 54 | 50 |
| 55 // Device Type. | 51 // Device Type. |
| 56 sync_pb::SyncEnums::DeviceType device_type() const; | 52 sync_pb::SyncEnums::DeviceType device_type() const; |
| 57 | 53 |
| 58 // Device_id that is stable until user signs out. This device_id is used for | 54 // Device_id that is stable until user signs out. This device_id is used for |
| 59 // annotating login scoped refresh token. | 55 // annotating login scoped refresh token. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 71 // Apps can set ids for a device that is meaningful to them but | 67 // Apps can set ids for a device that is meaningful to them but |
| 72 // not unique enough so the user can be tracked. Exposing |guid| | 68 // not unique enough so the user can be tracked. Exposing |guid| |
| 73 // would lead to a stable unique id for a device which can potentially | 69 // would lead to a stable unique id for a device which can potentially |
| 74 // be used for tracking. | 70 // be used for tracking. |
| 75 void set_public_id(std::string id); | 71 void set_public_id(std::string id); |
| 76 | 72 |
| 77 // Converts the |DeviceInfo| values to a JS friendly DictionaryValue, | 73 // Converts the |DeviceInfo| values to a JS friendly DictionaryValue, |
| 78 // which extension APIs can expose to third party apps. | 74 // which extension APIs can expose to third party apps. |
| 79 base::DictionaryValue* ToValue(); | 75 base::DictionaryValue* ToValue(); |
| 80 | 76 |
| 81 static sync_pb::SyncEnums::DeviceType GetLocalDeviceType(); | |
| 82 | |
| 83 // Creates a |DeviceInfo| object representing the local device and passes | |
| 84 // it as parameter to the callback. | |
| 85 static void CreateLocalDeviceInfo( | |
| 86 const std::string& guid, | |
| 87 const std::string& signin_scoped_device_id, | |
| 88 base::Callback<void(const DeviceInfo& local_info)> callback); | |
| 89 | |
| 90 // Gets the local device name and passes it as a parameter to callback. | 77 // Gets the local device name and passes it as a parameter to callback. |
| 91 static void GetClientName( | 78 static void GetClientName( |
| 92 base::Callback<void(const std::string& local_info)> callback); | 79 const base::Callback<void(const std::string& local_info)> callback); |
|
maniscalco
2014/09/23 16:28:27
You can make callback a reference parameter.
stanisc
2014/09/23 21:30:33
Done.
| |
| 93 | |
| 94 // Helper to construct a user agent string (ASCII) suitable for use by | |
| 95 // the syncapi for any HTTP communication. This string is used by the sync | |
| 96 // backend for classifying client types when calculating statistics. | |
| 97 static std::string MakeUserAgentForSyncApi( | |
| 98 const chrome::VersionInfo& version_info); | |
| 99 | 80 |
| 100 private: | 81 private: |
| 101 static void GetClientNameContinuation( | |
| 102 base::Callback<void(const std::string& local_info)> callback, | |
| 103 const std::string& session_name); | |
| 104 | |
| 105 static void CreateLocalDeviceInfoContinuation( | |
| 106 const std::string& guid, | |
| 107 const std::string& signin_scoped_device_id, | |
| 108 base::Callback<void(const DeviceInfo& local_info)> callback, | |
| 109 const std::string& session_name); | |
| 110 | |
| 111 const std::string guid_; | 82 const std::string guid_; |
| 112 | 83 |
| 113 const std::string client_name_; | 84 const std::string client_name_; |
| 114 | 85 |
| 115 const std::string chrome_version_; | 86 const std::string chrome_version_; |
| 116 | 87 |
| 117 const std::string sync_user_agent_; | 88 const std::string sync_user_agent_; |
| 118 | 89 |
| 119 const sync_pb::SyncEnums::DeviceType device_type_; | 90 const sync_pb::SyncEnums::DeviceType device_type_; |
| 120 | 91 |
| 121 std::string signin_scoped_device_id_; | 92 std::string signin_scoped_device_id_; |
| 122 | 93 |
| 123 // Exposing |guid| would lead to a stable unique id for a device which | 94 // Exposing |guid| would lead to a stable unique id for a device which |
| 124 // can potentially be used for tracking. Public ids are privacy safe | 95 // can potentially be used for tracking. Public ids are privacy safe |
| 125 // ids in that the same device will have different id for different apps | 96 // ids in that the same device will have different id for different apps |
| 126 // and they are also reset when app/extension is uninstalled. | 97 // and they are also reset when app/extension is uninstalled. |
| 127 std::string public_id_; | 98 std::string public_id_; |
| 128 | 99 |
| 129 DISALLOW_COPY_AND_ASSIGN(DeviceInfo); | 100 DISALLOW_COPY_AND_ASSIGN(DeviceInfo); |
| 130 }; | 101 }; |
| 131 | 102 |
| 132 } // namespace browser_sync | 103 } // namespace browser_sync |
| 133 | 104 |
| 134 #endif // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_ | 105 #endif // CHROME_BROWSER_SYNC_GLUE_DEVICE_INFO_H_ |
| OLD | NEW |