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

Side by Side Diff: components/sync/device_info/local_device_info_provider_impl.cc

Issue 2915453002: Deprecate NonThreadSafe in components/sync in favor of SequenceChecker. (Closed)
Patch Set: fix comment Created 3 years, 6 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
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/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/task_runner.h" 9 #include "base/task_runner.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 24 matching lines...) Expand all
35 } // namespace 35 } // namespace
36 36
37 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl( 37 LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl(
38 version_info::Channel channel, 38 version_info::Channel channel,
39 const std::string& version, 39 const std::string& version,
40 bool is_tablet) 40 bool is_tablet)
41 : channel_(channel), 41 : channel_(channel),
42 version_(version), 42 version_(version),
43 is_tablet_(is_tablet), 43 is_tablet_(is_tablet),
44 weak_factory_(this) { 44 weak_factory_(this) {
45 DCHECK(CalledOnValidThread()); 45 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
46 } 46 }
47 47
48 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {} 48 LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {
49 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
50 }
49 51
50 const DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const { 52 const DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const {
51 DCHECK(CalledOnValidThread()); 53 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
52 return local_device_info_.get(); 54 return local_device_info_.get();
53 } 55 }
54 56
55 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const { 57 std::string LocalDeviceInfoProviderImpl::GetSyncUserAgent() const {
56 DCHECK(CalledOnValidThread()); 58 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
57 return MakeUserAgentForSync(channel_, is_tablet_); 59 return MakeUserAgentForSync(channel_, is_tablet_);
58 } 60 }
59 61
60 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const { 62 std::string LocalDeviceInfoProviderImpl::GetLocalSyncCacheGUID() const {
61 DCHECK(CalledOnValidThread()); 63 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
62 return cache_guid_; 64 return cache_guid_;
63 } 65 }
64 66
65 std::unique_ptr<LocalDeviceInfoProvider::Subscription> 67 std::unique_ptr<LocalDeviceInfoProvider::Subscription>
66 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback( 68 LocalDeviceInfoProviderImpl::RegisterOnInitializedCallback(
67 const base::Closure& callback) { 69 const base::Closure& callback) {
68 DCHECK(CalledOnValidThread()); 70 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
69 DCHECK(!local_device_info_.get()); 71 DCHECK(!local_device_info_.get());
70 return callback_list_.Add(callback); 72 return callback_list_.Add(callback);
71 } 73 }
72 74
73 void LocalDeviceInfoProviderImpl::Initialize( 75 void LocalDeviceInfoProviderImpl::Initialize(
74 const std::string& cache_guid, 76 const std::string& cache_guid,
75 const std::string& signin_scoped_device_id, 77 const std::string& signin_scoped_device_id,
76 const scoped_refptr<base::TaskRunner>& blocking_task_runner) { 78 const scoped_refptr<base::TaskRunner>& blocking_task_runner) {
77 DCHECK(CalledOnValidThread()); 79 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
78 DCHECK(!cache_guid.empty()); 80 DCHECK(!cache_guid.empty());
79 cache_guid_ = cache_guid; 81 cache_guid_ = cache_guid;
80 82
81 GetSessionName( 83 GetSessionName(
82 blocking_task_runner, 84 blocking_task_runner,
83 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation, 85 base::Bind(&LocalDeviceInfoProviderImpl::InitializeContinuation,
84 weak_factory_.GetWeakPtr(), cache_guid, 86 weak_factory_.GetWeakPtr(), cache_guid,
85 signin_scoped_device_id)); 87 signin_scoped_device_id));
86 } 88 }
87 89
88 void LocalDeviceInfoProviderImpl::InitializeContinuation( 90 void LocalDeviceInfoProviderImpl::InitializeContinuation(
89 const std::string& guid, 91 const std::string& guid,
90 const std::string& signin_scoped_device_id, 92 const std::string& signin_scoped_device_id,
91 const std::string& session_name) { 93 const std::string& session_name) {
92 DCHECK(CalledOnValidThread()); 94 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
93 if (guid != cache_guid_) { 95 if (guid != cache_guid_) {
94 // Clear() happened before this callback; abort. 96 // Clear() happened before this callback; abort.
95 return; 97 return;
96 } 98 }
97 99
98 local_device_info_ = base::MakeUnique<DeviceInfo>( 100 local_device_info_ = base::MakeUnique<DeviceInfo>(
99 guid, session_name, version_, GetSyncUserAgent(), 101 guid, session_name, version_, GetSyncUserAgent(),
100 GetLocalDeviceType(is_tablet_), signin_scoped_device_id); 102 GetLocalDeviceType(is_tablet_), signin_scoped_device_id);
101 103
102 // Notify observers. 104 // Notify observers.
103 callback_list_.Notify(); 105 callback_list_.Notify();
104 } 106 }
105 107
106 void LocalDeviceInfoProviderImpl::Clear() { 108 void LocalDeviceInfoProviderImpl::Clear() {
107 DCHECK(CalledOnValidThread()); 109 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
108 cache_guid_ = ""; 110 cache_guid_ = "";
109 local_device_info_.reset(); 111 local_device_info_.reset();
110 } 112 }
111 113
112 } // namespace syncer 114 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698