Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: components/sync/driver/glue/sync_backend_host_impl.cc

Issue 2563423005: [Sync] Move ConfigureDataTypes logic into DataTypeManagerImpl. (Closed)
Patch Set: Address comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/driver/glue/sync_backend_host_impl.h" 5 #include "components/sync/driver/glue/sync_backend_host_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 194
195 // Shut down and destroy SyncManager. SyncManager holds a pointer to 195 // Shut down and destroy SyncManager. SyncManager holds a pointer to
196 // |registrar_| so its destruction must be sequenced before the destruction of 196 // |registrar_| so its destruction must be sequenced before the destruction of
197 // |registrar_|. 197 // |registrar_|.
198 sync_task_runner_->PostTask( 198 sync_task_runner_->PostTask(
199 FROM_HERE, base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason)); 199 FROM_HERE, base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason));
200 core_ = nullptr; 200 core_ = nullptr;
201 registrar_ = nullptr; 201 registrar_ = nullptr;
202 } 202 }
203 203
204 ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes( 204 void SyncBackendHostImpl::ConfigureDataTypes(ConfigureParams params) {
205 ConfigureReason reason,
206 const DataTypeConfigStateMap& config_state_map,
207 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task,
208 const base::Callback<void()>& retry_callback) {
209 // Only one configure is allowed at a time. This is guaranteed by our
210 // callers. The SyncBackendHostImpl requests one configure as the backend is
211 // initializing and waits for it to complete. After initialization, all
212 // configurations will pass through the DataTypeManager, which is careful to
213 // never send a new configure request until the current request succeeds.
214
215 // The SyncBackendRegistrar's routing info will be updated by adding the
216 // types_to_add to the list then removing types_to_remove. Any types which
217 // are not in either of those sets will remain untouched.
218 //
219 // Types which were not in the list previously are not fully downloaded, so we
220 // must ask the syncer to download them. Any newly supported datatypes will
221 // not have been in that routing info list, so they will be among the types
222 // downloaded if they are enabled.
223 //
224 // The SyncBackendRegistrar's state was initially derived from the types
225 // detected to have been downloaded in the database. Afterwards it is
226 // modified only by this function. We expect it to remain in sync with the
227 // backend because configuration requests are never aborted; they are retried
228 // until they succeed or the backend is shut down.
229
230 ModelTypeSet disabled_types = GetDataTypesInState(DISABLED, config_state_map);
231 ModelTypeSet fatal_types = GetDataTypesInState(FATAL, config_state_map);
232 ModelTypeSet crypto_types = GetDataTypesInState(CRYPTO, config_state_map);
233 ModelTypeSet unready_types = GetDataTypesInState(UNREADY, config_state_map);
234
235 disabled_types.PutAll(fatal_types);
236 disabled_types.PutAll(crypto_types);
237 disabled_types.PutAll(unready_types);
238
239 ModelTypeSet active_types =
240 GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map);
241 ModelTypeSet clean_first_types =
242 GetDataTypesInState(CONFIGURE_CLEAN, config_state_map);
243 ModelTypeSet types_to_download = registrar_->ConfigureDataTypes(
244 Union(active_types, clean_first_types), disabled_types);
245 types_to_download.PutAll(clean_first_types);
246 types_to_download.RemoveAll(ProxyTypes());
247 if (!types_to_download.Empty())
248 types_to_download.Put(NIGORI);
249
250 // TODO(sync): crbug.com/137550.
251 // It's dangerous to configure types that have progress markers. Types with
252 // progress markers can trigger a MIGRATION_DONE response. We are not
253 // prepared to handle a migration during a configure, so we must ensure that
254 // all our types_to_download actually contain no data before we sync them.
255 //
256 // One common way to end up in this situation used to be types which
257 // downloaded some or all of their data but have not applied it yet. We avoid
258 // problems with those types by purging the data of any such partially synced
259 // types soon after we load the directory.
260 //
261 // Another possible scenario is that we have newly supported or newly enabled
262 // data types being downloaded here but the nigori type, which is always
263 // included in any GetUpdates request, requires migration. The server has
264 // code to detect this scenario based on the configure reason, the fact that
265 // the nigori type is the only requested type which requires migration, and
266 // that the requested types list includes at least one non-nigori type. It
267 // will not send a MIGRATION_DONE response in that case. We still need to be
268 // careful to not send progress markers for non-nigori types, though. If a
269 // non-nigori type in the request requires migration, a MIGRATION_DONE
270 // response will be sent.
271
272 ModelSafeRoutingInfo routing_info;
273 registrar_->GetModelSafeRoutingInfo(&routing_info);
274
275 ModelTypeSet current_types = registrar_->GetLastConfiguredTypes();
276 ModelTypeSet types_to_purge = Difference(ModelTypeSet::All(), current_types);
277 ModelTypeSet inactive_types =
278 GetDataTypesInState(CONFIGURE_INACTIVE, config_state_map);
279 // Include clean_first_types in types_to_purge, they are part of
280 // current_types, but still need to be cleared.
281 DCHECK(current_types.HasAll(clean_first_types));
282 types_to_purge.PutAll(clean_first_types);
283 types_to_purge.RemoveAll(inactive_types);
284 types_to_purge.RemoveAll(unready_types);
285
286 // If a type has already been disabled and unapplied or journaled, it will
287 // not be part of the |types_to_purge| set, and therefore does not need
288 // to be acted on again.
289 fatal_types.RetainAll(types_to_purge);
290 ModelTypeSet unapply_types = Union(crypto_types, clean_first_types);
291 unapply_types.RetainAll(types_to_purge);
292
293 DCHECK(Intersection(current_types, fatal_types).Empty());
294 DCHECK(Intersection(current_types, crypto_types).Empty());
295 DCHECK(current_types.HasAll(types_to_download));
296
297 SDVLOG(1) << "Types " << ModelTypeSetToString(types_to_download)
298 << " added; calling DoConfigureSyncer";
299 // Divide up the types into their corresponding actions (each is mutually
300 // exclusive):
301 // - Types which have just been added to the routing info (types_to_download):
302 // are downloaded.
303 // - Types which have encountered a fatal error (fatal_types) are deleted
304 // from the directory and journaled in the delete journal.
305 // - Types which have encountered a cryptographer error (crypto_types) are
306 // unapplied (local state is purged but sync state is not).
307 // - All other types not in the routing info (types just disabled) are deleted
308 // from the directory.
309 // - Everything else (enabled types and already disabled types) is not
310 // touched.
311 sync_task_runner_->PostTask( 205 sync_task_runner_->PostTask(
312 FROM_HERE, base::Bind(&SyncBackendHostCore::DoPurgeDisabledTypes, core_, 206 FROM_HERE,
313 types_to_purge, fatal_types, unapply_types)); 207 base::Bind(&SyncBackendHostCore::DoPurgeDisabledTypes, core_,
314 RequestConfigureSyncer(reason, types_to_download, routing_info, ready_task, 208 params.to_purge, params.to_journal, params.to_unapply));
315 retry_callback); 209 sync_task_runner_->PostTask(
316 210 FROM_HERE, base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_,
317 DCHECK(Intersection(active_types, types_to_purge).Empty()); 211 base::Passed(&params)));
318 DCHECK(Intersection(active_types, fatal_types).Empty());
319 DCHECK(Intersection(active_types, unapply_types).Empty());
320 DCHECK(Intersection(active_types, inactive_types).Empty());
321 return Difference(active_types, types_to_download);
322 } 212 }
323 213
324 void SyncBackendHostImpl::EnableEncryptEverything() { 214 void SyncBackendHostImpl::EnableEncryptEverything() {
325 sync_task_runner_->PostTask( 215 sync_task_runner_->PostTask(
326 FROM_HERE, 216 FROM_HERE,
327 base::Bind(&SyncBackendHostCore::DoEnableEncryptEverything, core_)); 217 base::Bind(&SyncBackendHostCore::DoEnableEncryptEverything, core_));
328 } 218 }
329 219
330 void SyncBackendHostImpl::ActivateDirectoryDataType( 220 void SyncBackendHostImpl::ActivateDirectoryDataType(
331 ModelType type, 221 ModelType type,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 } 316 }
427 317
428 void SyncBackendHostImpl::DisableDirectoryTypeDebugInfoForwarding() { 318 void SyncBackendHostImpl::DisableDirectoryTypeDebugInfoForwarding() {
429 DCHECK(initialized()); 319 DCHECK(initialized());
430 sync_task_runner_->PostTask( 320 sync_task_runner_->PostTask(
431 FROM_HERE, 321 FROM_HERE,
432 base::Bind(&SyncBackendHostCore::DisableDirectoryTypeDebugInfoForwarding, 322 base::Bind(&SyncBackendHostCore::DisableDirectoryTypeDebugInfoForwarding,
433 core_)); 323 core_));
434 } 324 }
435 325
436 void SyncBackendHostImpl::RequestConfigureSyncer(
437 ConfigureReason reason,
438 ModelTypeSet to_download,
439 const ModelSafeRoutingInfo& routing_info,
440 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task,
441 const base::Closure& retry_callback) {
442 sync_task_runner_->PostTask(
443 FROM_HERE,
444 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_, reason,
445 to_download, routing_info, ready_task, retry_callback));
446 }
447
448 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop( 326 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop(
449 const ModelTypeSet enabled_types, 327 const ModelTypeSet enabled_types,
450 const ModelTypeSet succeeded_configuration_types, 328 const ModelTypeSet succeeded_configuration_types,
451 const ModelTypeSet failed_configuration_types, 329 const ModelTypeSet failed_configuration_types,
452 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) { 330 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) {
453 if (invalidator_) { 331 if (invalidator_) {
454 CHECK(invalidator_->UpdateRegisteredInvalidationIds( 332 CHECK(invalidator_->UpdateRegisteredInvalidationIds(
455 this, ModelTypeSetToObjectIdSet(enabled_types))); 333 this, ModelTypeSetToObjectIdSet(enabled_types)));
456 } 334 }
457 335
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 const SyncManager::ClearServerDataCallback& frontend_callback) { 569 const SyncManager::ClearServerDataCallback& frontend_callback) {
692 DCHECK(thread_checker_.CalledOnValidThread()); 570 DCHECK(thread_checker_.CalledOnValidThread());
693 frontend_callback.Run(); 571 frontend_callback.Run();
694 } 572 }
695 573
696 } // namespace syncer 574 } // namespace syncer
697 575
698 #undef SDVLOG 576 #undef SDVLOG
699 577
700 #undef SLOG 578 #undef SLOG
OLDNEW
« no previous file with comments | « components/sync/driver/glue/sync_backend_host_impl.h ('k') | components/sync/driver/glue/sync_backend_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698