1 // Copyright 2014 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 "components/sync_driver/non_blocking_data_type_manager.h" 6 7 #include "base/sequenced_task_runner.h" 8 #include "components/sync_driver/non_blocking_data_type_controller.h" 9 #include "sync/engine/non_blocking_type_processor.h" 10 11 namespace browser_sync { 12 13 NonBlockingDataTypeManager::NonBlockingDataTypeManager() 14 : non_blocking_data_type_controllers_deleter_( 15 &non_blocking_data_type_controllers_) {} 16 17 NonBlockingDataTypeManager::~NonBlockingDataTypeManager() {} 18 19 void NonBlockingDataTypeManager::RegisterType( 20 syncer::ModelType type, 21 bool enabled) { 22 DCHECK_EQ(0U, non_blocking_data_type_controllers_.count(type)) 23 << "Duplicate registration of type " << ModelTypeToString(type); 24 25 non_blocking_data_type_controllers_.insert(std::make_pair( 26 type, 27 new NonBlockingDataTypeController( 28 type, 29 enabled))); 30 } 31 32 void NonBlockingDataTypeManager::InitializeTypeProcessor( 33 syncer::ModelType type, 34 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 35 const base::WeakPtr<syncer::NonBlockingTypeProcessor>& processor) { 36 NonBlockingDataTypeControllerMap::iterator it = 37 non_blocking_data_type_controllers_.find(type); 38 DCHECK(it != non_blocking_data_type_controllers_.end()); 39 it->second->InitializeProcessor(task_runner, processor); 40 } 41 42 void NonBlockingDataTypeManager::ConnectSyncBackend( 43 scoped_ptr<syncer::SyncCoreProxy> proxy) { 44 for (NonBlockingDataTypeControllerMap::iterator it = 45 non_blocking_data_type_controllers_.begin(); 46 it != non_blocking_data_type_controllers_.end(); ++it) { 47 it->second->InitializeSyncCoreProxy(proxy->Clone()); 48 } 49 } 50 51 void NonBlockingDataTypeManager::DisconnectSyncBackend() { 52 for (NonBlockingDataTypeControllerMap::iterator it = 53 non_blocking_data_type_controllers_.begin(); 54 it != non_blocking_data_type_controllers_.end(); ++it) { 55 it->second->ClearSyncCoreProxy(); 56 } 57 } 58 59 void NonBlockingDataTypeManager::SetPreferredTypes( 60 syncer::ModelTypeSet preferred_types) { 61 for (NonBlockingDataTypeControllerMap::iterator it = 62 non_blocking_data_type_controllers_.begin(); 63 it != non_blocking_data_type_controllers_.end(); ++it) { 64 it->second->SetIsPreferred(preferred_types.Has(it->first)); 65 } 66 } 67 68 syncer::ModelTypeSet NonBlockingDataTypeManager::GetRegisteredTypes() const { 69 syncer::ModelTypeSet result; 70 for (NonBlockingDataTypeControllerMap::const_iterator it = 71 non_blocking_data_type_controllers_.begin(); 72 it != non_blocking_data_type_controllers_.end(); ++it) { 73 result.Put(it->first); 74 } 75 return result; 76 } 77 78 } // namespace browser_sync 79