• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TestInternalComponentsFactory(const Switches & switches,StorageOption option)15 TestInternalComponentsFactory::TestInternalComponentsFactory(
16     const Switches& switches,
17     StorageOption option)
18     : switches_(switches),
19       storage_option_(option) {
20 }
21 
~TestInternalComponentsFactory()22 TestInternalComponentsFactory::~TestInternalComponentsFactory() { }
23 
BuildScheduler(const std::string & name,sessions::SyncSessionContext * context,syncer::CancelationSignal * cancelation_signal)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>
BuildContext(ServerConnectionManager * connection_manager,syncable::Directory * directory,ExtensionsActivity * monitor,const std::vector<SyncEngineEventListener * > & listeners,sessions::DebugInfoGetter * debug_info_getter,ModelTypeRegistry * model_type_registry,const std::string & invalidator_client_id)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     ModelTypeRegistry* model_type_registry,
39     const std::string& invalidator_client_id) {
40 
41   // Tests don't wire up listeners.
42   std::vector<SyncEngineEventListener*> empty_listeners;
43   return scoped_ptr<sessions::SyncSessionContext>(
44       new sessions::SyncSessionContext(
45           connection_manager, directory, monitor,
46           empty_listeners, debug_info_getter,
47           model_type_registry,
48           switches_.encryption_method == ENCRYPTION_KEYSTORE,
49           switches_.pre_commit_updates_policy ==
50               FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE,
51           invalidator_client_id));
52 
53 }
54 
55 scoped_ptr<syncable::DirectoryBackingStore>
BuildDirectoryBackingStore(const std::string & dir_name,const base::FilePath & backing_filepath)56 TestInternalComponentsFactory::BuildDirectoryBackingStore(
57       const std::string& dir_name, const base::FilePath& backing_filepath) {
58   switch (storage_option_) {
59     case STORAGE_IN_MEMORY:
60       return scoped_ptr<syncable::DirectoryBackingStore>(
61           new syncable::InMemoryDirectoryBackingStore(dir_name));
62     case STORAGE_ON_DISK:
63       return scoped_ptr<syncable::DirectoryBackingStore>(
64           new syncable::OnDiskDirectoryBackingStore(dir_name,
65                                                     backing_filepath));
66     case STORAGE_INVALID:
67       return scoped_ptr<syncable::DirectoryBackingStore>(
68           new syncable::InvalidDirectoryBackingStore());
69   }
70   NOTREACHED();
71   return scoped_ptr<syncable::DirectoryBackingStore>();
72 }
73 
74 InternalComponentsFactory::Switches
GetSwitches() const75 TestInternalComponentsFactory::GetSwitches() const {
76   return switches_;
77 }
78 
79 }  // namespace syncer
80