• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/model_type_sync_proxy_impl.h"
10 
11 namespace sync_driver {
12 
NonBlockingDataTypeManager()13 NonBlockingDataTypeManager::NonBlockingDataTypeManager()
14     : non_blocking_data_type_controllers_deleter_(
15           &non_blocking_data_type_controllers_) {}
16 
~NonBlockingDataTypeManager()17 NonBlockingDataTypeManager::~NonBlockingDataTypeManager() {}
18 
RegisterType(syncer::ModelType type,bool enabled)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 
InitializeType(syncer::ModelType type,const scoped_refptr<base::SequencedTaskRunner> & task_runner,const base::WeakPtr<syncer::ModelTypeSyncProxyImpl> & proxy_impl)32 void NonBlockingDataTypeManager::InitializeType(
33     syncer::ModelType type,
34     const scoped_refptr<base::SequencedTaskRunner>& task_runner,
35     const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& proxy_impl) {
36   NonBlockingDataTypeControllerMap::iterator it =
37       non_blocking_data_type_controllers_.find(type);
38   DCHECK(it != non_blocking_data_type_controllers_.end());
39   it->second->InitializeType(task_runner, proxy_impl);
40 }
41 
ConnectSyncBackend(scoped_ptr<syncer::SyncContextProxy> proxy)42 void NonBlockingDataTypeManager::ConnectSyncBackend(
43     scoped_ptr<syncer::SyncContextProxy> 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->InitializeSyncContext(proxy->Clone());
48   }
49 }
50 
DisconnectSyncBackend()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->ClearSyncContext();
56   }
57 }
58 
SetPreferredTypes(syncer::ModelTypeSet preferred_types)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 
GetRegisteredTypes() const68 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 sync_driver
79