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 ExtensionsActivity* monitor,
36 const std::vector<SyncEngineEventListener*>& listeners,
37 sessions::DebugInfoGetter* debug_info_getter,
38 TrafficRecorder* traffic_recorder,
39 ModelTypeRegistry* model_type_registry,
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, monitor,
47 empty_listeners, debug_info_getter,
50 switches_.encryption_method == ENCRYPTION_KEYSTORE,
51 switches_.pre_commit_updates_policy ==
52 FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE,
53 invalidator_client_id));
57 scoped_ptr<syncable::DirectoryBackingStore>
58 TestInternalComponentsFactory::BuildDirectoryBackingStore(
59 const std::string& dir_name, const base::FilePath& backing_filepath) {
60 switch (storage_option_) {
61 case STORAGE_IN_MEMORY:
62 return scoped_ptr<syncable::DirectoryBackingStore>(
63 new syncable::InMemoryDirectoryBackingStore(dir_name));
65 return scoped_ptr<syncable::DirectoryBackingStore>(
66 new syncable::OnDiskDirectoryBackingStore(dir_name,
69 return scoped_ptr<syncable::DirectoryBackingStore>(
70 new syncable::InvalidDirectoryBackingStore());
73 return scoped_ptr<syncable::DirectoryBackingStore>();
76 InternalComponentsFactory::Switches
77 TestInternalComponentsFactory::GetSwitches() const {