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

Side by Side Diff: chrome/browser/sync/glue/device_info.cc

Issue 10985008: sync: Add DeviceInfo protobuf and supporting code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Some review fixes Created 8 years, 2 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 | Annotate | Revision Log
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 "chrome/browser/sync/glue/device_info.h"
6
7 #include "base/threading/sequenced_worker_pool.h"
8 #include "chrome/common/chrome_version_info.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "sync/util/get_session_name.h"
11
12 namespace browser_sync {
13
14 DeviceInfo::DeviceInfo()
15 : client_name_("Unset"),
16 sync_user_agent_("Unknown"),
17 device_type_(sync_pb::SyncEnums::TYPE_OTHER) {
18 }
19
20 DeviceInfo::DeviceInfo(const std::string& client_name,
21 const std::string& chrome_version,
22 const std::string& sync_user_agent,
23 const sync_pb::SyncEnums::DeviceType device_type)
24 : client_name_(client_name),
25 chrome_version_(chrome_version),
26 sync_user_agent_(sync_user_agent),
27 device_type_(device_type) {
28 }
29
30 DeviceInfo::~DeviceInfo() { }
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 sync_pb::SyncEnums::DeviceType DeviceInfo::device_type() const {
45 return device_type_;
46 }
47
48 bool DeviceInfo::Equals(const DeviceInfo& other) const {
49 return this->client_name() == other.client_name()
50 && this->chrome_version() == other.chrome_version()
51 && this->sync_user_agent() == other.sync_user_agent()
52 && this->device_type() == other.device_type();
53 }
54
55 // static.
56 sync_pb::SyncEnums::DeviceType DeviceInfo::GetLocalDeviceType() {
57 #if defined(OS_CHROMEOS)
58 return sync_pb::SyncEnums_DeviceType_TYPE_CROS;
59 #elif defined(OS_LINUX)
60 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX;
61 #elif defined(OS_MACOSX)
62 return sync_pb::SyncEnums_DeviceType_TYPE_MAC;
63 #elif defined(OS_WIN)
64 return sync_pb::SyncEnums_DeviceType_TYPE_WIN;
65 #elif defined(OS_ANDROID)
66 return IsTabletUI() ?
67 sync_pb::SessionHeader_DeviceType_TYPE_TABLET :
68 sync_pb::SessionHeader_DeviceType_TYPE_PHONE;
69 #else
70 return sync_pb::SessionHeader_DeviceType_TYPE_OTHER;
71 #endif
72 }
73
74 // static
75 std::string DeviceInfo::MakeUserAgentForSyncApi(
76 const chrome::VersionInfo& version_info) {
77 std::string user_agent;
78 user_agent = "Chrome ";
79 #if defined(OS_WIN)
80 user_agent += "WIN ";
81 #elif defined(OS_CHROMEOS)
82 user_agent += "CROS ";
83 #elif defined(OS_ANDROID)
84 user_agent += "ANDROID ";
85 #elif defined(OS_LINUX)
86 user_agent += "LINUX ";
87 #elif defined(OS_FREEBSD)
88 user_agent += "FREEBSD ";
89 #elif defined(OS_OPENBSD)
90 user_agent += "OPENBSD ";
91 #elif defined(OS_MACOSX)
92 user_agent += "MAC ";
93 #endif
94 if (!version_info.is_valid()) {
95 DLOG(ERROR) << "Unable to create chrome::VersionInfo object";
96 return user_agent;
97 }
98
99 user_agent += version_info.Version();
100 user_agent += " (" + version_info.LastChange() + ")";
101 if (!version_info.IsOfficialBuild())
102 user_agent += "-devel";
103 return user_agent;
104 }
105
106 // static.
107 void DeviceInfo::CreateLocalDeviceInfo(
108 base::Callback<void(const DeviceInfo& local_info)> callback) {
109 syncer::GetSessionName(
110 content::BrowserThread::GetBlockingPool(),
111 base::Bind(&DeviceInfo::CreateLocalDeviceInfoContinuation, callback));
112 }
113
114 // static.
115 void DeviceInfo::CreateLocalDeviceInfoContinuation(
116 base::Callback<void(const DeviceInfo& local_info)> callback,
117 const std::string& session_name) {
118 chrome::VersionInfo version_info;
119
120 DeviceInfo local_info(
121 session_name,
122 version_info.CreateVersionString(),
123 MakeUserAgentForSyncApi(version_info),
124 GetLocalDeviceType());
125
126 callback.Run(local_info);
127 }
128
129 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698