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

Side by Side Diff: sync/internal_api/test/fake_sync_manager.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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 (c) 2012 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 "sync/internal_api/public/test/fake_sync_manager.h"
6
7 #include <cstddef>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/location.h"
12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h"
14 #include "base/run_loop.h"
15 #include "base/sequenced_task_runner.h"
16 #include "base/single_thread_task_runner.h"
17 #include "base/threading/thread_task_runner_handle.h"
18 #include "sync/internal_api/public/http_post_provider_factory.h"
19 #include "sync/internal_api/public/internal_components_factory.h"
20 #include "sync/internal_api/public/test/fake_model_type_connector.h"
21 #include "sync/internal_api/public/util/weak_handle.h"
22 #include "sync/syncable/directory.h"
23 #include "sync/test/fake_sync_encryption_handler.h"
24
25 class GURL;
26
27 namespace syncer {
28
29 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types,
30 ModelTypeSet progress_marker_types,
31 ModelTypeSet configure_fail_types) :
32 initial_sync_ended_types_(initial_sync_ended_types),
33 progress_marker_types_(progress_marker_types),
34 configure_fail_types_(configure_fail_types),
35 last_configure_reason_(CONFIGURE_REASON_UNKNOWN),
36 num_invalidations_received_(0) {
37 fake_encryption_handler_.reset(new FakeSyncEncryptionHandler());
38 }
39
40 FakeSyncManager::~FakeSyncManager() {}
41
42 ModelTypeSet FakeSyncManager::GetAndResetCleanedTypes() {
43 ModelTypeSet cleaned_types = cleaned_types_;
44 cleaned_types_.Clear();
45 return cleaned_types;
46 }
47
48 ModelTypeSet FakeSyncManager::GetAndResetDownloadedTypes() {
49 ModelTypeSet downloaded_types = downloaded_types_;
50 downloaded_types_.Clear();
51 return downloaded_types;
52 }
53
54 ModelTypeSet FakeSyncManager::GetAndResetEnabledTypes() {
55 ModelTypeSet enabled_types = enabled_types_;
56 enabled_types_.Clear();
57 return enabled_types;
58 }
59
60 ConfigureReason FakeSyncManager::GetAndResetConfigureReason() {
61 ConfigureReason reason = last_configure_reason_;
62 last_configure_reason_ = CONFIGURE_REASON_UNKNOWN;
63 return reason;
64 }
65
66 int FakeSyncManager::GetInvalidationCount() const {
67 return num_invalidations_received_;
68 }
69
70 void FakeSyncManager::WaitForSyncThread() {
71 // Post a task to |sync_task_runner_| and block until it runs.
72 base::RunLoop run_loop;
73 if (!sync_task_runner_->PostTaskAndReply(
74 FROM_HERE,
75 base::Bind(&base::DoNothing),
76 run_loop.QuitClosure())) {
77 NOTREACHED();
78 }
79 run_loop.Run();
80 }
81
82 void FakeSyncManager::Init(InitArgs* args) {
83 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get();
84 PurgePartiallySyncedTypes();
85
86 test_user_share_.SetUp();
87 UserShare* share = test_user_share_.user_share();
88 for (ModelTypeSet::Iterator it = initial_sync_ended_types_.First();
89 it.Good(); it.Inc()) {
90 TestUserShare::CreateRoot(it.Get(), share);
91 }
92
93 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
94 OnInitializationComplete(
95 WeakHandle<JsBackend>(),
96 WeakHandle<DataTypeDebugInfoListener>(),
97 true, initial_sync_ended_types_));
98 }
99
100 ModelTypeSet FakeSyncManager::InitialSyncEndedTypes() {
101 return initial_sync_ended_types_;
102 }
103
104 ModelTypeSet FakeSyncManager::GetTypesWithEmptyProgressMarkerToken(
105 ModelTypeSet types) {
106 ModelTypeSet empty_types = types;
107 empty_types.RemoveAll(progress_marker_types_);
108 return empty_types;
109 }
110
111 bool FakeSyncManager::PurgePartiallySyncedTypes() {
112 ModelTypeSet partial_types;
113 for (ModelTypeSet::Iterator i = progress_marker_types_.First();
114 i.Good(); i.Inc()) {
115 if (!initial_sync_ended_types_.Has(i.Get()))
116 partial_types.Put(i.Get());
117 }
118 progress_marker_types_.RemoveAll(partial_types);
119 cleaned_types_.PutAll(partial_types);
120 return true;
121 }
122
123 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) {
124 NOTIMPLEMENTED();
125 }
126
127 void FakeSyncManager::StartSyncingNormally(
128 const ModelSafeRoutingInfo& routing_info, base::Time last_poll_time) {
129 // Do nothing.
130 }
131
132 void FakeSyncManager::ConfigureSyncer(
133 ConfigureReason reason,
134 ModelTypeSet to_download,
135 ModelTypeSet to_purge,
136 ModelTypeSet to_journal,
137 ModelTypeSet to_unapply,
138 const ModelSafeRoutingInfo& new_routing_info,
139 const base::Closure& ready_task,
140 const base::Closure& retry_task) {
141 last_configure_reason_ = reason;
142 enabled_types_ = GetRoutingInfoTypes(new_routing_info);
143 ModelTypeSet success_types = to_download;
144 success_types.RemoveAll(configure_fail_types_);
145
146 DVLOG(1) << "Faking configuration. Downloading: "
147 << ModelTypeSetToString(success_types) << ". Cleaning: "
148 << ModelTypeSetToString(to_purge);
149
150 // Update our fake directory by clearing and fake-downloading as necessary.
151 UserShare* share = GetUserShare();
152 share->directory->PurgeEntriesWithTypeIn(to_purge,
153 to_journal,
154 to_unapply);
155 for (ModelTypeSet::Iterator it = success_types.First(); it.Good(); it.Inc()) {
156 // We must be careful to not create the same root node twice.
157 if (!initial_sync_ended_types_.Has(it.Get())) {
158 TestUserShare::CreateRoot(it.Get(), share);
159 }
160 }
161
162 // Simulate cleaning up disabled types.
163 // TODO(sync): consider only cleaning those types that were recently disabled,
164 // if this isn't the first cleanup, which more accurately reflects the
165 // behavior of the real cleanup logic.
166 initial_sync_ended_types_.RemoveAll(to_purge);
167 progress_marker_types_.RemoveAll(to_purge);
168 cleaned_types_.PutAll(to_purge);
169
170 // Now simulate the actual configuration for those types that successfully
171 // download + apply.
172 progress_marker_types_.PutAll(success_types);
173 initial_sync_ended_types_.PutAll(success_types);
174 downloaded_types_.PutAll(success_types);
175
176 ready_task.Run();
177 }
178
179 void FakeSyncManager::AddObserver(Observer* observer) {
180 observers_.AddObserver(observer);
181 }
182
183 void FakeSyncManager::RemoveObserver(Observer* observer) {
184 observers_.RemoveObserver(observer);
185 }
186
187 SyncStatus FakeSyncManager::GetDetailedStatus() const {
188 NOTIMPLEMENTED();
189 return SyncStatus();
190 }
191
192 void FakeSyncManager::SaveChanges() {
193 // Do nothing.
194 }
195
196 void FakeSyncManager::ShutdownOnSyncThread(ShutdownReason reason) {
197 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
198 test_user_share_.TearDown();
199 }
200
201 UserShare* FakeSyncManager::GetUserShare() {
202 return test_user_share_.user_share();
203 }
204
205 std::unique_ptr<syncer_v2::ModelTypeConnector>
206 FakeSyncManager::GetModelTypeConnectorProxy() {
207 return base::WrapUnique(new syncer_v2::FakeModelTypeConnector());
208 }
209
210 const std::string FakeSyncManager::cache_guid() {
211 return test_user_share_.user_share()->directory->cache_guid();
212 }
213
214 bool FakeSyncManager::ReceivedExperiment(Experiments* experiments) {
215 return false;
216 }
217
218 bool FakeSyncManager::HasUnsyncedItems() {
219 NOTIMPLEMENTED();
220 return false;
221 }
222
223 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() {
224 return fake_encryption_handler_.get();
225 }
226
227 ScopedVector<syncer::ProtocolEvent>
228 FakeSyncManager::GetBufferedProtocolEvents() {
229 return ScopedVector<syncer::ProtocolEvent>();
230 }
231
232 std::unique_ptr<base::ListValue> FakeSyncManager::GetAllNodesForType(
233 syncer::ModelType type) {
234 return std::unique_ptr<base::ListValue>(new base::ListValue());
235 }
236
237 void FakeSyncManager::RefreshTypes(ModelTypeSet types) {
238 last_refresh_request_types_ = types;
239 }
240
241 void FakeSyncManager::RegisterDirectoryTypeDebugInfoObserver(
242 syncer::TypeDebugInfoObserver* observer) {}
243
244 void FakeSyncManager::UnregisterDirectoryTypeDebugInfoObserver(
245 syncer::TypeDebugInfoObserver* observer) {}
246
247 bool FakeSyncManager::HasDirectoryTypeDebugInfoObserver(
248 syncer::TypeDebugInfoObserver* observer) {
249 return false;
250 }
251
252 void FakeSyncManager::RequestEmitDebugInfo() {}
253
254 void FakeSyncManager::OnIncomingInvalidation(
255 syncer::ModelType type,
256 std::unique_ptr<InvalidationInterface> invalidation) {
257 num_invalidations_received_++;
258 }
259
260 ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() {
261 return last_refresh_request_types_;
262 }
263
264 void FakeSyncManager::SetInvalidatorEnabled(bool invalidator_enabled) {
265 // Do nothing.
266 }
267
268 void FakeSyncManager::ClearServerData(const ClearServerDataCallback& callback) {
269 callback.Run();
270 }
271
272 void FakeSyncManager::OnCookieJarChanged(bool account_mismatch,
273 bool empty_jar) {}
274
275 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/test/fake_model_type_processor.cc ('k') | sync/internal_api/test/model_type_store_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698