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