OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
43 #include "content/browser/browser_thread.h" | 43 #include "content/browser/browser_thread.h" |
44 #include "content/common/notification_service.h" | 44 #include "content/common/notification_service.h" |
45 #include "googleurl/src/gurl.h" | 45 #include "googleurl/src/gurl.h" |
46 #include "webkit/glue/webkit_glue.h" | 46 #include "webkit/glue/webkit_glue.h" |
47 | 47 |
48 static const int kSaveChangesIntervalSeconds = 10; | 48 static const int kSaveChangesIntervalSeconds = 10; |
49 static const FilePath::CharType kSyncDataFolderName[] = | 49 static const FilePath::CharType kSyncDataFolderName[] = |
50 FILE_PATH_LITERAL("Sync Data"); | 50 FILE_PATH_LITERAL("Sync Data"); |
51 | 51 |
52 using browser_sync::DataTypeController; | |
53 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; | 52 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; |
54 | 53 |
55 typedef GoogleServiceAuthError AuthError; | 54 typedef GoogleServiceAuthError AuthError; |
56 | 55 |
57 namespace browser_sync { | 56 namespace browser_sync { |
58 | 57 |
59 using sessions::SyncSessionSnapshot; | 58 using sessions::SyncSessionSnapshot; |
60 using sync_api::SyncCredentials; | 59 using sync_api::SyncCredentials; |
61 | 60 |
62 SyncBackendHost::SyncBackendHost(Profile* profile) | 61 SyncBackendHost::SyncBackendHost(Profile* profile) |
(...skipping 26 matching lines...) Expand all Loading... | |
89 | 88 |
90 SyncBackendHost::~SyncBackendHost() { | 89 SyncBackendHost::~SyncBackendHost() { |
91 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 90 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
92 DCHECK(registrar_.workers.empty()); | 91 DCHECK(registrar_.workers.empty()); |
93 } | 92 } |
94 | 93 |
95 void SyncBackendHost::Initialize( | 94 void SyncBackendHost::Initialize( |
96 SyncFrontend* frontend, | 95 SyncFrontend* frontend, |
97 const WeakHandle<JsEventHandler>& event_handler, | 96 const WeakHandle<JsEventHandler>& event_handler, |
98 const GURL& sync_service_url, | 97 const GURL& sync_service_url, |
99 const syncable::ModelTypeSet& types, | 98 const syncable::ModelTypeSet& initial_types, |
100 const SyncCredentials& credentials, | 99 const SyncCredentials& credentials, |
101 bool delete_sync_data_folder) { | 100 bool delete_sync_data_folder) { |
102 if (!sync_thread_.Start()) | 101 if (!sync_thread_.Start()) |
103 return; | 102 return; |
104 | 103 |
105 frontend_ = frontend; | 104 frontend_ = frontend; |
106 DCHECK(frontend); | 105 DCHECK(frontend); |
107 | 106 |
108 registrar_.workers[GROUP_DB] = new DatabaseModelWorker(); | 107 registrar_.workers[GROUP_DB] = new DatabaseModelWorker(); |
109 registrar_.workers[GROUP_UI] = new UIModelWorker(); | 108 registrar_.workers[GROUP_UI] = new UIModelWorker(); |
110 registrar_.workers[GROUP_PASSIVE] = new ModelSafeWorker(); | 109 registrar_.workers[GROUP_PASSIVE] = new ModelSafeWorker(); |
111 registrar_.workers[GROUP_HISTORY] = new HistoryModelWorker( | 110 registrar_.workers[GROUP_HISTORY] = new HistoryModelWorker( |
112 profile_->GetHistoryService(Profile::IMPLICIT_ACCESS)); | 111 profile_->GetHistoryService(Profile::IMPLICIT_ACCESS)); |
113 | 112 |
114 // Any datatypes that we want the syncer to pull down must | 113 // Any datatypes that we want the syncer to pull down must |
115 // be in the routing_info map. We set them to group passive, meaning that | 114 // be in the routing_info map. We set them to group passive, meaning that |
116 // updates will be applied to sync, but not dispatched to the native models. | 115 // updates will be applied to sync, but not dispatched to the native models. |
117 for (syncable::ModelTypeSet::const_iterator it = types.begin(); | 116 for (syncable::ModelTypeSet::const_iterator it = initial_types.begin(); |
118 it != types.end(); ++it) { | 117 it != initial_types.end(); ++it) { |
119 registrar_.routing_info[(*it)] = GROUP_PASSIVE; | 118 registrar_.routing_info[(*it)] = GROUP_PASSIVE; |
120 } | 119 } |
121 | 120 |
122 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) | 121 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) |
123 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; | 122 registrar_.routing_info[syncable::NIGORI] = GROUP_PASSIVE; |
124 | 123 |
125 PasswordStore* password_store = | 124 PasswordStore* password_store = |
126 profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); | 125 profile_->GetPasswordStore(Profile::IMPLICIT_ACCESS); |
127 if (password_store) { | 126 if (password_store) { |
128 registrar_.workers[GROUP_PASSWORD] = | 127 registrar_.workers[GROUP_PASSWORD] = |
129 new PasswordModelWorker(password_store); | 128 new PasswordModelWorker(password_store); |
130 } else { | 129 } else { |
131 LOG_IF(WARNING, types.count(syncable::PASSWORDS) > 0) << "Password store " | 130 LOG_IF(WARNING, initial_types.count(syncable::PASSWORDS) > 0) |
132 << "not initialized, cannot sync passwords"; | 131 << "Password store not initialized, cannot sync passwords"; |
133 registrar_.routing_info.erase(syncable::PASSWORDS); | 132 registrar_.routing_info.erase(syncable::PASSWORDS); |
134 } | 133 } |
135 | 134 |
136 InitCore(Core::DoInitializeOptions( | 135 InitCore(Core::DoInitializeOptions( |
137 event_handler, | 136 event_handler, |
138 sync_service_url, | 137 sync_service_url, |
139 profile_->GetRequestContext(), | 138 profile_->GetRequestContext(), |
140 credentials, | 139 credentials, |
141 delete_sync_data_folder, | 140 delete_sync_data_folder, |
142 RestoreEncryptionBootstrapToken(), | 141 RestoreEncryptionBootstrapToken(), |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 } | 273 } |
275 | 274 |
276 SyncBackendHost::PendingConfigureDataTypesState:: | 275 SyncBackendHost::PendingConfigureDataTypesState:: |
277 PendingConfigureDataTypesState() | 276 PendingConfigureDataTypesState() |
278 : reason(sync_api::CONFIGURE_REASON_UNKNOWN) {} | 277 : reason(sync_api::CONFIGURE_REASON_UNKNOWN) {} |
279 | 278 |
280 SyncBackendHost::PendingConfigureDataTypesState:: | 279 SyncBackendHost::PendingConfigureDataTypesState:: |
281 ~PendingConfigureDataTypesState() {} | 280 ~PendingConfigureDataTypesState() {} |
282 | 281 |
283 void SyncBackendHost::GetPendingConfigModeState( | 282 void SyncBackendHost::GetPendingConfigModeState( |
284 const DataTypeController::TypeMap& data_type_controllers, | 283 const syncable::ModelTypeSet& types_to_add, |
285 const syncable::ModelTypeSet& types, | 284 const syncable::ModelTypeSet& types_to_remove, |
286 base::Callback<void(bool)> ready_task, | 285 base::Callback<void(bool)> ready_task, |
287 ModelSafeRoutingInfo* routing_info, | 286 ModelSafeRoutingInfo* routing_info, |
288 sync_api::ConfigureReason reason, | 287 sync_api::ConfigureReason reason, |
289 bool nigori_enabled, | 288 SyncBackendHost::PendingConfigureDataTypesState* state) { |
290 SyncBackendHost::PendingConfigureDataTypesState* state, | 289 if (DCHECK_IS_ON()) { |
291 bool* deleted_type) { | 290 syncable::ModelTypeSet intersection; |
291 std::set_intersection( | |
292 types_to_add.begin(), types_to_add.end(), | |
293 types_to_remove.begin(), types_to_remove.end(), | |
294 std::inserter(intersection, intersection.end())); | |
295 DCHECK(intersection.empty()); | |
296 } | |
292 *state = SyncBackendHost::PendingConfigureDataTypesState(); | 297 *state = SyncBackendHost::PendingConfigureDataTypesState(); |
293 *deleted_type = false; | 298 |
294 for (DataTypeController::TypeMap::const_iterator it = | 299 for (syncable::ModelTypeSet::const_iterator it = types_to_add.begin(); |
295 data_type_controllers.begin(); | 300 it != types_to_add.end(); ++it) { |
296 it != data_type_controllers.end(); ++it) { | 301 syncable::ModelType type = *it; |
297 syncable::ModelType type = it->first; | 302 // Add a newly specified data type as GROUP_PASSIVE into the |
298 // If a type is not specified, remove it from the routing_info. | 303 // routing_info, if it does not already exist. |
299 if (types.count(type) == 0) { | 304 if (routing_info->count(type) == 0) { |
300 *deleted_type = true; | 305 (*routing_info)[type] = GROUP_PASSIVE; |
301 routing_info->erase(type); | 306 state->added_types.insert(type); |
302 } else { | |
303 // Add a newly specified data type as GROUP_PASSIVE into the | |
304 // routing_info, if it does not already exist. | |
305 if (routing_info->count(type) == 0) { | |
306 (*routing_info)[type] = GROUP_PASSIVE; | |
307 state->added_types.set(type); | |
308 } | |
309 } | 307 } |
310 } | 308 } |
311 | 309 |
312 // We must handle NIGORI separately as it has no DataTypeController. | 310 for (syncable::ModelTypeSet::const_iterator it = types_to_remove.begin(); |
313 if (types.count(syncable::NIGORI) == 0) { | 311 it != types_to_remove.end(); ++it) { |
314 if (nigori_enabled) { // Nigori is currently enabled. | 312 routing_info->erase(*it); |
315 *deleted_type = true; | |
316 routing_info->erase(syncable::NIGORI); | |
317 // IsNigoriEnabled is now false. | |
318 } | |
319 } else { // Nigori needs to be enabled. | |
320 if (!nigori_enabled) { | |
321 // Currently it is disabled. So enable it. | |
322 (*routing_info)[syncable::NIGORI] = GROUP_PASSIVE; | |
323 state->added_types.set(syncable::NIGORI); | |
324 } | |
325 } | 313 } |
326 | 314 |
327 state->ready_task = ready_task; | 315 state->ready_task = ready_task; |
328 state->initial_types = types; | 316 state->types_to_add = types_to_add; |
329 state->reason = reason; | 317 state->reason = reason; |
330 } | 318 } |
331 | 319 |
332 void SyncBackendHost::ConfigureDataTypes( | 320 void SyncBackendHost::ConfigureDataTypes( |
333 const DataTypeController::TypeMap& data_type_controllers, | 321 const syncable::ModelTypeSet& types_to_add, |
334 const syncable::ModelTypeSet& types, | 322 const syncable::ModelTypeSet& types_to_remove, |
335 sync_api::ConfigureReason reason, | 323 sync_api::ConfigureReason reason, |
336 base::Callback<void(bool)> ready_task, | 324 base::Callback<void(bool)> ready_task, |
337 bool enable_nigori) { | 325 bool enable_nigori) { |
326 syncable::ModelTypeSet types_to_add_with_nigori = types_to_add; | |
327 syncable::ModelTypeSet types_to_remove_with_nigori = types_to_remove; | |
328 if (enable_nigori) { | |
329 types_to_add_with_nigori.insert(syncable::NIGORI); | |
330 types_to_remove_with_nigori.erase(syncable::NIGORI); | |
331 } else { | |
332 types_to_add_with_nigori.erase(syncable::NIGORI); | |
333 types_to_remove_with_nigori.insert(syncable::NIGORI); | |
334 } | |
tim (not reviewing)
2011/08/10 23:39:08
^^
Wow, what a mindffffffffffffffff
akalin
2011/08/10 23:41:49
What do you suggest? It's better than the special
| |
338 // Only one configure is allowed at a time. | 335 // Only one configure is allowed at a time. |
339 DCHECK(!pending_config_mode_state_.get()); | 336 DCHECK(!pending_config_mode_state_.get()); |
340 DCHECK(!pending_download_state_.get()); | 337 DCHECK(!pending_download_state_.get()); |
341 DCHECK_GT(initialization_state_, NOT_INITIALIZED); | 338 DCHECK_GT(initialization_state_, NOT_INITIALIZED); |
342 | 339 |
343 syncable::ModelTypeSet types_copy = types; | |
344 if (enable_nigori) { | |
345 types_copy.insert(syncable::NIGORI); | |
346 } | |
347 bool nigori_currently_enabled = IsNigoriEnabled(); | |
348 pending_config_mode_state_.reset(new PendingConfigureDataTypesState()); | 340 pending_config_mode_state_.reset(new PendingConfigureDataTypesState()); |
349 bool deleted_type = false; | |
350 { | 341 { |
351 base::AutoLock lock(registrar_lock_); | 342 base::AutoLock lock(registrar_lock_); |
352 GetPendingConfigModeState(data_type_controllers, types_copy, | 343 GetPendingConfigModeState(types_to_add_with_nigori, |
353 ready_task, ®istrar_.routing_info, reason, | 344 types_to_remove_with_nigori, |
354 nigori_currently_enabled, | 345 ready_task, |
355 pending_config_mode_state_.get(), | 346 ®istrar_.routing_info, reason, |
356 &deleted_type); | 347 pending_config_mode_state_.get()); |
357 } | 348 } |
358 | 349 |
359 if (deleted_type) { | 350 if (!types_to_remove.empty()) { |
360 sync_thread_.message_loop()->PostTask( | 351 sync_thread_.message_loop()->PostTask( |
361 FROM_HERE, | 352 FROM_HERE, |
362 NewRunnableMethod( | 353 NewRunnableMethod( |
363 core_.get(), | 354 core_.get(), |
364 &SyncBackendHost::Core::DoRequestCleanupDisabledTypes)); | 355 &SyncBackendHost::Core::DoRequestCleanupDisabledTypes)); |
365 } | 356 } |
366 | 357 |
367 StartConfiguration(NewCallback(core_.get(), | 358 StartConfiguration(NewCallback(core_.get(), |
368 &SyncBackendHost::Core::FinishConfigureDataTypes)); | 359 &SyncBackendHost::Core::FinishConfigureDataTypes)); |
369 } | 360 } |
(...skipping 15 matching lines...) Expand all Loading... | |
385 // | 376 // |
386 // In the case of additions, on the next sync cycle, the syncer should | 377 // In the case of additions, on the next sync cycle, the syncer should |
387 // notice that the routing info has changed and start the process of | 378 // notice that the routing info has changed and start the process of |
388 // downloading updates for newly added data types. Once this is | 379 // downloading updates for newly added data types. Once this is |
389 // complete, the configure_state_.ready_task_ is run via an | 380 // complete, the configure_state_.ready_task_ is run via an |
390 // OnInitializationComplete notification. | 381 // OnInitializationComplete notification. |
391 | 382 |
392 VLOG(1) << "Syncer in config mode. SBH executing" | 383 VLOG(1) << "Syncer in config mode. SBH executing" |
393 << "FinishConfigureDataTypesOnFrontendLoop"; | 384 << "FinishConfigureDataTypesOnFrontendLoop"; |
394 | 385 |
395 if (pending_config_mode_state_->added_types.none() && | 386 if (pending_config_mode_state_->added_types.empty() && |
396 !core_->sync_manager()->InitialSyncEndedForAllEnabledTypes()) { | 387 !core_->sync_manager()->InitialSyncEndedForAllEnabledTypes()) { |
397 LOG(WARNING) << "No new types, but initial sync not finished." | 388 LOG(WARNING) << "No new types, but initial sync not finished." |
398 << "Possible sync db corruption / removal."; | 389 << "Possible sync db corruption / removal."; |
399 // TODO(tim): Log / UMA / count this somehow? | 390 // TODO(tim): Log / UMA / count this somehow? |
400 // TODO(tim): If no added types, we could (should?) config only for | 391 // TODO(tim): If no added types, we could (should?) config only for |
401 // types that are needed... but this is a rare corruption edge case or | 392 // types that are needed... but this is a rare corruption edge case or |
402 // implies the user mucked around with their syncdb, so for now do all. | 393 // implies the user mucked around with their syncdb, so for now do all. |
403 pending_config_mode_state_->added_types = | 394 pending_config_mode_state_->added_types = |
404 syncable::ModelTypeBitSetFromSet( | 395 pending_config_mode_state_->types_to_add; |
405 pending_config_mode_state_->initial_types); | |
406 } | 396 } |
407 | 397 |
408 // If we've added types, we always want to request a nudge/config (even if | 398 // If we've added types, we always want to request a nudge/config (even if |
409 // the initial sync is ended), in case we could not decrypt the data. | 399 // the initial sync is ended), in case we could not decrypt the data. |
410 if (pending_config_mode_state_->added_types.none()) { | 400 if (pending_config_mode_state_->added_types.empty()) { |
411 VLOG(1) << "SyncBackendHost(" << this << "): No new types added. " | 401 VLOG(1) << "SyncBackendHost(" << this << "): No new types added. " |
412 << "Calling ready_task directly"; | 402 << "Calling ready_task directly"; |
413 // No new types - just notify the caller that the types are available. | 403 // No new types - just notify the caller that the types are available. |
414 pending_config_mode_state_->ready_task.Run(true); | 404 pending_config_mode_state_->ready_task.Run(true); |
415 } else { | 405 } else { |
416 pending_download_state_.reset(pending_config_mode_state_.release()); | 406 pending_download_state_.reset(pending_config_mode_state_.release()); |
417 | 407 |
418 syncable::ModelTypeBitSet types_copy(pending_download_state_->added_types); | 408 // Always configure nigori if it's enabled. |
419 if (IsNigoriEnabled()) | 409 syncable::ModelTypeSet types_to_config = |
420 types_copy.set(syncable::NIGORI); | 410 pending_download_state_->added_types; |
411 if (IsNigoriEnabled()) { | |
412 types_to_config.insert(syncable::NIGORI); | |
413 } | |
421 VLOG(1) << "SyncBackendHost(" << this << "):New Types added. " | 414 VLOG(1) << "SyncBackendHost(" << this << "):New Types added. " |
422 << "Calling DoRequestConfig"; | 415 << "Calling DoRequestConfig"; |
423 sync_thread_.message_loop()->PostTask(FROM_HERE, | 416 sync_thread_.message_loop()->PostTask(FROM_HERE, |
424 NewRunnableMethod(core_.get(), | 417 NewRunnableMethod(core_.get(), |
425 &SyncBackendHost::Core::DoRequestConfig, | 418 &SyncBackendHost::Core::DoRequestConfig, |
426 types_copy, | 419 syncable::ModelTypeBitSetFromSet(types_to_config), |
427 pending_download_state_->reason)); | 420 pending_download_state_->reason)); |
428 } | 421 } |
429 | 422 |
430 pending_config_mode_state_.reset(); | 423 pending_config_mode_state_.reset(); |
431 | 424 |
432 // Notify the SyncManager about the new types. | 425 // Notify the SyncManager about the new types. |
433 sync_thread_.message_loop()->PostTask(FROM_HERE, | 426 sync_thread_.message_loop()->PostTask(FROM_HERE, |
434 NewRunnableMethod(core_.get(), | 427 NewRunnableMethod(core_.get(), |
435 &SyncBackendHost::Core::DoUpdateEnabledTypes)); | 428 &SyncBackendHost::Core::DoUpdateEnabledTypes)); |
436 } | 429 } |
437 | 430 |
438 void SyncBackendHost::EncryptDataTypes( | 431 void SyncBackendHost::EncryptDataTypes( |
439 const syncable::ModelTypeSet& encrypted_types) { | 432 const syncable::ModelTypeSet& encrypted_types) { |
440 sync_thread_.message_loop()->PostTask(FROM_HERE, | 433 sync_thread_.message_loop()->PostTask(FROM_HERE, |
441 NewRunnableMethod(core_.get(), | 434 NewRunnableMethod(core_.get(), |
442 &SyncBackendHost::Core::DoEncryptDataTypes, | 435 &SyncBackendHost::Core::DoEncryptDataTypes, |
443 encrypted_types)); | 436 encrypted_types)); |
444 } | 437 } |
445 | 438 |
446 syncable::ModelTypeSet SyncBackendHost::GetEncryptedDataTypes() const { | 439 syncable::ModelTypeSet SyncBackendHost::GetEncryptedDataTypes() const { |
447 DCHECK_GT(initialization_state_, NOT_INITIALIZED); | 440 DCHECK_GT(initialization_state_, NOT_INITIALIZED); |
448 return core_->sync_manager()->GetEncryptedDataTypes(); | 441 return core_->sync_manager()->GetEncryptedDataTypes(); |
449 } | 442 } |
450 | 443 |
451 void SyncBackendHost::ActivateDataType( | 444 void SyncBackendHost::ActivateDataType( |
452 DataTypeController* data_type_controller, | 445 syncable::ModelType type, ModelSafeGroup group, |
453 ChangeProcessor* change_processor) { | 446 ChangeProcessor* change_processor) { |
454 base::AutoLock lock(registrar_lock_); | 447 base::AutoLock lock(registrar_lock_); |
455 | 448 |
456 // Ensure that the given data type is in the PASSIVE group. | 449 // Ensure that the given data type is in the PASSIVE group. |
457 browser_sync::ModelSafeRoutingInfo::iterator i = | 450 browser_sync::ModelSafeRoutingInfo::iterator i = |
458 registrar_.routing_info.find(data_type_controller->type()); | 451 registrar_.routing_info.find(type); |
459 DCHECK(i != registrar_.routing_info.end()); | 452 DCHECK(i != registrar_.routing_info.end()); |
460 DCHECK((*i).second == GROUP_PASSIVE); | 453 DCHECK((*i).second == GROUP_PASSIVE); |
461 syncable::ModelType type = data_type_controller->type(); | |
462 // Change the data type's routing info to its group. | 454 // Change the data type's routing info to its group. |
463 registrar_.routing_info[type] = data_type_controller->model_safe_group(); | 455 registrar_.routing_info[type] = group; |
464 | 456 |
465 // Add the data type's change processor to the list of change | 457 // Add the data type's change processor to the list of change |
466 // processors so it can receive updates. | 458 // processors so it can receive updates. |
467 DCHECK_EQ(processors_.count(type), 0U); | 459 DCHECK_EQ(processors_.count(type), 0U); |
468 processors_[type] = change_processor; | 460 processors_[type] = change_processor; |
469 | 461 |
470 // Start the change processor. | 462 // Start the change processor. |
471 change_processor->Start(profile_, GetUserShare()); | 463 change_processor->Start(profile_, GetUserShare()); |
464 DCHECK(GetProcessorUnsafe(type)); | |
472 } | 465 } |
473 | 466 |
474 void SyncBackendHost::DeactivateDataType( | 467 void SyncBackendHost::DeactivateDataType(syncable::ModelType type) { |
475 DataTypeController* data_type_controller, | |
476 ChangeProcessor* change_processor) { | |
477 base::AutoLock lock(registrar_lock_); | 468 base::AutoLock lock(registrar_lock_); |
478 registrar_.routing_info.erase(data_type_controller->type()); | 469 registrar_.routing_info.erase(type); |
479 | 470 |
471 std::map<syncable::ModelType, ChangeProcessor*>::iterator it = | |
472 processors_.find(type); | |
480 // Stop the change processor and remove it from the list of processors. | 473 // Stop the change processor and remove it from the list of processors. |
481 change_processor->Stop(); | 474 if (it != processors_.end()) { |
482 std::map<syncable::ModelType, ChangeProcessor*>::size_type erased = | 475 it->second->Stop(); |
483 processors_.erase(data_type_controller->type()); | 476 processors_.erase(it); |
484 DCHECK_EQ(erased, 1U); | 477 } |
478 DCHECK(!GetProcessorUnsafe(type)); | |
485 } | 479 } |
486 | 480 |
487 bool SyncBackendHost::RequestClearServerData() { | 481 bool SyncBackendHost::RequestClearServerData() { |
488 sync_thread_.message_loop()->PostTask(FROM_HERE, | 482 sync_thread_.message_loop()->PostTask(FROM_HERE, |
489 NewRunnableMethod(core_.get(), | 483 NewRunnableMethod(core_.get(), |
490 &SyncBackendHost::Core::DoRequestClearServerData)); | 484 &SyncBackendHost::Core::DoRequestClearServerData)); |
491 return true; | 485 return true; |
492 } | 486 } |
493 | 487 |
494 SyncBackendHost::Core::~Core() { | 488 SyncBackendHost::Core::~Core() { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 processing_passphrase_ = true; | 725 processing_passphrase_ = true; |
732 } | 726 } |
733 | 727 |
734 void SyncBackendHost::Core::DoEncryptDataTypes( | 728 void SyncBackendHost::Core::DoEncryptDataTypes( |
735 const syncable::ModelTypeSet& encrypted_types) { | 729 const syncable::ModelTypeSet& encrypted_types) { |
736 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); | 730 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); |
737 sync_manager_->EncryptDataTypes(encrypted_types); | 731 sync_manager_->EncryptDataTypes(encrypted_types); |
738 } | 732 } |
739 | 733 |
740 void SyncBackendHost::Core::DoRequestConfig( | 734 void SyncBackendHost::Core::DoRequestConfig( |
741 const syncable::ModelTypeBitSet& added_types, | 735 const syncable::ModelTypeBitSet& types_to_config, |
742 sync_api::ConfigureReason reason) { | 736 sync_api::ConfigureReason reason) { |
743 sync_manager_->RequestConfig(added_types, reason); | 737 sync_manager_->RequestConfig(types_to_config, reason); |
744 } | 738 } |
745 | 739 |
746 void SyncBackendHost::Core::DoStartConfiguration(Callback0::Type* callback) { | 740 void SyncBackendHost::Core::DoStartConfiguration(Callback0::Type* callback) { |
747 sync_manager_->StartConfigurationMode(callback); | 741 sync_manager_->StartConfigurationMode(callback); |
748 } | 742 } |
749 | 743 |
750 UIModelWorker* SyncBackendHost::ui_worker() { | 744 UIModelWorker* SyncBackendHost::ui_worker() { |
751 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; | 745 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; |
752 if (w == NULL) | 746 if (w == NULL) |
753 return NULL; | 747 return NULL; |
(...skipping 10 matching lines...) Expand all Loading... | |
764 sync_manager_->RemoveObserver(this); | 758 sync_manager_->RemoveObserver(this); |
765 sync_manager_.reset(); | 759 sync_manager_.reset(); |
766 host_->ui_worker()->OnSyncerShutdownComplete(); | 760 host_->ui_worker()->OnSyncerShutdownComplete(); |
767 | 761 |
768 if (sync_disabled) | 762 if (sync_disabled) |
769 DeleteSyncDataFolder(); | 763 DeleteSyncDataFolder(); |
770 | 764 |
771 host_ = NULL; | 765 host_ = NULL; |
772 } | 766 } |
773 | 767 |
774 ChangeProcessor* SyncBackendHost::Core::GetProcessor( | 768 ChangeProcessor* SyncBackendHost::GetProcessor( |
775 syncable::ModelType model_type) { | 769 syncable::ModelType model_type) { |
770 base::AutoLock lock(registrar_lock_); | |
771 return GetProcessorUnsafe(model_type); | |
772 } | |
773 | |
774 ChangeProcessor* SyncBackendHost::GetProcessorUnsafe( | |
775 syncable::ModelType model_type) { | |
776 registrar_lock_.AssertAcquired(); | |
776 std::map<syncable::ModelType, ChangeProcessor*>::const_iterator it = | 777 std::map<syncable::ModelType, ChangeProcessor*>::const_iterator it = |
777 host_->processors_.find(model_type); | 778 processors_.find(model_type); |
778 | 779 |
779 // Until model association happens for a datatype, it will not appear in | 780 // Until model association happens for a datatype, it will not appear in |
780 // the processors list. During this time, it is OK to drop changes on | 781 // the processors list. During this time, it is OK to drop changes on |
781 // the floor (since model association has not happened yet). When the | 782 // the floor (since model association has not happened yet). When the |
782 // data type is activated, model association takes place then the change | 783 // data type is activated, model association takes place then the change |
783 // processor is added to the processors_ list. This all happens on | 784 // processor is added to the processors_ list. This all happens on |
784 // the UI thread so we will never drop any changes after model | 785 // the UI thread so we will never drop any changes after model |
785 // association. | 786 // association. |
786 if (it == host_->processors_.end()) | 787 if (it == processors_.end()) |
787 return NULL; | 788 return NULL; |
788 | 789 |
789 if (!IsCurrentThreadSafeForModel(model_type)) { | 790 if (!IsCurrentThreadSafeForModel(model_type)) { |
790 NOTREACHED() << "Changes applied on wrong thread. Model: " | 791 NOTREACHED() << "Changes applied on wrong thread. Model: " |
791 << syncable::ModelTypeToString(model_type); | 792 << syncable::ModelTypeToString(model_type); |
792 return NULL; | 793 return NULL; |
793 } | 794 } |
794 | 795 |
795 // Now that we're sure we're on the correct thread, we can access the | 796 // Now that we're sure we're on the correct thread, we can access the |
796 // ChangeProcessor. | 797 // ChangeProcessor. |
797 ChangeProcessor* processor = it->second; | 798 ChangeProcessor* processor = it->second; |
798 | 799 |
799 // Ensure the change processor is willing to accept changes. | 800 // Ensure the change processor is willing to accept changes. |
800 if (!processor->IsRunning()) | 801 if (!processor->IsRunning()) |
801 return NULL; | 802 return NULL; |
802 | 803 |
803 return processor; | 804 return processor; |
804 } | 805 } |
805 | 806 |
806 void SyncBackendHost::Core::OnChangesApplied( | 807 void SyncBackendHost::Core::OnChangesApplied( |
807 syncable::ModelType model_type, | 808 syncable::ModelType model_type, |
808 const sync_api::BaseTransaction* trans, | 809 const sync_api::BaseTransaction* trans, |
809 const sync_api::SyncManager::ChangeRecord* changes, | 810 const sync_api::SyncManager::ChangeRecord* changes, |
810 int change_count) { | 811 int change_count) { |
811 if (!host_ || !host_->frontend_) { | 812 if (!host_ || !host_->frontend_) { |
812 DCHECK(false) << "OnChangesApplied called after Shutdown?"; | 813 DCHECK(false) << "OnChangesApplied called after Shutdown?"; |
813 return; | 814 return; |
814 } | 815 } |
815 ChangeProcessor* processor = GetProcessor(model_type); | 816 ChangeProcessor* processor = host_->GetProcessor(model_type); |
816 if (!processor) | 817 if (!processor) |
817 return; | 818 return; |
818 | 819 |
819 processor->ApplyChangesFromSyncModel(trans, changes, change_count); | 820 processor->ApplyChangesFromSyncModel(trans, changes, change_count); |
820 } | 821 } |
821 | 822 |
822 void SyncBackendHost::Core::OnChangesComplete( | 823 void SyncBackendHost::Core::OnChangesComplete( |
823 syncable::ModelType model_type) { | 824 syncable::ModelType model_type) { |
824 if (!host_ || !host_->frontend_) { | 825 if (!host_ || !host_->frontend_) { |
825 DCHECK(false) << "OnChangesComplete called after Shutdown?"; | 826 DCHECK(false) << "OnChangesComplete called after Shutdown?"; |
826 return; | 827 return; |
827 } | 828 } |
828 | 829 |
829 ChangeProcessor* processor = GetProcessor(model_type); | 830 ChangeProcessor* processor = host_->GetProcessor(model_type); |
830 if (!processor) | 831 if (!processor) |
831 return; | 832 return; |
832 | 833 |
833 // This call just notifies the processor that it can commit, it already | 834 // This call just notifies the processor that it can commit, it already |
834 // buffered any changes it plans to makes so needs no further information. | 835 // buffered any changes it plans to makes so needs no further information. |
835 processor->CommitChangesFromSyncModel(); | 836 processor->CommitChangesFromSyncModel(); |
836 } | 837 } |
837 | 838 |
838 void SyncBackendHost::Core::OnSyncCycleCompleted( | 839 void SyncBackendHost::Core::OnSyncCycleCompleted( |
839 const SyncSessionSnapshot* snapshot) { | 840 const SyncSessionSnapshot* snapshot) { |
(...skipping 14 matching lines...) Expand all Loading... | |
854 snapshot->syncer_status.types_needing_local_migration; | 855 snapshot->syncer_status.types_needing_local_migration; |
855 if (!to_migrate.empty()) | 856 if (!to_migrate.empty()) |
856 host_->frontend_->OnMigrationNeededForTypes(to_migrate); | 857 host_->frontend_->OnMigrationNeededForTypes(to_migrate); |
857 | 858 |
858 // If we are waiting for a configuration change, check here to see | 859 // If we are waiting for a configuration change, check here to see |
859 // if this sync cycle has initialized all of the types we've been | 860 // if this sync cycle has initialized all of the types we've been |
860 // waiting for. | 861 // waiting for. |
861 if (host_->pending_download_state_.get()) { | 862 if (host_->pending_download_state_.get()) { |
862 scoped_ptr<PendingConfigureDataTypesState> state( | 863 scoped_ptr<PendingConfigureDataTypesState> state( |
863 host_->pending_download_state_.release()); | 864 host_->pending_download_state_.release()); |
864 bool found_all_added = true; | 865 DCHECK( |
865 syncable::ModelTypeSet::const_iterator it; | 866 std::includes(state->types_to_add.begin(), state->types_to_add.end(), |
866 for (it = state->initial_types.begin(); it != state->initial_types.end(); | 867 state->added_types.begin(), state->added_types.end())); |
867 ++it) { | 868 syncable::ModelTypeBitSet added_types = |
868 if (state->added_types.test(*it)) | 869 syncable::ModelTypeBitSetFromSet(state->added_types); |
869 found_all_added &= snapshot->initial_sync_ended.test(*it); | 870 bool found_all_added = |
870 } | 871 (added_types & snapshot->initial_sync_ended) == added_types; |
871 state->ready_task.Run(found_all_added); | 872 state->ready_task.Run(found_all_added); |
872 if (!found_all_added) | 873 if (!found_all_added) |
873 return; | 874 return; |
874 } | 875 } |
875 | 876 |
876 if (host_->initialized()) | 877 if (host_->initialized()) |
877 host_->frontend_->OnSyncCycleCompleted(); | 878 host_->frontend_->OnSyncCycleCompleted(); |
878 } | 879 } |
879 | 880 |
880 void SyncBackendHost::Core::OnInitializationComplete( | 881 void SyncBackendHost::Core::OnInitializationComplete( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 // unconditionally as soon as the UI supports having this info early on. | 922 // unconditionally as soon as the UI supports having this info early on. |
922 if (setup_completed) | 923 if (setup_completed) |
923 core_->sync_manager()->RefreshEncryption(); | 924 core_->sync_manager()->RefreshEncryption(); |
924 initialization_state_ = INITIALIZED; | 925 initialization_state_ = INITIALIZED; |
925 frontend_->OnBackendInitialized(js_backend, true); | 926 frontend_->OnBackendInitialized(js_backend, true); |
926 return; | 927 return; |
927 } | 928 } |
928 | 929 |
929 initialization_state_ = DOWNLOADING_NIGORI; | 930 initialization_state_ = DOWNLOADING_NIGORI; |
930 ConfigureDataTypes( | 931 ConfigureDataTypes( |
931 DataTypeController::TypeMap(), | 932 syncable::ModelTypeSet(), |
932 syncable::ModelTypeSet(), | 933 syncable::ModelTypeSet(), |
933 sync_api::CONFIGURE_REASON_NEW_CLIENT, | 934 sync_api::CONFIGURE_REASON_NEW_CLIENT, |
934 base::Bind( | 935 base::Bind( |
935 &SyncBackendHost::Core::HandleInitializationCompletedOnFrontendLoop, | 936 &SyncBackendHost::Core::HandleInitializationCompletedOnFrontendLoop, |
936 core_.get(), js_backend), | 937 core_.get(), js_backend), |
937 true); | 938 true); |
938 } | 939 } |
939 | 940 |
940 bool SyncBackendHost::Core::IsCurrentThreadSafeForModel( | 941 bool SyncBackendHost::IsCurrentThreadSafeForModel( |
941 syncable::ModelType model_type) { | 942 syncable::ModelType model_type) const { |
942 base::AutoLock lock(host_->registrar_lock_); | 943 registrar_lock_.AssertAcquired(); |
943 | 944 |
944 browser_sync::ModelSafeRoutingInfo::const_iterator routing_it = | 945 browser_sync::ModelSafeRoutingInfo::const_iterator routing_it = |
945 host_->registrar_.routing_info.find(model_type); | 946 registrar_.routing_info.find(model_type); |
946 if (routing_it == host_->registrar_.routing_info.end()) | 947 if (routing_it == registrar_.routing_info.end()) |
947 return false; | 948 return false; |
948 browser_sync::ModelSafeGroup group = routing_it->second; | 949 browser_sync::ModelSafeGroup group = routing_it->second; |
949 WorkerMap::const_iterator worker_it = host_->registrar_.workers.find(group); | 950 WorkerMap::const_iterator worker_it = registrar_.workers.find(group); |
950 if (worker_it == host_->registrar_.workers.end()) | 951 if (worker_it == registrar_.workers.end()) |
951 return false; | 952 return false; |
952 ModelSafeWorker* worker = worker_it->second; | 953 ModelSafeWorker* worker = worker_it->second; |
953 return worker->CurrentThreadIsWorkThread(); | 954 return worker->CurrentThreadIsWorkThread(); |
954 } | 955 } |
955 | 956 |
956 void SyncBackendHost::Core::OnAuthError(const AuthError& auth_error) { | 957 void SyncBackendHost::Core::OnAuthError(const AuthError& auth_error) { |
957 // Post to our core loop so we can modify state. Could be on another thread. | 958 // Post to our core loop so we can modify state. Could be on another thread. |
958 host_->frontend_loop_->PostTask(FROM_HERE, | 959 host_->frontend_loop_->PostTask(FROM_HERE, |
959 NewRunnableMethod(this, &Core::HandleAuthErrorEventOnFrontendLoop, | 960 NewRunnableMethod(this, &Core::HandleAuthErrorEventOnFrontendLoop, |
960 auth_error)); | 961 auth_error)); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1049 } | 1050 } |
1050 | 1051 |
1051 void SyncBackendHost::Core::DeleteSyncDataFolder() { | 1052 void SyncBackendHost::Core::DeleteSyncDataFolder() { |
1052 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { | 1053 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { |
1053 if (!file_util::Delete(host_->sync_data_folder_path(), true)) | 1054 if (!file_util::Delete(host_->sync_data_folder_path(), true)) |
1054 LOG(DFATAL) << "Could not delete the Sync Data folder."; | 1055 LOG(DFATAL) << "Could not delete the Sync Data folder."; |
1055 } | 1056 } |
1056 } | 1057 } |
1057 | 1058 |
1058 } // namespace browser_sync | 1059 } // namespace browser_sync |
OLD | NEW |