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
3 // found in the LICENSE file.
6 #include "chrome/browser/sync/glue/local_device_info_provider_impl.h"
7 #include "chrome/common/channel_info.h"
8 #include "components/sync_driver/sync_util.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "sync/util/get_session_name.h"
11 #include "ui/base/device_form_factor.h"
13 namespace browser_sync
{
17 #if defined(OS_ANDROID)
19 return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
;
23 sync_pb::SyncEnums::DeviceType
GetLocalDeviceType() {
24 #if defined(OS_CHROMEOS)
25 return sync_pb::SyncEnums_DeviceType_TYPE_CROS
;
26 #elif defined(OS_LINUX)
27 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX
;
28 #elif defined(OS_MACOSX)
29 return sync_pb::SyncEnums_DeviceType_TYPE_MAC
;
31 return sync_pb::SyncEnums_DeviceType_TYPE_WIN
;
32 #elif defined(OS_ANDROID)
33 return IsTabletUI() ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET
34 : sync_pb::SyncEnums_DeviceType_TYPE_PHONE
;
36 return sync_pb::SyncEnums_DeviceType_TYPE_OTHER
;
42 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl()
43 : weak_factory_(this) {
46 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {
49 const sync_driver::DeviceInfo
*
50 LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const {
51 return local_device_info_
.get();
54 std::string
LocalDeviceInfoProviderImpl::GetSyncUserAgent() const {
55 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
56 return MakeDesktopUserAgentForSync(chrome::GetChannel());
57 #elif defined(OS_CHROMEOS)
58 return MakeUserAgentForSync("CROS ", chrome::GetChannel());
59 #elif defined(OS_ANDROID)
61 return MakeUserAgentForSync("ANDROID-TABLET ", chrome::GetChannel());
63 return MakeUserAgentForSync("ANDROID-PHONE ", chrome::GetChannel());
68 std::string
LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const {
72 scoped_ptr
<sync_driver::LocalDeviceInfoProvider::Subscription
>
73 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback(
74 const base::Closure
& callback
) {
75 DCHECK(!local_device_info_
.get());
76 return callback_list_
.Add(callback
);
79 void LocalDeviceInfoProviderImpl::Initialize(
80 const std::string
& cache_guid
, const std::string
& signin_scoped_device_id
) {
81 DCHECK(!cache_guid
.empty());
82 cache_guid_
= cache_guid
;
84 syncer::GetSessionName(
85 content::BrowserThread::GetBlockingPool(),
86 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation
,
87 weak_factory_
.GetWeakPtr(),
89 signin_scoped_device_id
));
92 void LocalDeviceInfoProviderImpl::InitializeContinuation(
93 const std::string
& guid
,
94 const std::string
& signin_scoped_device_id
,
95 const std::string
& session_name
) {
96 local_device_info_
.reset(
97 new sync_driver::DeviceInfo(guid
,
99 chrome::GetVersionString(),
101 GetLocalDeviceType(),
102 signin_scoped_device_id
));
105 callback_list_
.Notify();
108 } // namespace browser_sync