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

Unified 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: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/glue/device_info.cc
diff --git a/chrome/browser/sync/glue/device_info.cc b/chrome/browser/sync/glue/device_info.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0eaaf0a81249bd22151356491098bc66f05e49a1
--- /dev/null
+++ b/chrome/browser/sync/glue/device_info.cc
@@ -0,0 +1,120 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/glue/device_info.h"
+
+#include "base/threading/sequenced_worker_pool.h"
+#include "chrome/common/chrome_version_info.h"
+#include "content/public/browser/browser_thread.h"
+#include "sync/util/get_session_name.h"
+
+namespace browser_sync {
+
+DeviceInfo::DeviceInfo()
+ : client_name_("Unset"),
+ sync_user_agent_("Unknown"),
+ device_type_(sync_pb::SyncEnums::TYPE_OTHER) {
+}
+
+DeviceInfo::DeviceInfo(const std::string& client_name,
+ const std::string& sync_user_agent,
+ const sync_pb::SyncEnums::DeviceType device_type)
+ : client_name_(client_name),
+ sync_user_agent_(sync_user_agent),
+ device_type_(device_type) {
+}
+
+DeviceInfo::~DeviceInfo() { }
+
+const std::string& DeviceInfo::client_name() const {
+ return client_name_;
+}
+
+const std::string& DeviceInfo::sync_user_agent() const {
+ return sync_user_agent_;
+}
+
+sync_pb::SyncEnums::DeviceType DeviceInfo::device_type() const {
+ return device_type_;
+}
+
+bool DeviceInfo::Equals(const DeviceInfo& other) const {
+ return this->client_name() == other.client_name()
+ && this->sync_user_agent() == other.sync_user_agent()
+ && this->device_type() == other.device_type();
+}
+
+// static.
+sync_pb::SyncEnums::DeviceType DeviceInfo::GetLocalDeviceType() {
+#if defined(OS_CHROMEOS)
+ return sync_pb::SyncEnums_DeviceType_TYPE_CROS;
+#elif defined(OS_LINUX)
+ return sync_pb::SyncEnums_DeviceType_TYPE_LINUX;
+#elif defined(OS_MACOSX)
+ return sync_pb::SyncEnums_DeviceType_TYPE_MAC;
+#elif defined(OS_WIN)
+ return sync_pb::SyncEnums_DeviceType_TYPE_WIN;
+#elif defined(OS_ANDROID)
+ return IsTabletUI() ?
+ sync_pb::SessionHeader_DeviceType_TYPE_TABLET :
+ sync_pb::SessionHeader_DeviceType_TYPE_PHONE;
+#else
+ return sync_pb::SessionHeader_DeviceType_TYPE_OTHER;
+#endif
+}
+
+// static
+std::string DeviceInfo::MakeUserAgentForSyncApi() {
+ std::string user_agent;
+ user_agent = "Chrome ";
+#if defined(OS_WIN)
+ user_agent += "WIN ";
+#elif defined(OS_CHROMEOS)
+ user_agent += "CROS ";
+#elif defined(OS_LINUX)
Nicolas Zea 2012/09/26 01:50:59 FYI, Android now has a field here (change just lan
rlarocque 2012/09/26 20:44:36 Thanks. I'll be sure to rebase before commit.
+ user_agent += "LINUX ";
+#elif defined(OS_FREEBSD)
+ user_agent += "FREEBSD ";
+#elif defined(OS_OPENBSD)
+ user_agent += "OPENBSD ";
+#elif defined(OS_MACOSX)
+ user_agent += "MAC ";
+#endif
+ chrome::VersionInfo version_info;
+ if (!version_info.is_valid()) {
+ DLOG(ERROR) << "Unable to create chrome::VersionInfo object";
+ return user_agent;
+ }
+
+ user_agent += version_info.Version();
+ user_agent += " (" + version_info.LastChange() + ")";
+ if (!version_info.IsOfficialBuild())
+ user_agent += "-devel";
+ return user_agent;
+}
+
+// static.
+void DeviceInfo::CreateLocalDeviceInfo(
+ base::Callback<void(const DeviceInfo& local_info)> callback) {
+ const scoped_refptr<base::TaskRunner> blocking_task_runner(
+ content::BrowserThread::GetBlockingPool());
+ syncer::GetSessionName(
Nicolas Zea 2012/09/26 01:50:59 GetSessionName( content::BrowserThread::GetBlock
rlarocque 2012/09/26 20:44:36 Done.
+ blocking_task_runner.get(),
+ base::Bind(&DeviceInfo::CreateLocalDeviceInfoContinuation, callback));
+}
+
+// static.
+void DeviceInfo::CreateLocalDeviceInfoContinuation(
+ base::Callback<void(const DeviceInfo& local_info)> callback,
+ const std::string& session_name) {
+
+ DeviceInfo local_info(
+ session_name,
+ MakeUserAgentForSyncApi(),
+ GetLocalDeviceType());
+
+ callback.Run(local_info);
+}
+
+} // namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698