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" | 11 #include "ui/base/device_form_factor.h" |
| 12 | 12 |
| 13 namespace browser_sync { | 13 namespace browser_sync { |
|
stanisc
2015/10/09 17:18:02
Should the namespace be changed to sync_driver?
| |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 #if defined(OS_ANDROID) | 17 #if defined(OS_ANDROID) |
| 18 bool IsTabletUI() { | 18 bool IsTabletUI() { |
| 19 return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET; | 19 return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET; |
| 20 } | 20 } |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 sync_pb::SyncEnums::DeviceType GetLocalDeviceType() { | 23 sync_pb::SyncEnums::DeviceType GetLocalDeviceType() { |
| 24 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 25 return sync_pb::SyncEnums_DeviceType_TYPE_CROS; | 25 return sync_pb::SyncEnums_DeviceType_TYPE_CROS; |
| 26 #elif defined(OS_LINUX) | 26 #elif defined(OS_LINUX) |
| 27 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; | 27 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; |
| 28 #elif defined(OS_MACOSX) | 28 #elif defined(OS_MACOSX) |
| 29 return sync_pb::SyncEnums_DeviceType_TYPE_MAC; | 29 return sync_pb::SyncEnums_DeviceType_TYPE_MAC; |
| 30 #elif defined(OS_WIN) | 30 #elif defined(OS_WIN) |
| 31 return sync_pb::SyncEnums_DeviceType_TYPE_WIN; | 31 return sync_pb::SyncEnums_DeviceType_TYPE_WIN; |
| 32 #elif defined(OS_ANDROID) | 32 #elif defined(OS_ANDROID) |
| 33 return IsTabletUI() ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET | 33 return IsTabletUI() ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET |
| 34 : sync_pb::SyncEnums_DeviceType_TYPE_PHONE; | 34 : sync_pb::SyncEnums_DeviceType_TYPE_PHONE; |
| 35 #else | 35 #else |
| 36 return sync_pb::SyncEnums_DeviceType_TYPE_OTHER; | 36 return sync_pb::SyncEnums_DeviceType_TYPE_OTHER; |
| 37 #endif | 37 #endif |
| 38 } | 38 } |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl() | 42 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl( |
| 43 : weak_factory_(this) { | 43 version_info::Channel channel, |
| 44 } | 44 const std::string& version) |
| 45 : channel_(channel), version_(version), weak_factory_(this) {} | |
| 45 | 46 |
| 46 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() { | 47 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {} |
| 47 } | |
| 48 | 48 |
| 49 const sync_driver::DeviceInfo* | 49 const sync_driver::DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() |
| 50 LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const { | 50 const { |
| 51 return local_device_info_.get(); | 51 return local_device_info_.get(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const { | 54 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const { |
| 55 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 55 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 56 return MakeDesktopUserAgentForSync(chrome::GetChannel()); | 56 return MakeDesktopUserAgentForSync(channel_); |
| 57 #elif defined(OS_CHROMEOS) | 57 #elif defined(OS_CHROMEOS) |
| 58 return MakeUserAgentForSync("CROS ", chrome::GetChannel()); | 58 return MakeUserAgentForSync("CROS ", channel_); |
| 59 #elif defined(OS_ANDROID) | 59 #elif defined(OS_ANDROID) |
| 60 if (IsTabletUI()) { | 60 if (IsTabletUI()) { |
| 61 return MakeUserAgentForSync("ANDROID-TABLET ", chrome::GetChannel()); | 61 return MakeUserAgentForSync("ANDROID-TABLET ", channel_); |
| 62 } else { | 62 } else { |
| 63 return MakeUserAgentForSync("ANDROID-PHONE ", chrome::GetChannel()); | 63 return MakeUserAgentForSync("ANDROID-PHONE ", channel_); |
| 64 } | 64 } |
| 65 #endif | 65 #endif |
| 66 } | 66 } |
| 67 | 67 |
| 68 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { | 68 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { |
| 69 return cache_guid_; | 69 return cache_guid_; |
| 70 } | 70 } |
| 71 | 71 |
| 72 scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> | 72 scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> |
| 73 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( | 73 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( |
| 74 const base::Closure& callback) { | 74 const base::Closure& callback) { |
| 75 DCHECK(!local_device_info_.get()); | 75 DCHECK(!local_device_info_.get()); |
| 76 return callback_list_.Add(callback); | 76 return callback_list_.Add(callback); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void LocalDeviceInfoProviderImpl::Initialize( | 79 void LocalDeviceInfoProviderImpl::Initialize( |
| 80 const std::string& cache_guid, const std::string& signin_scoped_device_id) { | 80 const std::string& cache_guid, |
| 81 const std::string& signin_scoped_device_id, | |
| 82 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { | |
| 81 DCHECK(!cache_guid.empty()); | 83 DCHECK(!cache_guid.empty()); |
| 82 cache_guid_ = cache_guid; | 84 cache_guid_ = cache_guid; |
| 83 | 85 |
| 84 syncer::GetSessionName( | 86 syncer::GetSessionName( |
| 85 content::BrowserThread::GetBlockingPool(), | 87 blocking_task_runner, |
| 86 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, | 88 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, |
| 87 weak_factory_.GetWeakPtr(), | 89 weak_factory_.GetWeakPtr(), cache_guid, |
| 88 cache_guid, | |
| 89 signin_scoped_device_id)); | 90 signin_scoped_device_id)); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void LocalDeviceInfoProviderImpl::InitializeContinuation( | 93 void LocalDeviceInfoProviderImpl::InitializeContinuation( |
| 93 const std::string& guid, | 94 const std::string& guid, |
| 94 const std::string& signin_scoped_device_id, | 95 const std::string& signin_scoped_device_id, |
| 95 const std::string& session_name) { | 96 const std::string& session_name) { |
| 96 local_device_info_.reset( | 97 local_device_info_.reset(new sync_driver::DeviceInfo( |
| 97 new sync_driver::DeviceInfo(guid, | 98 guid, session_name, version_, GetSyncUserAgent(), GetLocalDeviceType(), |
| 98 session_name, | 99 signin_scoped_device_id)); |
| 99 chrome::GetVersionString(), | |
| 100 GetSyncUserAgent(), | |
| 101 GetLocalDeviceType(), | |
| 102 signin_scoped_device_id)); | |
| 103 | 100 |
| 104 // Notify observers. | 101 // Notify observers. |
| 105 callback_list_.Notify(); | 102 callback_list_.Notify(); |
| 106 } | 103 } |
| 107 | 104 |
| 108 } // namespace browser_sync | 105 } // namespace browser_sync |
| OLD | NEW |