OLD | NEW |
| (Empty) |
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 #include "base/values.h" | |
6 #include "chrome/browser/sync/glue/device_info.h" | |
7 #include "content/public/browser/browser_thread.h" | |
8 #include "sync/util/get_session_name.h" | |
9 | |
10 namespace browser_sync { | |
11 | |
12 DeviceInfo::DeviceInfo(const std::string& guid, | |
13 const std::string& client_name, | |
14 const std::string& chrome_version, | |
15 const std::string& sync_user_agent, | |
16 const sync_pb::SyncEnums::DeviceType device_type, | |
17 const std::string& signin_scoped_device_id) | |
18 : guid_(guid), | |
19 client_name_(client_name), | |
20 chrome_version_(chrome_version), | |
21 sync_user_agent_(sync_user_agent), | |
22 device_type_(device_type), | |
23 signin_scoped_device_id_(signin_scoped_device_id) { | |
24 } | |
25 | |
26 DeviceInfo::~DeviceInfo() { } | |
27 | |
28 const std::string& DeviceInfo::guid() const { | |
29 return guid_; | |
30 } | |
31 | |
32 const std::string& DeviceInfo::client_name() const { | |
33 return client_name_; | |
34 } | |
35 | |
36 const std::string& DeviceInfo::chrome_version() const { | |
37 return chrome_version_; | |
38 } | |
39 | |
40 const std::string& DeviceInfo::sync_user_agent() const { | |
41 return sync_user_agent_; | |
42 } | |
43 | |
44 const std::string& DeviceInfo::public_id() const { | |
45 return public_id_; | |
46 } | |
47 | |
48 sync_pb::SyncEnums::DeviceType DeviceInfo::device_type() const { | |
49 return device_type_; | |
50 } | |
51 | |
52 const std::string& DeviceInfo::signin_scoped_device_id() const { | |
53 return signin_scoped_device_id_; | |
54 } | |
55 | |
56 std::string DeviceInfo::GetOSString() const { | |
57 switch (device_type_) { | |
58 case sync_pb::SyncEnums_DeviceType_TYPE_WIN: | |
59 return "win"; | |
60 case sync_pb::SyncEnums_DeviceType_TYPE_MAC: | |
61 return "mac"; | |
62 case sync_pb::SyncEnums_DeviceType_TYPE_LINUX: | |
63 return "linux"; | |
64 case sync_pb::SyncEnums_DeviceType_TYPE_CROS: | |
65 return "chrome_os"; | |
66 case sync_pb::SyncEnums_DeviceType_TYPE_PHONE: | |
67 case sync_pb::SyncEnums_DeviceType_TYPE_TABLET: | |
68 // TODO(lipalani): crbug.com/170375. Add support for ios | |
69 // phones and tablets. | |
70 return "android"; | |
71 default: | |
72 return "unknown"; | |
73 } | |
74 } | |
75 | |
76 std::string DeviceInfo::GetDeviceTypeString() const { | |
77 switch (device_type_) { | |
78 case sync_pb::SyncEnums_DeviceType_TYPE_WIN: | |
79 case sync_pb::SyncEnums_DeviceType_TYPE_MAC: | |
80 case sync_pb::SyncEnums_DeviceType_TYPE_LINUX: | |
81 case sync_pb::SyncEnums_DeviceType_TYPE_CROS: | |
82 return "desktop_or_laptop"; | |
83 case sync_pb::SyncEnums_DeviceType_TYPE_PHONE: | |
84 return "phone"; | |
85 case sync_pb::SyncEnums_DeviceType_TYPE_TABLET: | |
86 return "tablet"; | |
87 default: | |
88 return "unknown"; | |
89 } | |
90 } | |
91 | |
92 bool DeviceInfo::Equals(const DeviceInfo& other) const { | |
93 return this->guid() == other.guid() && | |
94 this->client_name() == other.client_name() && | |
95 this->chrome_version() == other.chrome_version() && | |
96 this->sync_user_agent() == other.sync_user_agent() && | |
97 this->device_type() == other.device_type() && | |
98 this->signin_scoped_device_id() == other.signin_scoped_device_id(); | |
99 } | |
100 | |
101 base::DictionaryValue* DeviceInfo::ToValue() { | |
102 base::DictionaryValue* value = new base::DictionaryValue(); | |
103 value->SetString("name", client_name_); | |
104 value->SetString("id", public_id_); | |
105 value->SetString("os", GetOSString()); | |
106 value->SetString("type", GetDeviceTypeString()); | |
107 value->SetString("chromeVersion", chrome_version_); | |
108 return value; | |
109 } | |
110 | |
111 void DeviceInfo::set_public_id(std::string id) { | |
112 public_id_ = id; | |
113 } | |
114 | |
115 // static. | |
116 void DeviceInfo::GetClientName(const GetClientNameCallback& callback) { | |
117 syncer::GetSessionName(content::BrowserThread::GetBlockingPool(), callback); | |
118 } | |
119 | |
120 } // namespace browser_sync | |
OLD | NEW |