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

Side by Side Diff: components/sync/core_impl/test/fake_sync_manager.cc

Issue 2413313004: [Sync] Move the last things out of core/. (Closed)
Patch Set: Address comments. Created 4 years, 2 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 "components/sync/core/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 "components/sync/base/weak_handle.h"
19 #include "components/sync/core/internal_components_factory.h"
20 #include "components/sync/core/test/fake_model_type_connector.h"
21 #include "components/sync/engine/net/http_post_provider_factory.h"
22 #include "components/sync/syncable/directory.h"
23 #include "components/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, base::Bind(&base::DoNothing), run_loop.QuitClosure())) {
75 NOTREACHED();
76 }
77 run_loop.Run();
78 }
79
80 void FakeSyncManager::Init(InitArgs* args) {
81 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get();
82 PurgePartiallySyncedTypes();
83
84 test_user_share_.SetUp();
85 UserShare* share = test_user_share_.user_share();
86 for (ModelTypeSet::Iterator it = initial_sync_ended_types_.First(); it.Good();
87 it.Inc()) {
88 TestUserShare::CreateRoot(it.Get(), share);
89 }
90
91 FOR_EACH_OBSERVER(
92 SyncManager::Observer, observers_,
93 OnInitializationComplete(WeakHandle<JsBackend>(),
94 WeakHandle<DataTypeDebugInfoListener>(), true,
95 initial_sync_ended_types_));
96 }
97
98 ModelTypeSet FakeSyncManager::InitialSyncEndedTypes() {
99 return initial_sync_ended_types_;
100 }
101
102 ModelTypeSet FakeSyncManager::GetTypesWithEmptyProgressMarkerToken(
103 ModelTypeSet types) {
104 ModelTypeSet empty_types = types;
105 empty_types.RemoveAll(progress_marker_types_);
106 return empty_types;
107 }
108
109 bool FakeSyncManager::PurgePartiallySyncedTypes() {
110 ModelTypeSet partial_types;
111 for (ModelTypeSet::Iterator i = progress_marker_types_.First(); i.Good();
112 i.Inc()) {
113 if (!initial_sync_ended_types_.Has(i.Get()))
114 partial_types.Put(i.Get());
115 }
116 progress_marker_types_.RemoveAll(partial_types);
117 cleaned_types_.PutAll(partial_types);
118 return true;
119 }
120
121 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) {
122 NOTIMPLEMENTED();
123 }
124
125 void FakeSyncManager::StartSyncingNormally(
126 const ModelSafeRoutingInfo& routing_info,
127 base::Time last_poll_time) {
128 // Do nothing.
129 }
130
131 void FakeSyncManager::ConfigureSyncer(
132 ConfigureReason reason,
133 ModelTypeSet to_download,
134 ModelTypeSet to_purge,
135 ModelTypeSet to_journal,
136 ModelTypeSet to_unapply,
137 const ModelSafeRoutingInfo& new_routing_info,
138 const base::Closure& ready_task,
139 const base::Closure& retry_task) {
140 last_configure_reason_ = reason;
141 enabled_types_ = GetRoutingInfoTypes(new_routing_info);
142 ModelTypeSet success_types = to_download;
143 success_types.RemoveAll(configure_fail_types_);
144
145 DVLOG(1) << "Faking configuration. Downloading: "
146 << ModelTypeSetToString(success_types)
147 << ". Cleaning: " << ModelTypeSetToString(to_purge);
148
149 // Update our fake directory by clearing and fake-downloading as necessary.
150 UserShare* share = GetUserShare();
151 share->directory->PurgeEntriesWithTypeIn(to_purge, to_journal, to_unapply);
152 for (ModelTypeSet::Iterator it = success_types.First(); it.Good(); it.Inc()) {
153 // We must be careful to not create the same root node twice.
154 if (!initial_sync_ended_types_.Has(it.Get())) {
155 TestUserShare::CreateRoot(it.Get(), share);
156 }
157 }
158
159 // Simulate cleaning up disabled types.
160 // TODO(sync): consider only cleaning those types that were recently disabled,
161 // if this isn't the first cleanup, which more accurately reflects the
162 // behavior of the real cleanup logic.
163 initial_sync_ended_types_.RemoveAll(to_purge);
164 progress_marker_types_.RemoveAll(to_purge);
165 cleaned_types_.PutAll(to_purge);
166
167 // Now simulate the actual configuration for those types that successfully
168 // download + apply.
169 progress_marker_types_.PutAll(success_types);
170 initial_sync_ended_types_.PutAll(success_types);
171 downloaded_types_.PutAll(success_types);
172
173 ready_task.Run();
174 }
175
176 void FakeSyncManager::AddObserver(Observer* observer) {
177 observers_.AddObserver(observer);
178 }
179
180 void FakeSyncManager::RemoveObserver(Observer* observer) {
181 observers_.RemoveObserver(observer);
182 }
183
184 SyncStatus FakeSyncManager::GetDetailedStatus() const {
185 NOTIMPLEMENTED();
186 return SyncStatus();
187 }
188
189 void FakeSyncManager::SaveChanges() {
190 // Do nothing.
191 }
192
193 void FakeSyncManager::ShutdownOnSyncThread(ShutdownReason reason) {
194 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
195 test_user_share_.TearDown();
196 }
197
198 UserShare* FakeSyncManager::GetUserShare() {
199 return test_user_share_.user_share();
200 }
201
202 std::unique_ptr<ModelTypeConnector>
203 FakeSyncManager::GetModelTypeConnectorProxy() {
204 return base::MakeUnique<FakeModelTypeConnector>();
205 }
206
207 const std::string FakeSyncManager::cache_guid() {
208 return test_user_share_.user_share()->directory->cache_guid();
209 }
210
211 bool FakeSyncManager::ReceivedExperiment(Experiments* experiments) {
212 return false;
213 }
214
215 bool FakeSyncManager::HasUnsyncedItems() {
216 NOTIMPLEMENTED();
217 return false;
218 }
219
220 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() {
221 return fake_encryption_handler_.get();
222 }
223
224 std::vector<std::unique_ptr<ProtocolEvent>>
225 FakeSyncManager::GetBufferedProtocolEvents() {
226 return std::vector<std::unique_ptr<ProtocolEvent>>();
227 }
228
229 void FakeSyncManager::RefreshTypes(ModelTypeSet types) {
230 last_refresh_request_types_ = types;
231 }
232
233 void FakeSyncManager::RegisterDirectoryTypeDebugInfoObserver(
234 TypeDebugInfoObserver* observer) {}
235
236 void FakeSyncManager::UnregisterDirectoryTypeDebugInfoObserver(
237 TypeDebugInfoObserver* observer) {}
238
239 bool FakeSyncManager::HasDirectoryTypeDebugInfoObserver(
240 TypeDebugInfoObserver* observer) {
241 return false;
242 }
243
244 void FakeSyncManager::RequestEmitDebugInfo() {}
245
246 void FakeSyncManager::OnIncomingInvalidation(
247 ModelType type,
248 std::unique_ptr<InvalidationInterface> invalidation) {
249 num_invalidations_received_++;
250 }
251
252 ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() {
253 return last_refresh_request_types_;
254 }
255
256 void FakeSyncManager::SetInvalidatorEnabled(bool invalidator_enabled) {
257 // Do nothing.
258 }
259
260 void FakeSyncManager::ClearServerData(const ClearServerDataCallback& callback) {
261 callback.Run();
262 }
263
264 void FakeSyncManager::OnCookieJarChanged(bool account_mismatch,
265 bool empty_jar) {}
266
267 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698