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/internal_components_factory_impl.h"
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/deferred_on_disk_directory_backing_store.h"
12 #include "sync/syncable/on_disk_directory_backing_store.h"
14 using base::TimeDelta
;
18 InternalComponentsFactoryImpl::InternalComponentsFactoryImpl(
19 const Switches
& switches
) : switches_(switches
) {
22 InternalComponentsFactoryImpl::~InternalComponentsFactoryImpl() { }
24 scoped_ptr
<SyncScheduler
> InternalComponentsFactoryImpl::BuildScheduler(
25 const std::string
& name
,
26 sessions::SyncSessionContext
* context
,
27 CancelationSignal
* cancelation_signal
) {
29 scoped_ptr
<BackoffDelayProvider
> delay(BackoffDelayProvider::FromDefaults());
31 if (switches_
.backoff_override
== BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE
)
32 delay
.reset(BackoffDelayProvider::WithShortInitialRetryOverride());
34 return scoped_ptr
<SyncScheduler
>(new SyncSchedulerImpl(
38 new Syncer(cancelation_signal
)));
41 scoped_ptr
<sessions::SyncSessionContext
>
42 InternalComponentsFactoryImpl::BuildContext(
43 ServerConnectionManager
* connection_manager
,
44 syncable::Directory
* directory
,
45 ExtensionsActivity
* extensions_activity
,
46 const std::vector
<SyncEngineEventListener
*>& listeners
,
47 sessions::DebugInfoGetter
* debug_info_getter
,
48 ModelTypeRegistry
* model_type_registry
,
49 const std::string
& invalidation_client_id
) {
50 return scoped_ptr
<sessions::SyncSessionContext
>(
51 new sessions::SyncSessionContext(
52 connection_manager
, directory
, extensions_activity
,
53 listeners
, debug_info_getter
,
55 switches_
.encryption_method
== ENCRYPTION_KEYSTORE
,
56 switches_
.pre_commit_updates_policy
==
57 FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE
,
58 invalidation_client_id
));
61 scoped_ptr
<syncable::DirectoryBackingStore
>
62 InternalComponentsFactoryImpl::BuildDirectoryBackingStore(
63 StorageOption storage
, const std::string
& dir_name
,
64 const base::FilePath
& backing_filepath
) {
65 if (storage
== STORAGE_ON_DISK
) {
66 return scoped_ptr
<syncable::DirectoryBackingStore
>(
67 new syncable::OnDiskDirectoryBackingStore(dir_name
, backing_filepath
));
68 } else if (storage
== STORAGE_ON_DISK_DEFERRED
) {
69 return scoped_ptr
<syncable::DirectoryBackingStore
>(
70 new syncable::DeferredOnDiskDirectoryBackingStore(dir_name
,
74 return scoped_ptr
<syncable::DirectoryBackingStore
>();
78 InternalComponentsFactory::Switches
79 InternalComponentsFactoryImpl::GetSwitches() const {