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/device_info/local_device_info_provider_impl.h" | 5 #include "components/sync/device_info/local_device_info_provider_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/task_runner.h" | 8 #include "base/task_runner.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "components/sync/base/get_session_name.h" | 10 #include "components/sync/base/get_session_name.h" |
11 #include "components/sync/driver/sync_util.h" | 11 #include "components/sync/driver/sync_util.h" |
12 | 12 |
13 namespace browser_sync { | 13 namespace syncer { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 sync_pb::SyncEnums::DeviceType GetLocalDeviceType(bool is_tablet) { | 17 sync_pb::SyncEnums::DeviceType GetLocalDeviceType(bool is_tablet) { |
18 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
19 return sync_pb::SyncEnums_DeviceType_TYPE_CROS; | 19 return sync_pb::SyncEnums_DeviceType_TYPE_CROS; |
20 #elif defined(OS_LINUX) | 20 #elif defined(OS_LINUX) |
21 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; | 21 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX; |
22 #elif defined(OS_ANDROID) || defined(OS_IOS) | 22 #elif defined(OS_ANDROID) || defined(OS_IOS) |
23 return is_tablet ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET | 23 return is_tablet ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET |
(...skipping 15 matching lines...) Expand all Loading... |
39 bool is_tablet) | 39 bool is_tablet) |
40 : channel_(channel), | 40 : channel_(channel), |
41 version_(version), | 41 version_(version), |
42 is_tablet_(is_tablet), | 42 is_tablet_(is_tablet), |
43 weak_factory_(this) { | 43 weak_factory_(this) { |
44 DCHECK(CalledOnValidThread()); | 44 DCHECK(CalledOnValidThread()); |
45 } | 45 } |
46 | 46 |
47 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {} | 47 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {} |
48 | 48 |
49 const sync_driver::DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() | 49 const DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const { |
50 const { | |
51 DCHECK(CalledOnValidThread()); | 50 DCHECK(CalledOnValidThread()); |
52 return local_device_info_.get(); | 51 return local_device_info_.get(); |
53 } | 52 } |
54 | 53 |
55 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const { | 54 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const { |
56 DCHECK(CalledOnValidThread()); | 55 DCHECK(CalledOnValidThread()); |
57 return MakeUserAgentForSync(channel_, is_tablet_); | 56 return MakeUserAgentForSync(channel_, is_tablet_); |
58 } | 57 } |
59 | 58 |
60 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { | 59 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { |
61 DCHECK(CalledOnValidThread()); | 60 DCHECK(CalledOnValidThread()); |
62 return cache_guid_; | 61 return cache_guid_; |
63 } | 62 } |
64 | 63 |
65 std::unique_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> | 64 std::unique_ptr<LocalDeviceInfoProvider::Subscription> |
66 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( | 65 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( |
67 const base::Closure& callback) { | 66 const base::Closure& callback) { |
68 DCHECK(CalledOnValidThread()); | 67 DCHECK(CalledOnValidThread()); |
69 DCHECK(!local_device_info_.get()); | 68 DCHECK(!local_device_info_.get()); |
70 return callback_list_.Add(callback); | 69 return callback_list_.Add(callback); |
71 } | 70 } |
72 | 71 |
73 void LocalDeviceInfoProviderImpl::Initialize( | 72 void LocalDeviceInfoProviderImpl::Initialize( |
74 const std::string& cache_guid, | 73 const std::string& cache_guid, |
75 const std::string& signin_scoped_device_id, | 74 const std::string& signin_scoped_device_id, |
76 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { | 75 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { |
77 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
78 DCHECK(!cache_guid.empty()); | 77 DCHECK(!cache_guid.empty()); |
79 cache_guid_ = cache_guid; | 78 cache_guid_ = cache_guid; |
80 | 79 |
81 syncer::GetSessionName( | 80 GetSessionName( |
82 blocking_task_runner, | 81 blocking_task_runner, |
83 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, | 82 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, |
84 weak_factory_.GetWeakPtr(), cache_guid, | 83 weak_factory_.GetWeakPtr(), cache_guid, |
85 signin_scoped_device_id)); | 84 signin_scoped_device_id)); |
86 } | 85 } |
87 | 86 |
88 void LocalDeviceInfoProviderImpl::InitializeContinuation( | 87 void LocalDeviceInfoProviderImpl::InitializeContinuation( |
89 const std::string& guid, | 88 const std::string& guid, |
90 const std::string& signin_scoped_device_id, | 89 const std::string& signin_scoped_device_id, |
91 const std::string& session_name) { | 90 const std::string& session_name) { |
92 DCHECK(CalledOnValidThread()); | 91 DCHECK(CalledOnValidThread()); |
93 if (guid != cache_guid_) { | 92 if (guid != cache_guid_) { |
94 // Clear() happened before this callback; abort. | 93 // Clear() happened before this callback; abort. |
95 return; | 94 return; |
96 } | 95 } |
97 | 96 |
98 local_device_info_.reset(new sync_driver::DeviceInfo( | 97 local_device_info_.reset( |
99 guid, session_name, version_, GetSyncUserAgent(), | 98 new DeviceInfo(guid, session_name, version_, GetSyncUserAgent(), |
100 GetLocalDeviceType(is_tablet_), signin_scoped_device_id)); | 99 GetLocalDeviceType(is_tablet_), signin_scoped_device_id)); |
101 | 100 |
102 // Notify observers. | 101 // Notify observers. |
103 callback_list_.Notify(); | 102 callback_list_.Notify(); |
104 } | 103 } |
105 | 104 |
106 void LocalDeviceInfoProviderImpl::Clear() { | 105 void LocalDeviceInfoProviderImpl::Clear() { |
107 DCHECK(CalledOnValidThread()); | 106 DCHECK(CalledOnValidThread()); |
108 cache_guid_ = ""; | 107 cache_guid_ = ""; |
109 local_device_info_.reset(); | 108 local_device_info_.reset(); |
110 } | 109 } |
111 | 110 |
112 } // namespace browser_sync | 111 } // namespace syncer |
OLD | NEW |