2f1367fbc02ac771491ea73747ef962023c198a8
[platform/framework/web/crosswalk.git] / src / sync / internal_api / test / test_internal_components_factory.cc
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/test_internal_components_factory.h"
6
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"
12
13 namespace syncer {
14
15 TestInternalComponentsFactory::TestInternalComponentsFactory(
16     const Switches& switches,
17     StorageOption option)
18     : switches_(switches),
19       storage_option_(option) {
20 }
21
22 TestInternalComponentsFactory::~TestInternalComponentsFactory() { }
23
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());
29 }
30
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) {
41
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,
48           traffic_recorder,
49           model_type_registry,
50           switches_.encryption_method == ENCRYPTION_KEYSTORE,
51           switches_.pre_commit_updates_policy ==
52               FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE,
53           invalidator_client_id));
54
55 }
56
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));
64     case STORAGE_ON_DISK:
65       return scoped_ptr<syncable::DirectoryBackingStore>(
66           new syncable::OnDiskDirectoryBackingStore(dir_name,
67                                                     backing_filepath));
68     case STORAGE_INVALID:
69       return scoped_ptr<syncable::DirectoryBackingStore>(
70           new syncable::InvalidDirectoryBackingStore());
71   }
72   NOTREACHED();
73   return scoped_ptr<syncable::DirectoryBackingStore>();
74 }
75
76 InternalComponentsFactory::Switches
77 TestInternalComponentsFactory::GetSwitches() const {
78   return switches_;
79 }
80
81 }  // namespace syncer