Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/sync_driver/local_device_info_provider_impl.h" | |
| 6 | |
| 5 #include "base/bind.h" | 7 #include "base/bind.h" |
| 6 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h" | 8 #include "base/task_runner.h" |
| 7 #include "chrome/common/channel_info.h" | |
| 8 #include "components/sync_driver/sync_util.h" | 9 #include "components/sync_driver/sync_util.h" |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "sync/util/get_session_name.h" | 10 #include "sync/util/get_session_name.h" |
| 11 #include "ui/base/device_form_factor.h" | |
| 12 | 11 |
| 13 namespace browser_sync { | 12 namespace browser_sync { |
| 14 | 13 |
| 15 namespace { | 14 namespace { |
| 16 | 15 |
| 17 #if defined(OS_ANDROID) | |
| 18 bool IsTabletUI() { | |
| 19 return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET; | |
| 20 } | |
| 21 #endif | |
| 22 | |
| 23 sync_pb::SyncEnums::DeviceType GetLocalDeviceType() { | 16 sync_pb::SyncEnums::DeviceType GetLocalDeviceType() { |
| 24 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
| 25 return sync_pb::SyncEnums_DeviceType_TYPE_CROS; | 18 return sync_pb::SyncEnums_DeviceType_TYPE_CROS; |
| 26 #elif defined(OS_LINUX) | 19 #elif defined(OS_LINUX) |
| 27 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; | 20 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; |
| 28 #elif defined(OS_MACOSX) | 21 #elif defined(OS_MACOSX) |
| 29 return sync_pb::SyncEnums_DeviceType_TYPE_MAC; | 22 return sync_pb::SyncEnums_DeviceType_TYPE_MAC; |
| 30 #elif defined(OS_WIN) | 23 #elif defined(OS_WIN) |
| 31 return sync_pb::SyncEnums_DeviceType_TYPE_WIN; | 24 return sync_pb::SyncEnums_DeviceType_TYPE_WIN; |
| 32 #elif defined(OS_ANDROID) | 25 #elif defined(OS_ANDROID) |
| 33 return IsTabletUI() ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET | 26 return IsTabletUI() ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET |
|
stanisc
2015/10/27 22:32:43
Missed this during review: IsTabletUI() should be
| |
| 34 : sync_pb::SyncEnums_DeviceType_TYPE_PHONE; | 27 : sync_pb::SyncEnums_DeviceType_TYPE_PHONE; |
| 35 #else | 28 #else |
| 36 return sync_pb::SyncEnums_DeviceType_TYPE_OTHER; | 29 return sync_pb::SyncEnums_DeviceType_TYPE_OTHER; |
| 37 #endif | 30 #endif |
| 38 } | 31 } |
| 39 | 32 |
| 40 } // namespace | 33 } // namespace |
| 41 | 34 |
| 42 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl() | 35 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl( |
| 43 : weak_factory_(this) { | 36 version_info::Channel channel, |
| 44 } | 37 const std::string& version, |
| 38 bool is_tablet) | |
| 39 : channel_(channel), | |
| 40 version_(version), | |
| 41 is_tablet_(is_tablet), | |
| 42 weak_factory_(this) {} | |
| 45 | 43 |
| 46 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() { | 44 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {} |
| 47 } | |
| 48 | 45 |
| 49 const sync_driver::DeviceInfo* | 46 const sync_driver::DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() |
| 50 LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const { | 47 const { |
| 51 return local_device_info_.get(); | 48 return local_device_info_.get(); |
| 52 } | 49 } |
| 53 | 50 |
| 54 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const { | 51 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const { |
| 55 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 52 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 56 return MakeDesktopUserAgentForSync(chrome::GetChannel()); | 53 return MakeDesktopUserAgentForSync(channel_); |
| 57 #elif defined(OS_CHROMEOS) | 54 #elif defined(OS_CHROMEOS) |
| 58 return MakeUserAgentForSync("CROS ", chrome::GetChannel()); | 55 return MakeUserAgentForSync("CROS ", channel_); |
| 59 #elif defined(OS_ANDROID) | 56 #elif defined(OS_ANDROID) |
| 60 if (IsTabletUI()) { | 57 if (is_tablet_) { |
| 61 return MakeUserAgentForSync("ANDROID-TABLET ", chrome::GetChannel()); | 58 return MakeUserAgentForSync("ANDROID-TABLET ", channel_); |
| 62 } else { | 59 } else { |
| 63 return MakeUserAgentForSync("ANDROID-PHONE ", chrome::GetChannel()); | 60 return MakeUserAgentForSync("ANDROID-PHONE ", channel_); |
| 64 } | 61 } |
| 65 #endif | 62 #endif |
| 66 } | 63 } |
| 67 | 64 |
| 68 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { | 65 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { |
| 69 return cache_guid_; | 66 return cache_guid_; |
| 70 } | 67 } |
| 71 | 68 |
| 72 scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> | 69 scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> |
| 73 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( | 70 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( |
| 74 const base::Closure& callback) { | 71 const base::Closure& callback) { |
| 75 DCHECK(!local_device_info_.get()); | 72 DCHECK(!local_device_info_.get()); |
| 76 return callback_list_.Add(callback); | 73 return callback_list_.Add(callback); |
| 77 } | 74 } |
| 78 | 75 |
| 79 void LocalDeviceInfoProviderImpl::Initialize( | 76 void LocalDeviceInfoProviderImpl::Initialize( |
| 80 const std::string& cache_guid, const std::string& signin_scoped_device_id) { | 77 const std::string& cache_guid, |
| 78 const std::string& signin_scoped_device_id, | |
| 79 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { | |
| 81 DCHECK(!cache_guid.empty()); | 80 DCHECK(!cache_guid.empty()); |
| 82 cache_guid_ = cache_guid; | 81 cache_guid_ = cache_guid; |
| 83 | 82 |
| 84 syncer::GetSessionName( | 83 syncer::GetSessionName( |
| 85 content::BrowserThread::GetBlockingPool(), | 84 blocking_task_runner, |
| 86 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, | 85 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, |
| 87 weak_factory_.GetWeakPtr(), | 86 weak_factory_.GetWeakPtr(), cache_guid, |
| 88 cache_guid, | |
| 89 signin_scoped_device_id)); | 87 signin_scoped_device_id)); |
| 90 } | 88 } |
| 91 | 89 |
| 92 void LocalDeviceInfoProviderImpl::InitializeContinuation( | 90 void LocalDeviceInfoProviderImpl::InitializeContinuation( |
| 93 const std::string& guid, | 91 const std::string& guid, |
| 94 const std::string& signin_scoped_device_id, | 92 const std::string& signin_scoped_device_id, |
| 95 const std::string& session_name) { | 93 const std::string& session_name) { |
| 96 local_device_info_.reset( | 94 local_device_info_.reset(new sync_driver::DeviceInfo( |
| 97 new sync_driver::DeviceInfo(guid, | 95 guid, session_name, version_, GetSyncUserAgent(), GetLocalDeviceType(), |
| 98 session_name, | 96 signin_scoped_device_id)); |
| 99 chrome::GetVersionString(), | |
| 100 GetSyncUserAgent(), | |
| 101 GetLocalDeviceType(), | |
| 102 signin_scoped_device_id)); | |
| 103 | 97 |
| 104 // Notify observers. | 98 // Notify observers. |
| 105 callback_list_.Notify(); | 99 callback_list_.Notify(); |
| 106 } | 100 } |
| 107 | 101 |
| 108 } // namespace browser_sync | 102 } // namespace browser_sync |
| OLD | NEW |