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.
5 #include "sync/internal_api/public/test/test_internal_components_factory.h"
7 #include "sync/sessions/sync_session_context.h"
8 #include "sync/syncable/in_memory_directory_backing_store.h"
9 #include "sync/syncable/on_disk_directory_backing_store.h"
10 #include "sync/syncable/invalid_directory_backing_store.h"
11 #include "sync/test/engine/fake_sync_scheduler.h"
15 TestInternalComponentsFactory::TestInternalComponentsFactory(
16 const Switches& switches,
18 : switches_(switches),
19 storage_option_(option) {
22 TestInternalComponentsFactory::~TestInternalComponentsFactory() { }
24 scoped_ptr<SyncScheduler> TestInternalComponentsFactory::BuildScheduler(
25 const std::string& name,
26 sessions::SyncSessionContext* context,
27 syncer::CancelationSignal* cancelation_signal) {
28 return scoped_ptr<SyncScheduler>(new FakeSyncScheduler());
31 scoped_ptr<sessions::SyncSessionContext>
32 TestInternalComponentsFactory::BuildContext(
33 ServerConnectionManager* connection_manager,
34 syncable::Directory* directory,
35 const std::vector<ModelSafeWorker*>& workers,
36 ExtensionsActivity* monitor,
37 const std::vector<SyncEngineEventListener*>& listeners,
38 sessions::DebugInfoGetter* debug_info_getter,
39 TrafficRecorder* traffic_recorder,
40 const std::string& invalidator_client_id) {
42 // Tests don't wire up listeners.
43 std::vector<SyncEngineEventListener*> empty_listeners;
44 return scoped_ptr<sessions::SyncSessionContext>(
45 new sessions::SyncSessionContext(
46 connection_manager, directory, workers, monitor,
47 empty_listeners, debug_info_getter,
49 switches_.encryption_method == ENCRYPTION_KEYSTORE,
50 switches_.pre_commit_updates_policy ==
51 FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE,
52 invalidator_client_id));
56 scoped_ptr<syncable::DirectoryBackingStore>
57 TestInternalComponentsFactory::BuildDirectoryBackingStore(
58 const std::string& dir_name, const base::FilePath& backing_filepath) {
59 switch (storage_option_) {
60 case STORAGE_IN_MEMORY:
61 return scoped_ptr<syncable::DirectoryBackingStore>(
62 new syncable::InMemoryDirectoryBackingStore(dir_name));
64 return scoped_ptr<syncable::DirectoryBackingStore>(
65 new syncable::OnDiskDirectoryBackingStore(dir_name,
68 return scoped_ptr<syncable::DirectoryBackingStore>(
69 new syncable::InvalidDirectoryBackingStore());
72 return scoped_ptr<syncable::DirectoryBackingStore>();
75 InternalComponentsFactory::Switches
76 TestInternalComponentsFactory::GetSwitches() const {