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 "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& sync_user_agent, |
| 22 const sync_pb::SyncEnums::DeviceType device_type) |
| 23 : client_name_(client_name), |
| 24 sync_user_agent_(sync_user_agent), |
| 25 device_type_(device_type) { |
| 26 } |
| 27 |
| 28 DeviceInfo::~DeviceInfo() { } |
| 29 |
| 30 const std::string& DeviceInfo::client_name() const { |
| 31 return client_name_; |
| 32 } |
| 33 |
| 34 const std::string& DeviceInfo::sync_user_agent() const { |
| 35 return sync_user_agent_; |
| 36 } |
| 37 |
| 38 sync_pb::SyncEnums::DeviceType DeviceInfo::device_type() const { |
| 39 return device_type_; |
| 40 } |
| 41 |
| 42 bool DeviceInfo::Equals(const DeviceInfo& other) const { |
| 43 return this->client_name() == other.client_name() |
| 44 && this->sync_user_agent() == other.sync_user_agent() |
| 45 && this->device_type() == other.device_type(); |
| 46 } |
| 47 |
| 48 // static. |
| 49 sync_pb::SyncEnums::DeviceType DeviceInfo::GetLocalDeviceType() { |
| 50 #if defined(OS_CHROMEOS) |
| 51 return sync_pb::SyncEnums_DeviceType_TYPE_CROS; |
| 52 #elif defined(OS_LINUX) |
| 53 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; |
| 54 #elif defined(OS_MACOSX) |
| 55 return sync_pb::SyncEnums_DeviceType_TYPE_MAC; |
| 56 #elif defined(OS_WIN) |
| 57 return sync_pb::SyncEnums_DeviceType_TYPE_WIN; |
| 58 #elif defined(OS_ANDROID) |
| 59 return IsTabletUI() ? |
| 60 sync_pb::SessionHeader_DeviceType_TYPE_TABLET : |
| 61 sync_pb::SessionHeader_DeviceType_TYPE_PHONE; |
| 62 #else |
| 63 return sync_pb::SessionHeader_DeviceType_TYPE_OTHER; |
| 64 #endif |
| 65 } |
| 66 |
| 67 // static |
| 68 std::string DeviceInfo::MakeUserAgentForSyncApi() { |
| 69 std::string user_agent; |
| 70 user_agent = "Chrome "; |
| 71 #if defined(OS_WIN) |
| 72 user_agent += "WIN "; |
| 73 #elif defined(OS_CHROMEOS) |
| 74 user_agent += "CROS "; |
| 75 #elif defined(OS_LINUX) |
| 76 user_agent += "LINUX "; |
| 77 #elif defined(OS_FREEBSD) |
| 78 user_agent += "FREEBSD "; |
| 79 #elif defined(OS_OPENBSD) |
| 80 user_agent += "OPENBSD "; |
| 81 #elif defined(OS_MACOSX) |
| 82 user_agent += "MAC "; |
| 83 #endif |
| 84 chrome::VersionInfo version_info; |
| 85 if (!version_info.is_valid()) { |
| 86 DLOG(ERROR) << "Unable to create chrome::VersionInfo object"; |
| 87 return user_agent; |
| 88 } |
| 89 |
| 90 user_agent += version_info.Version(); |
| 91 user_agent += " (" + version_info.LastChange() + ")"; |
| 92 if (!version_info.IsOfficialBuild()) |
| 93 user_agent += "-devel"; |
| 94 return user_agent; |
| 95 } |
| 96 |
| 97 // static. |
| 98 void DeviceInfo::CreateLocalDeviceInfo( |
| 99 base::Callback<void(const DeviceInfo& local_info)> callback) { |
| 100 const scoped_refptr<base::TaskRunner> blocking_task_runner( |
| 101 content::BrowserThread::GetBlockingPool()); |
| 102 syncer::GetSessionName( |
| 103 blocking_task_runner.get(), |
| 104 base::Bind(&DeviceInfo::CreateLocalDeviceInfoContinuation, callback)); |
| 105 } |
| 106 |
| 107 // static. |
| 108 void DeviceInfo::CreateLocalDeviceInfoContinuation( |
| 109 base::Callback<void(const DeviceInfo& local_info)> callback, |
| 110 const std::string& session_name) { |
| 111 |
| 112 DeviceInfo local_info( |
| 113 session_name, |
| 114 MakeUserAgentForSyncApi(), |
| 115 GetLocalDeviceType()); |
| 116 |
| 117 callback.Run(local_info); |
| 118 } |
| 119 |
| 120 } // namespace browser_sync |
OLD | NEW |