Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Side by Side Diff: components/sync_driver/local_device_info_provider_impl.cc

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "components/sync_driver/local_device_info_provider_impl.h"
6
7 #include "base/bind.h"
8 #include "base/task_runner.h"
9 #include "build/build_config.h"
10 #include "components/sync/base/get_session_name.h"
11 #include "components/sync_driver/sync_util.h"
12
13 namespace browser_sync {
14
15 namespace {
16
17 sync_pb::SyncEnums::DeviceType GetLocalDeviceType(bool is_tablet) {
18 #if defined(OS_CHROMEOS)
19 return sync_pb::SyncEnums_DeviceType_TYPE_CROS;
20 #elif defined(OS_LINUX)
21 return sync_pb::SyncEnums_DeviceType_TYPE_LINUX;
22 #elif defined(OS_ANDROID) || defined(OS_IOS)
23 return is_tablet ? sync_pb::SyncEnums_DeviceType_TYPE_TABLET
24 : sync_pb::SyncEnums_DeviceType_TYPE_PHONE;
25 #elif defined(OS_MACOSX)
26 return sync_pb::SyncEnums_DeviceType_TYPE_MAC;
27 #elif defined(OS_WIN)
28 return sync_pb::SyncEnums_DeviceType_TYPE_WIN;
29 #else
30 return sync_pb::SyncEnums_DeviceType_TYPE_OTHER;
31 #endif
32 }
33
34 } // namespace
35
36 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl(
37 version_info::Channel channel,
38 const std::string& version,
39 bool is_tablet)
40 : channel_(channel),
41 version_(version),
42 is_tablet_(is_tablet),
43 weak_factory_(this) {
44 DCHECK(CalledOnValidThread());
45 }
46
47 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {}
48
49 const sync_driver::DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo()
50 const {
51 DCHECK(CalledOnValidThread());
52 return local_device_info_.get();
53 }
54
55 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const {
56 DCHECK(CalledOnValidThread());
57 return MakeUserAgentForSync(channel_, is_tablet_);
58 }
59
60 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const {
61 DCHECK(CalledOnValidThread());
62 return cache_guid_;
63 }
64
65 std::unique_ptr<sync_driver::LocalDeviceInfoProvider::Subscription>
66 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback(
67 const base::Closure& callback) {
68 DCHECK(CalledOnValidThread());
69 DCHECK(!local_device_info_.get());
70 return callback_list_.Add(callback);
71 }
72
73 void LocalDeviceInfoProviderImpl::Initialize(
74 const std::string& cache_guid,
75 const std::string& signin_scoped_device_id,
76 const scoped_refptr<base::TaskRunner>& blocking_task_runner) {
77 DCHECK(CalledOnValidThread());
78 DCHECK(!cache_guid.empty());
79 cache_guid_ = cache_guid;
80
81 syncer::GetSessionName(
82 blocking_task_runner,
83 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation,
84 weak_factory_.GetWeakPtr(), cache_guid,
85 signin_scoped_device_id));
86 }
87
88 void LocalDeviceInfoProviderImpl::InitializeContinuation(
89 const std::string& guid,
90 const std::string& signin_scoped_device_id,
91 const std::string& session_name) {
92 DCHECK(CalledOnValidThread());
93 if (guid != cache_guid_) {
94 // Clear() happened before this callback; abort.
95 return;
96 }
97
98 local_device_info_.reset(new sync_driver::DeviceInfo(
99 guid, session_name, version_, GetSyncUserAgent(),
100 GetLocalDeviceType(is_tablet_), signin_scoped_device_id));
101
102 // Notify observers.
103 callback_list_.Notify();
104 }
105
106 void LocalDeviceInfoProviderImpl::Clear() {
107 DCHECK(CalledOnValidThread());
108 cache_guid_ = "";
109 local_device_info_.reset();
110 }
111
112 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync_driver/local_device_info_provider_impl.h ('k') | components/sync_driver/local_device_info_provider_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698