OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "sync/sessions/model_type_registry.h" | 5 #include "sync/sessions/model_type_registry.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "sync/engine/directory_commit_contributor.h" | 10 #include "sync/engine/directory_commit_contributor.h" |
11 #include "sync/engine/directory_update_handler.h" | 11 #include "sync/engine/directory_update_handler.h" |
12 #include "sync/engine/non_blocking_sync_common.h" | |
12 #include "sync/engine/non_blocking_type_processor.h" | 13 #include "sync/engine/non_blocking_type_processor.h" |
13 #include "sync/engine/non_blocking_type_processor_core.h" | 14 #include "sync/engine/non_blocking_type_processor_core.h" |
15 #include "sync/engine/non_blocking_type_processor_core_interface.h" | |
14 #include "sync/sessions/directory_type_debug_info_emitter.h" | 16 #include "sync/sessions/directory_type_debug_info_emitter.h" |
15 | 17 |
16 namespace syncer { | 18 namespace syncer { |
17 | 19 |
20 namespace { | |
21 | |
22 class NonBlockingTypeProcessorCoreWrapper | |
Nicolas Zea
2014/05/15 21:58:55
Is this that much better than having NonBlockingTy
rlarocque
2014/05/15 22:28:54
The most practical reason is that it allows me to
Nicolas Zea
2014/05/19 23:54:15
How about changing the naming then. It seems that
rlarocque
2014/05/20 01:39:47
Right. Let's discuss naming tomorrow. There will
| |
23 : public NonBlockingTypeProcessorCoreInterface { | |
24 public: | |
25 NonBlockingTypeProcessorCoreWrapper( | |
26 base::WeakPtr<NonBlockingTypeProcessorCore> core, | |
27 scoped_refptr<base::SequencedTaskRunner> sync_thread); | |
28 virtual ~NonBlockingTypeProcessorCoreWrapper(); | |
29 | |
30 virtual void RequestCommits(const CommitRequestDataList& list) OVERRIDE; | |
31 | |
32 private: | |
33 base::WeakPtr<NonBlockingTypeProcessorCore> core_; | |
34 scoped_refptr<base::SequencedTaskRunner> sync_thread_; | |
35 }; | |
36 | |
37 NonBlockingTypeProcessorCoreWrapper::NonBlockingTypeProcessorCoreWrapper( | |
38 base::WeakPtr<NonBlockingTypeProcessorCore> core, | |
39 scoped_refptr<base::SequencedTaskRunner> sync_thread) | |
40 : core_(core), sync_thread_(sync_thread) { | |
41 } | |
42 | |
43 NonBlockingTypeProcessorCoreWrapper::~NonBlockingTypeProcessorCoreWrapper() { | |
44 } | |
45 | |
46 void NonBlockingTypeProcessorCoreWrapper::RequestCommits( | |
47 const CommitRequestDataList& list) { | |
48 sync_thread_->PostTask( | |
49 FROM_HERE, | |
50 base::Bind(&NonBlockingTypeProcessorCore::RequestCommits, core_, list)); | |
51 } | |
52 | |
53 } // namespace | |
54 | |
18 ModelTypeRegistry::ModelTypeRegistry() : directory_(NULL) {} | 55 ModelTypeRegistry::ModelTypeRegistry() : directory_(NULL) {} |
19 | 56 |
20 ModelTypeRegistry::ModelTypeRegistry( | 57 ModelTypeRegistry::ModelTypeRegistry( |
21 const std::vector<scoped_refptr<ModelSafeWorker> >& workers, | 58 const std::vector<scoped_refptr<ModelSafeWorker> >& workers, |
22 syncable::Directory* directory) | 59 syncable::Directory* directory) |
23 : directory_(directory) { | 60 : directory_(directory) { |
24 for (size_t i = 0u; i < workers.size(); ++i) { | 61 for (size_t i = 0u; i < workers.size(); ++i) { |
25 workers_map_.insert( | 62 workers_map_.insert( |
26 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); | 63 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); |
27 } | 64 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 DCHECK(inserted2) << "Attempt to override existing type handler in map"; | 126 DCHECK(inserted2) << "Attempt to override existing type handler in map"; |
90 } | 127 } |
91 | 128 |
92 enabled_directory_types_ = GetRoutingInfoTypes(routing_info); | 129 enabled_directory_types_ = GetRoutingInfoTypes(routing_info); |
93 DCHECK(Intersection(GetEnabledDirectoryTypes(), | 130 DCHECK(Intersection(GetEnabledDirectoryTypes(), |
94 GetEnabledNonBlockingTypes()).Empty()); | 131 GetEnabledNonBlockingTypes()).Empty()); |
95 } | 132 } |
96 | 133 |
97 void ModelTypeRegistry::InitializeNonBlockingType( | 134 void ModelTypeRegistry::InitializeNonBlockingType( |
98 ModelType type, | 135 ModelType type, |
136 const DataTypeState& data_type_state, | |
99 scoped_refptr<base::SequencedTaskRunner> type_task_runner, | 137 scoped_refptr<base::SequencedTaskRunner> type_task_runner, |
100 base::WeakPtr<NonBlockingTypeProcessor> processor) { | 138 base::WeakPtr<NonBlockingTypeProcessor> processor) { |
101 DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); | 139 DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); |
102 | 140 |
103 // Initialize CoreProcessor -> Processor communication channel. | 141 // Initialize CoreProcessor -> Processor communication channel. |
104 scoped_ptr<NonBlockingTypeProcessorCore> core( | 142 scoped_ptr<NonBlockingTypeProcessorCore> core( |
105 new NonBlockingTypeProcessorCore(type, type_task_runner, processor)); | 143 new NonBlockingTypeProcessorCore(type, type_task_runner, processor)); |
106 | 144 |
145 // TODO(rlarocque): DataTypeState should be forwarded to core here. | |
146 (void)data_type_state; | |
Nicolas Zea
2014/05/19 23:54:15
what is this doing?
rlarocque
2014/05/20 01:39:47
Silences an unused variable warning. I seem to re
Nicolas Zea
2014/05/20 21:51:08
I don't think the warning happens for parameters,
rlarocque
2014/05/20 22:29:21
Updated in the latest patch. Let's see if the try
| |
147 | |
107 // Initialize Processor -> CoreProcessor communication channel. | 148 // Initialize Processor -> CoreProcessor communication channel. |
108 type_task_runner->PostTask( | 149 scoped_ptr<NonBlockingTypeProcessorCoreInterface> core_interface( |
109 FROM_HERE, | 150 new NonBlockingTypeProcessorCoreWrapper( |
110 base::Bind(&NonBlockingTypeProcessor::OnConnect, | 151 core->AsWeakPtr(), |
111 processor, | 152 scoped_refptr<base::SequencedTaskRunner>( |
112 core->AsWeakPtr(), | 153 base::MessageLoopProxy::current()))); |
113 scoped_refptr<base::SequencedTaskRunner>( | 154 type_task_runner->PostTask(FROM_HERE, |
114 base::MessageLoopProxy::current()))); | 155 base::Bind(&NonBlockingTypeProcessor::OnConnect, |
156 processor, | |
157 base::Passed(&core_interface))); | |
115 | 158 |
116 DCHECK(update_handler_map_.find(type) == update_handler_map_.end()); | 159 DCHECK(update_handler_map_.find(type) == update_handler_map_.end()); |
117 DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end()); | 160 DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end()); |
118 | 161 |
119 update_handler_map_.insert(std::make_pair(type, core.get())); | 162 update_handler_map_.insert(std::make_pair(type, core.get())); |
120 commit_contributor_map_.insert(std::make_pair(type, core.get())); | 163 commit_contributor_map_.insert(std::make_pair(type, core.get())); |
121 | 164 |
122 // The container takes ownership. | 165 // The container takes ownership. |
123 non_blocking_type_processor_cores_.push_back(core.release()); | 166 non_blocking_type_processor_cores_.push_back(core.release()); |
124 | 167 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 ModelTypeSet enabled_off_thread_types; | 242 ModelTypeSet enabled_off_thread_types; |
200 for (ScopedVector<NonBlockingTypeProcessorCore>::const_iterator it = | 243 for (ScopedVector<NonBlockingTypeProcessorCore>::const_iterator it = |
201 non_blocking_type_processor_cores_.begin(); | 244 non_blocking_type_processor_cores_.begin(); |
202 it != non_blocking_type_processor_cores_.end(); ++it) { | 245 it != non_blocking_type_processor_cores_.end(); ++it) { |
203 enabled_off_thread_types.Put((*it)->GetModelType()); | 246 enabled_off_thread_types.Put((*it)->GetModelType()); |
204 } | 247 } |
205 return enabled_off_thread_types; | 248 return enabled_off_thread_types; |
206 } | 249 } |
207 | 250 |
208 } // namespace syncer | 251 } // namespace syncer |
OLD | NEW |