Chromium Code Reviews| 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"), | |
|
Nicolas Zea
2012/10/01 21:24:30
any reason these are different? (unset vs unknown)
rlarocque
2012/10/01 22:24:12
I seem to remember that this is the way it was bef
Nicolas Zea
2012/10/05 20:28:51
I'd prefer the same value. Either one works though
rlarocque
2012/10/05 21:05:00
Done.
| |
| 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) { | |
|
Nicolas Zea
2012/10/01 21:24:30
VersionInfo& version_info
rlarocque
2012/10/01 22:24:12
Done.
| |
| 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_LINUX) | |
| 84 user_agent += "LINUX "; | |
| 85 #elif defined(OS_FREEBSD) | |
| 86 user_agent += "FREEBSD "; | |
| 87 #elif defined(OS_OPENBSD) | |
| 88 user_agent += "OPENBSD "; | |
| 89 #elif defined(OS_MACOSX) | |
| 90 user_agent += "MAC "; | |
|
Nicolas Zea
2012/10/01 21:24:30
you're missing android
rlarocque
2012/10/01 22:24:12
!!!
I specifically looked for this when I updated
| |
| 91 #endif | |
| 92 if (!version_info.is_valid()) { | |
| 93 DLOG(ERROR) << "Unable to create chrome::VersionInfo object"; | |
| 94 return user_agent; | |
| 95 } | |
| 96 | |
| 97 user_agent += version_info.Version(); | |
| 98 user_agent += " (" + version_info.LastChange() + ")"; | |
| 99 if (!version_info.IsOfficialBuild()) | |
| 100 user_agent += "-devel"; | |
| 101 return user_agent; | |
| 102 } | |
| 103 | |
| 104 // static. | |
| 105 void DeviceInfo::CreateLocalDeviceInfo( | |
| 106 base::Callback<void(const DeviceInfo& local_info)> callback) { | |
| 107 syncer::GetSessionName( | |
| 108 content::BrowserThread::GetBlockingPool(), | |
| 109 base::Bind(&DeviceInfo::CreateLocalDeviceInfoContinuation, callback)); | |
| 110 } | |
| 111 | |
| 112 // static. | |
| 113 void DeviceInfo::CreateLocalDeviceInfoContinuation( | |
| 114 base::Callback<void(const DeviceInfo& local_info)> callback, | |
| 115 const std::string& session_name) { | |
| 116 chrome::VersionInfo version_info; | |
| 117 | |
| 118 DeviceInfo local_info( | |
| 119 session_name, | |
| 120 version_info.CreateVersionString(), | |
| 121 MakeUserAgentForSyncApi(version_info), | |
| 122 GetLocalDeviceType()); | |
| 123 | |
| 124 callback.Run(local_info); | |
| 125 } | |
| 126 | |
| 127 } // namespace browser_sync | |
| OLD | NEW |