- add sources.
[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     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) {
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, workers, monitor,
47           empty_listeners, debug_info_getter,
48           traffic_recorder,
49           switches_.encryption_method == ENCRYPTION_KEYSTORE,
50           switches_.pre_commit_updates_policy ==
51               FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE,
52           invalidator_client_id));
53
54 }
55
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));
63     case STORAGE_ON_DISK:
64       return scoped_ptr<syncable::DirectoryBackingStore>(
65           new syncable::OnDiskDirectoryBackingStore(dir_name,
66                                                     backing_filepath));
67     case STORAGE_INVALID:
68       return scoped_ptr<syncable::DirectoryBackingStore>(
69           new syncable::InvalidDirectoryBackingStore());
70   }
71   NOTREACHED();
72   return scoped_ptr<syncable::DirectoryBackingStore>();
73 }
74
75 InternalComponentsFactory::Switches
76 TestInternalComponentsFactory::GetSwitches() const {
77   return switches_;
78 }
79
80 }  // namespace syncer