| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/sync/engine/engine_components_factory_impl.h" | 5 #include "components/sync/engine/engine_components_factory_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 7 #include "components/sync/engine_impl/backoff_delay_provider.h" | 8 #include "components/sync/engine_impl/backoff_delay_provider.h" |
| 8 #include "components/sync/engine_impl/cycle/sync_cycle_context.h" | 9 #include "components/sync/engine_impl/cycle/sync_cycle_context.h" |
| 9 #include "components/sync/engine_impl/sync_scheduler_impl.h" | 10 #include "components/sync/engine_impl/sync_scheduler_impl.h" |
| 10 #include "components/sync/engine_impl/syncer.h" | 11 #include "components/sync/engine_impl/syncer.h" |
| 11 #include "components/sync/syncable/on_disk_directory_backing_store.h" | 12 #include "components/sync/syncable/on_disk_directory_backing_store.h" |
| 12 | 13 |
| 13 using base::TimeDelta; | 14 using base::TimeDelta; |
| 14 | 15 |
| 16 namespace { |
| 17 const int kShortNudgeDelayDurationMS = 1; |
| 18 } |
| 19 |
| 15 namespace syncer { | 20 namespace syncer { |
| 16 | 21 |
| 17 EngineComponentsFactoryImpl::EngineComponentsFactoryImpl( | 22 EngineComponentsFactoryImpl::EngineComponentsFactoryImpl( |
| 18 const Switches& switches) | 23 const Switches& switches) |
| 19 : switches_(switches) {} | 24 : switches_(switches) {} |
| 20 | 25 |
| 21 EngineComponentsFactoryImpl::~EngineComponentsFactoryImpl() {} | 26 EngineComponentsFactoryImpl::~EngineComponentsFactoryImpl() {} |
| 22 | 27 |
| 23 std::unique_ptr<SyncScheduler> EngineComponentsFactoryImpl::BuildScheduler( | 28 std::unique_ptr<SyncScheduler> EngineComponentsFactoryImpl::BuildScheduler( |
| 24 const std::string& name, | 29 const std::string& name, |
| 25 SyncCycleContext* context, | 30 SyncCycleContext* context, |
| 26 CancelationSignal* cancelation_signal) { | 31 CancelationSignal* cancelation_signal) { |
| 27 std::unique_ptr<BackoffDelayProvider> delay( | 32 std::unique_ptr<BackoffDelayProvider> delay( |
| 28 BackoffDelayProvider::FromDefaults()); | 33 BackoffDelayProvider::FromDefaults()); |
| 29 | 34 |
| 30 if (switches_.backoff_override == BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE) | 35 if (switches_.backoff_override == BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE) { |
| 31 delay.reset(BackoffDelayProvider::WithShortInitialRetryOverride()); | 36 delay.reset(BackoffDelayProvider::WithShortInitialRetryOverride()); |
| 37 } |
| 32 | 38 |
| 33 return std::unique_ptr<SyncScheduler>(new SyncSchedulerImpl( | 39 std::unique_ptr<SyncSchedulerImpl> scheduler = |
| 34 name, delay.release(), context, new Syncer(cancelation_signal))); | 40 base::MakeUnique<SyncSchedulerImpl>(name, delay.release(), context, |
| 41 new Syncer(cancelation_signal)); |
| 42 if (switches_.nudge_delay == NudgeDelay::SHORT_NUDGE_DELAY) { |
| 43 // Set the default nudge delay to 0 because the default is used as a floor |
| 44 // for override values, and we don't want the below override to be ignored. |
| 45 scheduler->SetDefaultNudgeDelay(TimeDelta::FromMilliseconds(0)); |
| 46 // Only protocol types can have their delay customized. |
| 47 ModelTypeSet protocol_types = syncer::ProtocolTypes(); |
| 48 std::map<ModelType, base::TimeDelta> nudge_delays; |
| 49 for (ModelTypeSet::Iterator it = protocol_types.First(); it.Good(); |
| 50 it.Inc()) { |
| 51 nudge_delays[it.Get()] = |
| 52 TimeDelta::FromMilliseconds(kShortNudgeDelayDurationMS); |
| 53 } |
| 54 scheduler->OnReceivedCustomNudgeDelays(nudge_delays); |
| 55 } |
| 56 return std::move(scheduler); |
| 35 } | 57 } |
| 36 | 58 |
| 37 std::unique_ptr<SyncCycleContext> EngineComponentsFactoryImpl::BuildContext( | 59 std::unique_ptr<SyncCycleContext> EngineComponentsFactoryImpl::BuildContext( |
| 38 ServerConnectionManager* connection_manager, | 60 ServerConnectionManager* connection_manager, |
| 39 syncable::Directory* directory, | 61 syncable::Directory* directory, |
| 40 ExtensionsActivity* extensions_activity, | 62 ExtensionsActivity* extensions_activity, |
| 41 const std::vector<SyncEngineEventListener*>& listeners, | 63 const std::vector<SyncEngineEventListener*>& listeners, |
| 42 DebugInfoGetter* debug_info_getter, | 64 DebugInfoGetter* debug_info_getter, |
| 43 ModelTypeRegistry* model_type_registry, | 65 ModelTypeRegistry* model_type_registry, |
| 44 const std::string& invalidation_client_id) { | 66 const std::string& invalidation_client_id) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 64 return std::unique_ptr<syncable::DirectoryBackingStore>(); | 86 return std::unique_ptr<syncable::DirectoryBackingStore>(); |
| 65 } | 87 } |
| 66 } | 88 } |
| 67 | 89 |
| 68 EngineComponentsFactory::Switches EngineComponentsFactoryImpl::GetSwitches() | 90 EngineComponentsFactory::Switches EngineComponentsFactoryImpl::GetSwitches() |
| 69 const { | 91 const { |
| 70 return switches_; | 92 return switches_; |
| 71 } | 93 } |
| 72 | 94 |
| 73 } // namespace syncer | 95 } // namespace syncer |
| OLD | NEW |