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/command_line.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "chrome/common/chrome_version_info.h" |
| 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "sync/util/get_session_name.h" |
| 13 |
| 14 namespace browser_sync { |
| 15 |
| 16 namespace { |
| 17 |
| 18 #if defined(OS_ANDROID) |
| 19 bool IsTabletUI() { |
| 20 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kTabletUI); |
| 21 } |
| 22 #endif |
| 23 |
| 24 } // namespace |
| 25 |
| 26 DeviceInfo::DeviceInfo() |
| 27 : client_name_("Unset"), |
| 28 sync_user_agent_("Unset"), |
| 29 device_type_(sync_pb::SyncEnums::TYPE_OTHER) { |
| 30 } |
| 31 |
| 32 DeviceInfo::DeviceInfo(const std::string& client_name, |
| 33 const std::string& chrome_version, |
| 34 const std::string& sync_user_agent, |
| 35 const sync_pb::SyncEnums::DeviceType device_type) |
| 36 : client_name_(client_name), |
| 37 chrome_version_(chrome_version), |
| 38 sync_user_agent_(sync_user_agent), |
| 39 device_type_(device_type) { |
| 40 } |
| 41 |
| 42 DeviceInfo::~DeviceInfo() { } |
| 43 |
| 44 const std::string& DeviceInfo::client_name() const { |
| 45 return client_name_; |
| 46 } |
| 47 |
| 48 const std::string& DeviceInfo::chrome_version() const { |
| 49 return chrome_version_; |
| 50 } |
| 51 |
| 52 const std::string& DeviceInfo::sync_user_agent() const { |
| 53 return sync_user_agent_; |
| 54 } |
| 55 |
| 56 sync_pb::SyncEnums::DeviceType DeviceInfo::device_type() const { |
| 57 return device_type_; |
| 58 } |
| 59 |
| 60 bool DeviceInfo::Equals(const DeviceInfo& other) const { |
| 61 return this->client_name() == other.client_name() |
| 62 && this->chrome_version() == other.chrome_version() |
| 63 && this->sync_user_agent() == other.sync_user_agent() |
| 64 && this->device_type() == other.device_type(); |
| 65 } |
| 66 |
| 67 // static. |
| 68 sync_pb::SyncEnums::DeviceType DeviceInfo::GetLocalDeviceType() { |
| 69 #if defined(OS_CHROMEOS) |
| 70 return sync_pb::SyncEnums_DeviceType_TYPE_CROS; |
| 71 #elif defined(OS_LINUX) |
| 72 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; |
| 73 #elif defined(OS_MACOSX) |
| 74 return sync_pb::SyncEnums_DeviceType_TYPE_MAC; |
| 75 #elif defined(OS_WIN) |
| 76 return sync_pb::SyncEnums_DeviceType_TYPE_WIN; |
| 77 #elif defined(OS_ANDROID) |
| 78 return IsTabletUI() ? |
| 79 sync_pb::SyncEnums_DeviceType_TYPE_TABLET : |
| 80 sync_pb::SyncEnums_DeviceType_TYPE_PHONE; |
| 81 #else |
| 82 return sync_pb::SyncEnums_DeviceType_TYPE_OTHER; |
| 83 #endif |
| 84 } |
| 85 |
| 86 // static |
| 87 std::string DeviceInfo::MakeUserAgentForSyncApi( |
| 88 const chrome::VersionInfo& version_info) { |
| 89 std::string user_agent; |
| 90 user_agent = "Chrome "; |
| 91 #if defined(OS_WIN) |
| 92 user_agent += "WIN "; |
| 93 #elif defined(OS_CHROMEOS) |
| 94 user_agent += "CROS "; |
| 95 #elif defined(OS_ANDROID) |
| 96 user_agent += "ANDROID "; |
| 97 #elif defined(OS_LINUX) |
| 98 user_agent += "LINUX "; |
| 99 #elif defined(OS_FREEBSD) |
| 100 user_agent += "FREEBSD "; |
| 101 #elif defined(OS_OPENBSD) |
| 102 user_agent += "OPENBSD "; |
| 103 #elif defined(OS_MACOSX) |
| 104 user_agent += "MAC "; |
| 105 #endif |
| 106 if (!version_info.is_valid()) { |
| 107 DLOG(ERROR) << "Unable to create chrome::VersionInfo object"; |
| 108 return user_agent; |
| 109 } |
| 110 |
| 111 user_agent += version_info.Version(); |
| 112 user_agent += " (" + version_info.LastChange() + ")"; |
| 113 if (!version_info.IsOfficialBuild()) |
| 114 user_agent += "-devel"; |
| 115 return user_agent; |
| 116 } |
| 117 |
| 118 // static. |
| 119 void DeviceInfo::CreateLocalDeviceInfo( |
| 120 base::Callback<void(const DeviceInfo& local_info)> callback) { |
| 121 syncer::GetSessionName( |
| 122 content::BrowserThread::GetBlockingPool(), |
| 123 base::Bind(&DeviceInfo::CreateLocalDeviceInfoContinuation, callback)); |
| 124 } |
| 125 |
| 126 // static. |
| 127 void DeviceInfo::CreateLocalDeviceInfoContinuation( |
| 128 base::Callback<void(const DeviceInfo& local_info)> callback, |
| 129 const std::string& session_name) { |
| 130 chrome::VersionInfo version_info; |
| 131 |
| 132 DeviceInfo local_info( |
| 133 session_name, |
| 134 version_info.CreateVersionString(), |
| 135 MakeUserAgentForSyncApi(version_info), |
| 136 GetLocalDeviceType()); |
| 137 |
| 138 callback.Run(local_info); |
| 139 } |
| 140 |
| 141 } // namespace browser_sync |
OLD | NEW |