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

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

Issue 11360259: Sync: Add DeviceInfo's ChangeProcessor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix sync_client.cc Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "sync/internal_api/public/test/fake_sync_manager.h" 5 #include "sync/internal_api/public/test/fake_sync_manager.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "sync/internal_api/public/http_post_provider_factory.h" 17 #include "sync/internal_api/public/http_post_provider_factory.h"
18 #include "sync/internal_api/public/internal_components_factory.h" 18 #include "sync/internal_api/public/internal_components_factory.h"
19 #include "sync/internal_api/public/util/weak_handle.h" 19 #include "sync/internal_api/public/util/weak_handle.h"
20 #include "sync/notifier/invalidator.h" 20 #include "sync/notifier/invalidator.h"
21 #include "sync/notifier/invalidator_state.h" 21 #include "sync/notifier/invalidator_state.h"
22 #include "sync/notifier/object_id_invalidation_map.h" 22 #include "sync/notifier/object_id_invalidation_map.h"
23 #include "sync/syncable/directory.h"
23 #include "sync/test/fake_sync_encryption_handler.h" 24 #include "sync/test/fake_sync_encryption_handler.h"
24 25
25 namespace syncer { 26 namespace syncer {
26 27
27 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types, 28 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types,
28 ModelTypeSet progress_marker_types, 29 ModelTypeSet progress_marker_types,
29 ModelTypeSet configure_fail_types) : 30 ModelTypeSet configure_fail_types) :
30 initial_sync_ended_types_(initial_sync_ended_types), 31 initial_sync_ended_types_(initial_sync_ended_types),
31 progress_marker_types_(progress_marker_types), 32 progress_marker_types_(progress_marker_types),
32 configure_fail_types_(configure_fail_types) { 33 configure_fail_types_(configure_fail_types) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 85 }
85 run_loop.Run(); 86 run_loop.Run();
86 } 87 }
87 88
88 void FakeSyncManager::Init( 89 void FakeSyncManager::Init(
89 const FilePath& database_location, 90 const FilePath& database_location,
90 const WeakHandle<JsEventHandler>& event_handler, 91 const WeakHandle<JsEventHandler>& event_handler,
91 const std::string& sync_server_and_path, 92 const std::string& sync_server_and_path,
92 int sync_server_port, 93 int sync_server_port,
93 bool use_ssl, 94 bool use_ssl,
94 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
95 scoped_ptr<HttpPostProviderFactory> post_factory, 95 scoped_ptr<HttpPostProviderFactory> post_factory,
96 const std::vector<ModelSafeWorker*>& workers, 96 const std::vector<ModelSafeWorker*>& workers,
97 ExtensionsActivityMonitor* extensions_activity_monitor, 97 ExtensionsActivityMonitor* extensions_activity_monitor,
98 ChangeDelegate* change_delegate, 98 ChangeDelegate* change_delegate,
99 const SyncCredentials& credentials, 99 const SyncCredentials& credentials,
100 scoped_ptr<Invalidator> invalidator, 100 scoped_ptr<Invalidator> invalidator,
101 const std::string& restored_key_for_bootstrapping, 101 const std::string& restored_key_for_bootstrapping,
102 const std::string& restored_keystore_key_for_bootstrapping, 102 const std::string& restored_keystore_key_for_bootstrapping,
103 scoped_ptr<InternalComponentsFactory> internal_components_factory, 103 scoped_ptr<InternalComponentsFactory> internal_components_factory,
104 Encryptor* encryptor, 104 Encryptor* encryptor,
105 UnrecoverableErrorHandler* unrecoverable_error_handler, 105 UnrecoverableErrorHandler* unrecoverable_error_handler,
106 ReportUnrecoverableErrorFunction 106 ReportUnrecoverableErrorFunction
107 report_unrecoverable_error_function) { 107 report_unrecoverable_error_function) {
108 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 108 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get();
109 PurgePartiallySyncedTypes(); 109 PurgePartiallySyncedTypes();
110
111 test_user_share_.SetUp();
112 UserShare* share = test_user_share_.user_share();
113 for (ModelTypeSet::Iterator it = initial_sync_ended_types_.First();
114 it.Good(); it.Inc()) {
115 TestUserShare::CreateRoot(it.Get(), share);
116 }
117
110 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 118 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
111 OnInitializationComplete( 119 OnInitializationComplete(
112 WeakHandle<JsBackend>(), 120 WeakHandle<JsBackend>(),
113 WeakHandle<DataTypeDebugInfoListener>(), 121 WeakHandle<DataTypeDebugInfoListener>(),
114 true, initial_sync_ended_types_)); 122 true, initial_sync_ended_types_));
115 } 123 }
116 124
117 void FakeSyncManager::ThrowUnrecoverableError() { 125 void FakeSyncManager::ThrowUnrecoverableError() {
118 NOTIMPLEMENTED(); 126 NOTIMPLEMENTED();
119 } 127 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); 187 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info);
180 ModelTypeSet disabled_types = Difference( 188 ModelTypeSet disabled_types = Difference(
181 ModelTypeSet::All(), enabled_types); 189 ModelTypeSet::All(), enabled_types);
182 ModelTypeSet success_types = types_to_config; 190 ModelTypeSet success_types = types_to_config;
183 success_types.RemoveAll(configure_fail_types_); 191 success_types.RemoveAll(configure_fail_types_);
184 192
185 DVLOG(1) << "Faking configuration. Downloading: " 193 DVLOG(1) << "Faking configuration. Downloading: "
186 << ModelTypeSetToString(success_types) << ". Cleaning: " 194 << ModelTypeSetToString(success_types) << ". Cleaning: "
187 << ModelTypeSetToString(disabled_types); 195 << ModelTypeSetToString(disabled_types);
188 196
197 // Update our fake directory by clearing and fake-downloading as necessary.
198 UserShare* share = GetUserShare();
199 share->directory->PurgeEntriesWithTypeIn(disabled_types);
200 for (ModelTypeSet::Iterator it = success_types.First(); it.Good(); it.Inc()) {
201 // We must be careful to not create the same root node twice.
202 if (!initial_sync_ended_types_.Has(it.Get())) {
203 TestUserShare::CreateRoot(it.Get(), share);
204 }
205 }
206
189 // Simulate cleaning up disabled types. 207 // Simulate cleaning up disabled types.
190 // TODO(sync): consider only cleaning those types that were recently disabled, 208 // TODO(sync): consider only cleaning those types that were recently disabled,
191 // if this isn't the first cleanup, which more accurately reflects the 209 // if this isn't the first cleanup, which more accurately reflects the
192 // behavior of the real cleanup logic. 210 // behavior of the real cleanup logic.
193 initial_sync_ended_types_.RemoveAll(disabled_types); 211 initial_sync_ended_types_.RemoveAll(disabled_types);
194 progress_marker_types_.RemoveAll(disabled_types); 212 progress_marker_types_.RemoveAll(disabled_types);
195 cleaned_types_.PutAll(disabled_types); 213 cleaned_types_.PutAll(disabled_types);
196 214
197 // Now simulate the actual configuration for those types that successfully 215 // Now simulate the actual configuration for those types that successfully
198 // download + apply. 216 // download + apply.
(...skipping 22 matching lines...) Expand all
221 } 239 }
222 240
223 void FakeSyncManager::StopSyncingForShutdown(const base::Closure& callback) { 241 void FakeSyncManager::StopSyncingForShutdown(const base::Closure& callback) {
224 if (!sync_task_runner_->PostTask(FROM_HERE, callback)) { 242 if (!sync_task_runner_->PostTask(FROM_HERE, callback)) {
225 NOTREACHED(); 243 NOTREACHED();
226 } 244 }
227 } 245 }
228 246
229 void FakeSyncManager::ShutdownOnSyncThread() { 247 void FakeSyncManager::ShutdownOnSyncThread() {
230 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 248 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
249 test_user_share_.TearDown();
231 } 250 }
232 251
233 UserShare* FakeSyncManager::GetUserShare() { 252 UserShare* FakeSyncManager::GetUserShare() {
234 return NULL; 253 return test_user_share_.user_share();
254 }
255
256 const std::string FakeSyncManager::cache_guid() {
257 return test_user_share_.user_share()->directory->cache_guid();
235 } 258 }
236 259
237 bool FakeSyncManager::ReceivedExperiment(Experiments* experiments) { 260 bool FakeSyncManager::ReceivedExperiment(Experiments* experiments) {
238 return false; 261 return false;
239 } 262 }
240 263
241 bool FakeSyncManager::HasUnsyncedItems() { 264 bool FakeSyncManager::HasUnsyncedItems() {
242 NOTIMPLEMENTED(); 265 NOTIMPLEMENTED();
243 return false; 266 return false;
244 } 267 }
245 268
246 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { 269 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() {
247 return fake_encryption_handler_.get(); 270 return fake_encryption_handler_.get();
248 } 271 }
249 272
250 void FakeSyncManager::InvalidateOnSyncThread( 273 void FakeSyncManager::InvalidateOnSyncThread(
251 const ObjectIdInvalidationMap& invalidation_map, 274 const ObjectIdInvalidationMap& invalidation_map,
252 IncomingInvalidationSource source) { 275 IncomingInvalidationSource source) {
253 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 276 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
254 registrar_.DispatchInvalidationsToHandlers(invalidation_map, source); 277 registrar_.DispatchInvalidationsToHandlers(invalidation_map, source);
255 } 278 }
256 279
257 void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( 280 void FakeSyncManager::UpdateInvalidatorStateOnSyncThread(
258 InvalidatorState state) { 281 InvalidatorState state) {
259 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 282 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
260 registrar_.UpdateInvalidatorState(state); 283 registrar_.UpdateInvalidatorState(state);
261 } 284 }
262 285
263 } // namespace syncer 286 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl_unittest.cc ('k') | sync/internal_api/test/test_user_share.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698