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 #include "chrome/browser/sync/glue/device_info.h" | 5 #include "chrome/browser/sync/glue/device_info.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 return "canary"; | 32 return "canary"; |
33 case chrome::VersionInfo::CHANNEL_DEV: | 33 case chrome::VersionInfo::CHANNEL_DEV: |
34 return "dev"; | 34 return "dev"; |
35 case chrome::VersionInfo::CHANNEL_BETA: | 35 case chrome::VersionInfo::CHANNEL_BETA: |
36 return "beta"; | 36 return "beta"; |
37 case chrome::VersionInfo::CHANNEL_STABLE: | 37 case chrome::VersionInfo::CHANNEL_STABLE: |
38 return "stable"; | 38 return "stable"; |
39 default: | 39 default: |
40 NOTREACHED(); | 40 NOTREACHED(); |
41 return "unknown"; | 41 return "unknown"; |
42 }; | 42 } |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 DeviceInfo::DeviceInfo(const std::string& guid, | 47 DeviceInfo::DeviceInfo(const std::string& guid, |
48 const std::string& client_name, | 48 const std::string& client_name, |
49 const std::string& chrome_version, | 49 const std::string& chrome_version, |
50 const std::string& sync_user_agent, | 50 const std::string& sync_user_agent, |
51 const sync_pb::SyncEnums::DeviceType device_type) | 51 const sync_pb::SyncEnums::DeviceType device_type, |
| 52 const std::string& signin_scoped_device_id) |
52 : guid_(guid), | 53 : guid_(guid), |
53 client_name_(client_name), | 54 client_name_(client_name), |
54 chrome_version_(chrome_version), | 55 chrome_version_(chrome_version), |
55 sync_user_agent_(sync_user_agent), | 56 sync_user_agent_(sync_user_agent), |
56 device_type_(device_type) { | 57 device_type_(device_type), |
| 58 signin_scoped_device_id_(signin_scoped_device_id) { |
57 } | 59 } |
58 | 60 |
59 DeviceInfo::~DeviceInfo() { } | 61 DeviceInfo::~DeviceInfo() { } |
60 | 62 |
61 const std::string& DeviceInfo::guid() const { | 63 const std::string& DeviceInfo::guid() const { |
62 return guid_; | 64 return guid_; |
63 } | 65 } |
64 | 66 |
65 const std::string& DeviceInfo::client_name() const { | 67 const std::string& DeviceInfo::client_name() const { |
66 return client_name_; | 68 return client_name_; |
67 } | 69 } |
68 | 70 |
69 const std::string& DeviceInfo::chrome_version() const { | 71 const std::string& DeviceInfo::chrome_version() const { |
70 return chrome_version_; | 72 return chrome_version_; |
71 } | 73 } |
72 | 74 |
73 const std::string& DeviceInfo::sync_user_agent() const { | 75 const std::string& DeviceInfo::sync_user_agent() const { |
74 return sync_user_agent_; | 76 return sync_user_agent_; |
75 } | 77 } |
76 | 78 |
77 const std::string& DeviceInfo::public_id() const { | 79 const std::string& DeviceInfo::public_id() const { |
78 return public_id_; | 80 return public_id_; |
79 } | 81 } |
80 | 82 |
81 sync_pb::SyncEnums::DeviceType DeviceInfo::device_type() const { | 83 sync_pb::SyncEnums::DeviceType DeviceInfo::device_type() const { |
82 return device_type_; | 84 return device_type_; |
83 } | 85 } |
84 | 86 |
| 87 const std::string& DeviceInfo::signin_scoped_device_id() const { |
| 88 return signin_scoped_device_id_; |
| 89 } |
| 90 |
85 std::string DeviceInfo::GetOSString() const { | 91 std::string DeviceInfo::GetOSString() const { |
86 switch (device_type_) { | 92 switch (device_type_) { |
87 case sync_pb::SyncEnums_DeviceType_TYPE_WIN: | 93 case sync_pb::SyncEnums_DeviceType_TYPE_WIN: |
88 return "win"; | 94 return "win"; |
89 case sync_pb::SyncEnums_DeviceType_TYPE_MAC: | 95 case sync_pb::SyncEnums_DeviceType_TYPE_MAC: |
90 return "mac"; | 96 return "mac"; |
91 case sync_pb::SyncEnums_DeviceType_TYPE_LINUX: | 97 case sync_pb::SyncEnums_DeviceType_TYPE_LINUX: |
92 return "linux"; | 98 return "linux"; |
93 case sync_pb::SyncEnums_DeviceType_TYPE_CROS: | 99 case sync_pb::SyncEnums_DeviceType_TYPE_CROS: |
94 return "chrome_os"; | 100 return "chrome_os"; |
(...skipping 17 matching lines...) Expand all Loading... |
112 case sync_pb::SyncEnums_DeviceType_TYPE_PHONE: | 118 case sync_pb::SyncEnums_DeviceType_TYPE_PHONE: |
113 return "phone"; | 119 return "phone"; |
114 case sync_pb::SyncEnums_DeviceType_TYPE_TABLET: | 120 case sync_pb::SyncEnums_DeviceType_TYPE_TABLET: |
115 return "tablet"; | 121 return "tablet"; |
116 default: | 122 default: |
117 return "unknown"; | 123 return "unknown"; |
118 } | 124 } |
119 } | 125 } |
120 | 126 |
121 bool DeviceInfo::Equals(const DeviceInfo& other) const { | 127 bool DeviceInfo::Equals(const DeviceInfo& other) const { |
122 return this->guid() == other.guid() | 128 return this->guid() == other.guid() && |
123 && this->client_name() == other.client_name() | 129 this->client_name() == other.client_name() && |
124 && this->chrome_version() == other.chrome_version() | 130 this->chrome_version() == other.chrome_version() && |
125 && this->sync_user_agent() == other.sync_user_agent() | 131 this->sync_user_agent() == other.sync_user_agent() && |
126 && this->device_type() == other.device_type(); | 132 this->device_type() == other.device_type() && |
| 133 this->signin_scoped_device_id() == other.signin_scoped_device_id(); |
127 } | 134 } |
128 | 135 |
129 // static. | 136 // static. |
130 sync_pb::SyncEnums::DeviceType DeviceInfo::GetLocalDeviceType() { | 137 sync_pb::SyncEnums::DeviceType DeviceInfo::GetLocalDeviceType() { |
131 #if defined(OS_CHROMEOS) | 138 #if defined(OS_CHROMEOS) |
132 return sync_pb::SyncEnums_DeviceType_TYPE_CROS; | 139 return sync_pb::SyncEnums_DeviceType_TYPE_CROS; |
133 #elif defined(OS_LINUX) | 140 #elif defined(OS_LINUX) |
134 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; | 141 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; |
135 #elif defined(OS_MACOSX) | 142 #elif defined(OS_MACOSX) |
136 return sync_pb::SyncEnums_DeviceType_TYPE_MAC; | 143 return sync_pb::SyncEnums_DeviceType_TYPE_MAC; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return value; | 202 return value; |
196 } | 203 } |
197 | 204 |
198 void DeviceInfo::set_public_id(std::string id) { | 205 void DeviceInfo::set_public_id(std::string id) { |
199 public_id_ = id; | 206 public_id_ = id; |
200 } | 207 } |
201 | 208 |
202 // static. | 209 // static. |
203 void DeviceInfo::CreateLocalDeviceInfo( | 210 void DeviceInfo::CreateLocalDeviceInfo( |
204 const std::string& guid, | 211 const std::string& guid, |
| 212 const std::string& signin_scoped_device_id, |
205 base::Callback<void(const DeviceInfo& local_info)> callback) { | 213 base::Callback<void(const DeviceInfo& local_info)> callback) { |
206 GetClientName( | 214 GetClientName(base::Bind(&DeviceInfo::CreateLocalDeviceInfoContinuation, |
207 base::Bind(&DeviceInfo::CreateLocalDeviceInfoContinuation, | 215 guid, |
208 guid, | 216 signin_scoped_device_id, |
209 callback)); | 217 callback)); |
210 } | 218 } |
211 | 219 |
212 // static. | 220 // static. |
213 void DeviceInfo::GetClientName( | 221 void DeviceInfo::GetClientName( |
214 base::Callback<void(const std::string& client_name)> callback) { | 222 base::Callback<void(const std::string& client_name)> callback) { |
215 syncer::GetSessionName( | 223 syncer::GetSessionName( |
216 content::BrowserThread::GetBlockingPool(), | 224 content::BrowserThread::GetBlockingPool(), |
217 base::Bind(&DeviceInfo::GetClientNameContinuation, | 225 base::Bind(&DeviceInfo::GetClientNameContinuation, |
218 callback)); | 226 callback)); |
219 } | 227 } |
220 | 228 |
221 void DeviceInfo::GetClientNameContinuation( | 229 void DeviceInfo::GetClientNameContinuation( |
222 base::Callback<void(const std::string& local_info)> callback, | 230 base::Callback<void(const std::string& local_info)> callback, |
223 const std::string& session_name) { | 231 const std::string& session_name) { |
224 callback.Run(session_name); | 232 callback.Run(session_name); |
225 } | 233 } |
226 | 234 |
227 // static. | 235 // static. |
228 void DeviceInfo::CreateLocalDeviceInfoContinuation( | 236 void DeviceInfo::CreateLocalDeviceInfoContinuation( |
229 const std::string& guid, | 237 const std::string& guid, |
| 238 const std::string& signin_scoped_device_id, |
230 base::Callback<void(const DeviceInfo& local_info)> callback, | 239 base::Callback<void(const DeviceInfo& local_info)> callback, |
231 const std::string& session_name) { | 240 const std::string& session_name) { |
232 chrome::VersionInfo version_info; | 241 chrome::VersionInfo version_info; |
233 | 242 |
234 DeviceInfo local_info( | 243 DeviceInfo local_info(guid, |
235 guid, | 244 session_name, |
236 session_name, | 245 version_info.CreateVersionString(), |
237 version_info.CreateVersionString(), | 246 MakeUserAgentForSyncApi(version_info), |
238 MakeUserAgentForSyncApi(version_info), | 247 GetLocalDeviceType(), |
239 GetLocalDeviceType()); | 248 signin_scoped_device_id); |
240 | 249 |
241 callback.Run(local_info); | 250 callback.Run(local_info); |
242 } | 251 } |
243 | 252 |
244 } // namespace browser_sync | 253 } // namespace browser_sync |
OLD | NEW |