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/internal_components_factory_impl.h"
6
7 #include "sync/engine/backoff_delay_provider.h"
8 #include "sync/engine/syncer.h"
9 #include "sync/engine/sync_scheduler_impl.h"
10 #include "sync/sessions/sync_session_context.h"
11 #include "sync/syncable/on_disk_directory_backing_store.h"
12
13 using base::TimeDelta;
14
15 namespace syncer {
16
InternalComponentsFactoryImpl(const Switches & switches)17 InternalComponentsFactoryImpl::InternalComponentsFactoryImpl(
18 const Switches& switches) : switches_(switches) {
19 }
20
~InternalComponentsFactoryImpl()21 InternalComponentsFactoryImpl::~InternalComponentsFactoryImpl() { }
22
BuildScheduler(const std::string & name,sessions::SyncSessionContext * context,CancelationSignal * cancelation_signal)23 scoped_ptr<SyncScheduler> InternalComponentsFactoryImpl::BuildScheduler(
24 const std::string& name,
25 sessions::SyncSessionContext* context,
26 CancelationSignal* cancelation_signal) {
27
28 scoped_ptr<BackoffDelayProvider> delay(BackoffDelayProvider::FromDefaults());
29
30 if (switches_.backoff_override == BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE)
31 delay.reset(BackoffDelayProvider::WithShortInitialRetryOverride());
32
33 return scoped_ptr<SyncScheduler>(new SyncSchedulerImpl(
34 name,
35 delay.release(),
36 context,
37 new Syncer(cancelation_signal)));
38 }
39
40 scoped_ptr<sessions::SyncSessionContext>
BuildContext(ServerConnectionManager * connection_manager,syncable::Directory * directory,ExtensionsActivity * extensions_activity,const std::vector<SyncEngineEventListener * > & listeners,sessions::DebugInfoGetter * debug_info_getter,ModelTypeRegistry * model_type_registry,const std::string & invalidation_client_id)41 InternalComponentsFactoryImpl::BuildContext(
42 ServerConnectionManager* connection_manager,
43 syncable::Directory* directory,
44 ExtensionsActivity* extensions_activity,
45 const std::vector<SyncEngineEventListener*>& listeners,
46 sessions::DebugInfoGetter* debug_info_getter,
47 ModelTypeRegistry* model_type_registry,
48 const std::string& invalidation_client_id) {
49 return scoped_ptr<sessions::SyncSessionContext>(
50 new sessions::SyncSessionContext(
51 connection_manager, directory, extensions_activity,
52 listeners, debug_info_getter,
53 model_type_registry,
54 switches_.encryption_method == ENCRYPTION_KEYSTORE,
55 switches_.pre_commit_updates_policy ==
56 FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE,
57 invalidation_client_id));
58 }
59
60 scoped_ptr<syncable::DirectoryBackingStore>
BuildDirectoryBackingStore(const std::string & dir_name,const base::FilePath & backing_filepath)61 InternalComponentsFactoryImpl::BuildDirectoryBackingStore(
62 const std::string& dir_name, const base::FilePath& backing_filepath) {
63 return scoped_ptr<syncable::DirectoryBackingStore>(
64 new syncable::OnDiskDirectoryBackingStore(dir_name, backing_filepath));
65 }
66
67 InternalComponentsFactory::Switches
GetSwitches() const68 InternalComponentsFactoryImpl::GetSwitches() const {
69 return switches_;
70 }
71
72 } // namespace syncer
73