Ensure that TileTaskRunner calls callbacks on empty schedule
[chromium-blink-merge.git] / components / sync_driver / device_info.cc
blobc80a1571c964640a6c00ea74fe10939a90f6275c
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.
5 #include "base/values.h"
6 #include "components/sync_driver/device_info.h"
8 namespace sync_driver {
10 DeviceInfo::DeviceInfo(const std::string& guid,
11 const std::string& client_name,
12 const std::string& chrome_version,
13 const std::string& sync_user_agent,
14 const sync_pb::SyncEnums::DeviceType device_type,
15 const std::string& signin_scoped_device_id)
16 : guid_(guid),
17 client_name_(client_name),
18 chrome_version_(chrome_version),
19 sync_user_agent_(sync_user_agent),
20 device_type_(device_type),
21 signin_scoped_device_id_(signin_scoped_device_id) {
24 DeviceInfo::~DeviceInfo() { }
26 const std::string& DeviceInfo::guid() const {
27 return guid_;
30 const std::string& DeviceInfo::client_name() const {
31 return client_name_;
34 const std::string& DeviceInfo::chrome_version() const {
35 return chrome_version_;
38 const std::string& DeviceInfo::sync_user_agent() const {
39 return sync_user_agent_;
42 const std::string& DeviceInfo::public_id() const {
43 return public_id_;
46 sync_pb::SyncEnums::DeviceType DeviceInfo::device_type() const {
47 return device_type_;
50 const std::string& DeviceInfo::signin_scoped_device_id() const {
51 return signin_scoped_device_id_;
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";
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";
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();
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;
109 void DeviceInfo::set_public_id(std::string id) {
110 public_id_ = id;
113 } // namespace sync_driver