Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: components/sync/driver/device_info.cc

Issue 2250033002: [Sync] Create //components/sync/device_info. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix lint on device info files. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "components/sync/driver/device_info.h"
6
7 #include "base/values.h"
8
9 namespace sync_driver {
10
11 DeviceInfo::DeviceInfo(const std::string& guid,
12 const std::string& client_name,
13 const std::string& chrome_version,
14 const std::string& sync_user_agent,
15 const sync_pb::SyncEnums::DeviceType device_type,
16 const std::string& signin_scoped_device_id)
17 : guid_(guid),
18 client_name_(client_name),
19 chrome_version_(chrome_version),
20 sync_user_agent_(sync_user_agent),
21 device_type_(device_type),
22 signin_scoped_device_id_(signin_scoped_device_id) {}
23
24 DeviceInfo::~DeviceInfo() {}
25
26 const std::string& DeviceInfo::guid() const {
27 return guid_;
28 }
29
30 const std::string& DeviceInfo::client_name() const {
31 return client_name_;
32 }
33
34 const std::string& DeviceInfo::chrome_version() const {
35 return chrome_version_;
36 }
37
38 const std::string& DeviceInfo::sync_user_agent() const {
39 return sync_user_agent_;
40 }
41
42 const std::string& DeviceInfo::public_id() const {
43 return public_id_;
44 }
45
46 sync_pb::SyncEnums::DeviceType DeviceInfo::device_type() const {
47 return device_type_;
48 }
49
50 const std::string& DeviceInfo::signin_scoped_device_id() const {
51 return signin_scoped_device_id_;
52 }
53
54 std::string DeviceInfo::GetOSString() const {
55 switch (device_type_) {
56 case sync_pb::SyncEnums_DeviceType_TYPE_WIN:
57 return "win";
58 case sync_pb::SyncEnums_DeviceType_TYPE_MAC:
59 return "mac";
60 case sync_pb::SyncEnums_DeviceType_TYPE_LINUX:
61 return "linux";
62 case sync_pb::SyncEnums_DeviceType_TYPE_CROS:
63 return "chrome_os";
64 case sync_pb::SyncEnums_DeviceType_TYPE_PHONE:
65 case sync_pb::SyncEnums_DeviceType_TYPE_TABLET:
66 // TODO(lipalani): crbug.com/170375. Add support for ios
67 // phones and tablets.
68 return "android";
69 default:
70 return "unknown";
71 }
72 }
73
74 std::string DeviceInfo::GetDeviceTypeString() const {
75 switch (device_type_) {
76 case sync_pb::SyncEnums_DeviceType_TYPE_WIN:
77 case sync_pb::SyncEnums_DeviceType_TYPE_MAC:
78 case sync_pb::SyncEnums_DeviceType_TYPE_LINUX:
79 case sync_pb::SyncEnums_DeviceType_TYPE_CROS:
80 return "desktop_or_laptop";
81 case sync_pb::SyncEnums_DeviceType_TYPE_PHONE:
82 return "phone";
83 case sync_pb::SyncEnums_DeviceType_TYPE_TABLET:
84 return "tablet";
85 default:
86 return "unknown";
87 }
88 }
89
90 bool DeviceInfo::Equals(const DeviceInfo& other) const {
91 return this->guid() == other.guid() &&
92 this->client_name() == other.client_name() &&
93 this->chrome_version() == other.chrome_version() &&
94 this->sync_user_agent() == other.sync_user_agent() &&
95 this->device_type() == other.device_type() &&
96 this->signin_scoped_device_id() == other.signin_scoped_device_id();
97 }
98
99 base::DictionaryValue* DeviceInfo::ToValue() {
100 base::DictionaryValue* value = new base::DictionaryValue();
101 value->SetString("name", client_name_);
102 value->SetString("id", public_id_);
103 value->SetString("os", GetOSString());
104 value->SetString("type", GetDeviceTypeString());
105 value->SetString("chromeVersion", chrome_version_);
106 return value;
107 }
108
109 void DeviceInfo::set_public_id(const std::string& id) {
110 public_id_ = id;
111 }
112
113 } // namespace sync_driver
OLDNEW
« no previous file with comments | « components/sync/driver/device_info.h ('k') | components/sync/driver/device_info_data_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698