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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 SyncBackendHost::SyncBackendHost(Profile* profile) | 61 SyncBackendHost::SyncBackendHost(Profile* profile) |
62 : core_(new Core(profile->GetDebugName(), | 62 : core_(new Core(profile->GetDebugName(), |
63 ALLOW_THIS_IN_INITIALIZER_LIST(this))), | 63 ALLOW_THIS_IN_INITIALIZER_LIST(this))), |
64 sync_thread_("Chrome_SyncThread"), | 64 sync_thread_("Chrome_SyncThread"), |
65 frontend_loop_(MessageLoop::current()), | 65 frontend_loop_(MessageLoop::current()), |
66 profile_(profile), | 66 profile_(profile), |
67 frontend_(NULL), | 67 frontend_(NULL), |
68 sync_data_folder_path_( | 68 sync_data_folder_path_( |
69 profile_->GetPath().Append(kSyncDataFolderName)), | 69 profile_->GetPath().Append(kSyncDataFolderName)), |
70 last_auth_error_(AuthError::None()), | 70 last_auth_error_(AuthError::None()), |
71 syncapi_initialized_(false) { | 71 sync_manager_initialized_(false) { |
72 } | 72 } |
73 | 73 |
74 SyncBackendHost::SyncBackendHost() | 74 SyncBackendHost::SyncBackendHost() |
75 : sync_thread_("Chrome_SyncThread"), | 75 : sync_thread_("Chrome_SyncThread"), |
76 frontend_loop_(MessageLoop::current()), | 76 frontend_loop_(MessageLoop::current()), |
77 profile_(NULL), | 77 profile_(NULL), |
78 frontend_(NULL), | 78 frontend_(NULL), |
79 last_auth_error_(AuthError::None()), | 79 last_auth_error_(AuthError::None()), |
80 syncapi_initialized_(false) { | 80 sync_manager_initialized_(false) { |
81 } | 81 } |
82 | 82 |
83 SyncBackendHost::~SyncBackendHost() { | 83 SyncBackendHost::~SyncBackendHost() { |
84 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 84 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
85 DCHECK(registrar_.workers.empty()); | 85 DCHECK(registrar_.workers.empty()); |
86 } | 86 } |
87 | 87 |
88 void SyncBackendHost::Initialize( | 88 void SyncBackendHost::Initialize( |
89 SyncFrontend* frontend, | 89 SyncFrontend* frontend, |
90 const GURL& sync_service_url, | 90 const GURL& sync_service_url, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 return token; | 159 return token; |
160 } | 160 } |
161 | 161 |
162 bool SyncBackendHost::IsNigoriEnabled() const { | 162 bool SyncBackendHost::IsNigoriEnabled() const { |
163 base::AutoLock lock(registrar_lock_); | 163 base::AutoLock lock(registrar_lock_); |
164 return registrar_.routing_info.find(syncable::NIGORI) != | 164 return registrar_.routing_info.find(syncable::NIGORI) != |
165 registrar_.routing_info.end(); | 165 registrar_.routing_info.end(); |
166 } | 166 } |
167 | 167 |
168 bool SyncBackendHost::IsUsingExplicitPassphrase() { | 168 bool SyncBackendHost::IsUsingExplicitPassphrase() { |
169 return IsNigoriEnabled() && syncapi_initialized_ && | 169 return IsNigoriEnabled() && sync_manager_initialized_ && |
170 core_->syncapi()->InitialSyncEndedForAllEnabledTypes() && | 170 core_->sync_manager()->InitialSyncEndedForAllEnabledTypes() && |
171 core_->syncapi()->IsUsingExplicitPassphrase(); | 171 core_->sync_manager()->IsUsingExplicitPassphrase(); |
172 } | 172 } |
173 | 173 |
174 bool SyncBackendHost::IsCryptographerReady( | 174 bool SyncBackendHost::IsCryptographerReady( |
175 const sync_api::BaseTransaction* trans) const { | 175 const sync_api::BaseTransaction* trans) const { |
176 return syncapi_initialized_ && trans->GetCryptographer()->is_ready(); | 176 return sync_manager_initialized_ && trans->GetCryptographer()->is_ready(); |
177 } | 177 } |
178 | 178 |
179 JsBackend* SyncBackendHost::GetJsBackend() { | 179 JsBackend* SyncBackendHost::GetJsBackend() { |
180 if (syncapi_initialized_) { | 180 if (sync_manager_initialized_) { |
181 return core_.get(); | 181 return core_.get(); |
182 } else { | 182 } else { |
183 NOTREACHED(); | 183 NOTREACHED(); |
184 return NULL; | 184 return NULL; |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 sync_api::HttpPostProviderFactory* SyncBackendHost::MakeHttpBridgeFactory( | 188 sync_api::HttpPostProviderFactory* SyncBackendHost::MakeHttpBridgeFactory( |
189 net::URLRequestContextGetter* getter) { | 189 net::URLRequestContextGetter* getter) { |
190 return new HttpBridgeFactory(getter); | 190 return new HttpBridgeFactory(getter); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoSetPassphrase, | 230 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoSetPassphrase, |
231 passphrase, is_explicit)); | 231 passphrase, is_explicit)); |
232 } | 232 } |
233 | 233 |
234 void SyncBackendHost::Shutdown(bool sync_disabled) { | 234 void SyncBackendHost::Shutdown(bool sync_disabled) { |
235 // Thread shutdown should occur in the following order: | 235 // Thread shutdown should occur in the following order: |
236 // - Sync Thread | 236 // - Sync Thread |
237 // - UI Thread (stops some time after we return from this call). | 237 // - UI Thread (stops some time after we return from this call). |
238 if (sync_thread_.IsRunning()) { // Not running in tests. | 238 if (sync_thread_.IsRunning()) { // Not running in tests. |
239 // TODO(akalin): Remove the need for this. | 239 // TODO(akalin): Remove the need for this. |
240 core_->syncapi()->RequestEarlyExit(); | 240 if (sync_manager_initialized_) { |
| 241 core_->sync_manager()->RequestEarlyExit(); |
| 242 } |
241 sync_thread_.message_loop()->PostTask(FROM_HERE, | 243 sync_thread_.message_loop()->PostTask(FROM_HERE, |
242 NewRunnableMethod(core_.get(), | 244 NewRunnableMethod(core_.get(), |
243 &SyncBackendHost::Core::DoShutdown, | 245 &SyncBackendHost::Core::DoShutdown, |
244 sync_disabled)); | 246 sync_disabled)); |
245 } | 247 } |
246 | 248 |
247 // Before joining the sync_thread_, we wait for the UIModelWorker to | 249 // Before joining the sync_thread_, we wait for the UIModelWorker to |
248 // give us the green light that it is not depending on the frontend_loop_ to | 250 // give us the green light that it is not depending on the frontend_loop_ to |
249 // process any more tasks. Stop() blocks until this termination condition | 251 // process any more tasks. Stop() blocks until this termination condition |
250 // is true. | 252 // is true. |
(...skipping 26 matching lines...) Expand all Loading... |
277 registrar_.workers.erase(GROUP_HISTORY); | 279 registrar_.workers.erase(GROUP_HISTORY); |
278 registrar_.workers.erase(GROUP_UI); | 280 registrar_.workers.erase(GROUP_UI); |
279 registrar_.workers.erase(GROUP_PASSIVE); | 281 registrar_.workers.erase(GROUP_PASSIVE); |
280 registrar_.workers.erase(GROUP_PASSWORD); | 282 registrar_.workers.erase(GROUP_PASSWORD); |
281 frontend_ = NULL; | 283 frontend_ = NULL; |
282 core_ = NULL; // Releases reference to core_. | 284 core_ = NULL; // Releases reference to core_. |
283 } | 285 } |
284 | 286 |
285 syncable::AutofillMigrationState | 287 syncable::AutofillMigrationState |
286 SyncBackendHost::GetAutofillMigrationState() { | 288 SyncBackendHost::GetAutofillMigrationState() { |
287 return core_->syncapi()->GetAutofillMigrationState(); | 289 DCHECK(sync_manager_initialized_); |
| 290 return core_->sync_manager()->GetAutofillMigrationState(); |
288 } | 291 } |
289 | 292 |
290 void SyncBackendHost::SetAutofillMigrationState( | 293 void SyncBackendHost::SetAutofillMigrationState( |
291 syncable::AutofillMigrationState state) { | 294 syncable::AutofillMigrationState state) { |
292 return core_->syncapi()->SetAutofillMigrationState(state); | 295 DCHECK(sync_manager_initialized_); |
| 296 return core_->sync_manager()->SetAutofillMigrationState(state); |
293 } | 297 } |
294 | 298 |
295 syncable::AutofillMigrationDebugInfo | 299 syncable::AutofillMigrationDebugInfo |
296 SyncBackendHost::GetAutofillMigrationDebugInfo() { | 300 SyncBackendHost::GetAutofillMigrationDebugInfo() { |
297 return core_->syncapi()->GetAutofillMigrationDebugInfo(); | 301 DCHECK(sync_manager_initialized_); |
| 302 return core_->sync_manager()->GetAutofillMigrationDebugInfo(); |
298 } | 303 } |
299 | 304 |
300 void SyncBackendHost::SetAutofillMigrationDebugInfo( | 305 void SyncBackendHost::SetAutofillMigrationDebugInfo( |
301 syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set, | 306 syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set, |
302 const syncable::AutofillMigrationDebugInfo& info) { | 307 const syncable::AutofillMigrationDebugInfo& info) { |
303 return core_->syncapi()->SetAutofillMigrationDebugInfo(property_to_set, info); | 308 DCHECK(sync_manager_initialized_); |
| 309 return core_->sync_manager()->SetAutofillMigrationDebugInfo( |
| 310 property_to_set, info); |
304 } | 311 } |
305 | 312 |
306 void SyncBackendHost::ConfigureAutofillMigration() { | 313 void SyncBackendHost::ConfigureAutofillMigration() { |
307 if (GetAutofillMigrationState() == syncable::NOT_DETERMINED) { | 314 if (GetAutofillMigrationState() == syncable::NOT_DETERMINED) { |
308 sync_api::ReadTransaction trans(GetUserShare()); | 315 sync_api::ReadTransaction trans(GetUserShare()); |
309 sync_api::ReadNode autofil_root_node(&trans); | 316 sync_api::ReadNode autofil_root_node(&trans); |
310 | 317 |
311 // Check for the presence of autofill node. | 318 // Check for the presence of autofill node. |
312 if (!autofil_root_node.InitByTagLookup(browser_sync::kAutofillTag)) { | 319 if (!autofil_root_node.InitByTagLookup(browser_sync::kAutofillTag)) { |
313 SetAutofillMigrationState(syncable::INSUFFICIENT_INFO_TO_DETERMINE); | 320 SetAutofillMigrationState(syncable::INSUFFICIENT_INFO_TO_DETERMINE); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 401 |
395 void SyncBackendHost::ConfigureDataTypes( | 402 void SyncBackendHost::ConfigureDataTypes( |
396 const DataTypeController::TypeMap& data_type_controllers, | 403 const DataTypeController::TypeMap& data_type_controllers, |
397 const syncable::ModelTypeSet& types, | 404 const syncable::ModelTypeSet& types, |
398 sync_api::ConfigureReason reason, | 405 sync_api::ConfigureReason reason, |
399 CancelableTask* ready_task, | 406 CancelableTask* ready_task, |
400 bool enable_nigori) { | 407 bool enable_nigori) { |
401 // Only one configure is allowed at a time. | 408 // Only one configure is allowed at a time. |
402 DCHECK(!pending_config_mode_state_.get()); | 409 DCHECK(!pending_config_mode_state_.get()); |
403 DCHECK(!pending_download_state_.get()); | 410 DCHECK(!pending_download_state_.get()); |
404 DCHECK(syncapi_initialized_); | 411 DCHECK(sync_manager_initialized_); |
405 | 412 |
406 if (types.count(syncable::AUTOFILL_PROFILE) != 0) { | 413 if (types.count(syncable::AUTOFILL_PROFILE) != 0) { |
407 ConfigureAutofillMigration(); | 414 ConfigureAutofillMigration(); |
408 } | 415 } |
409 | 416 |
410 syncable::ModelTypeSet types_copy = types; | 417 syncable::ModelTypeSet types_copy = types; |
411 if (enable_nigori) { | 418 if (enable_nigori) { |
412 types_copy.insert(syncable::NIGORI); | 419 types_copy.insert(syncable::NIGORI); |
413 } | 420 } |
414 bool nigori_currently_enabled = IsNigoriEnabled(); | 421 bool nigori_currently_enabled = IsNigoriEnabled(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 454 |
448 VLOG(1) << "Syncer in config mode. SBH executing" | 455 VLOG(1) << "Syncer in config mode. SBH executing" |
449 << "FinishConfigureDataTypesOnFrontendLoop"; | 456 << "FinishConfigureDataTypesOnFrontendLoop"; |
450 if (pending_config_mode_state_->deleted_type) { | 457 if (pending_config_mode_state_->deleted_type) { |
451 sync_thread_.message_loop()->PostTask(FROM_HERE, | 458 sync_thread_.message_loop()->PostTask(FROM_HERE, |
452 NewRunnableMethod(core_.get(), | 459 NewRunnableMethod(core_.get(), |
453 &SyncBackendHost::Core::DeferNudgeForCleanup)); | 460 &SyncBackendHost::Core::DeferNudgeForCleanup)); |
454 } | 461 } |
455 | 462 |
456 if (pending_config_mode_state_->added_types.none() && | 463 if (pending_config_mode_state_->added_types.none() && |
457 !core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) { | 464 !core_->sync_manager()->InitialSyncEndedForAllEnabledTypes()) { |
458 LOG(WARNING) << "No new types, but initial sync not finished." | 465 LOG(WARNING) << "No new types, but initial sync not finished." |
459 << "Possible sync db corruption / removal."; | 466 << "Possible sync db corruption / removal."; |
460 // TODO(tim): Log / UMA / count this somehow? | 467 // TODO(tim): Log / UMA / count this somehow? |
461 // TODO(tim): If no added types, we could (should?) config only for | 468 // TODO(tim): If no added types, we could (should?) config only for |
462 // types that are needed... but this is a rare corruption edge case or | 469 // types that are needed... but this is a rare corruption edge case or |
463 // implies the user mucked around with their syncdb, so for now do all. | 470 // implies the user mucked around with their syncdb, so for now do all. |
464 pending_config_mode_state_->added_types = | 471 pending_config_mode_state_->added_types = |
465 syncable::ModelTypeBitSetFromSet( | 472 syncable::ModelTypeBitSetFromSet( |
466 pending_config_mode_state_->initial_types); | 473 pending_config_mode_state_->initial_types); |
467 } | 474 } |
(...skipping 30 matching lines...) Expand all Loading... |
498 | 505 |
499 void SyncBackendHost::EncryptDataTypes( | 506 void SyncBackendHost::EncryptDataTypes( |
500 const syncable::ModelTypeSet& encrypted_types) { | 507 const syncable::ModelTypeSet& encrypted_types) { |
501 sync_thread_.message_loop()->PostTask(FROM_HERE, | 508 sync_thread_.message_loop()->PostTask(FROM_HERE, |
502 NewRunnableMethod(core_.get(), | 509 NewRunnableMethod(core_.get(), |
503 &SyncBackendHost::Core::DoEncryptDataTypes, | 510 &SyncBackendHost::Core::DoEncryptDataTypes, |
504 encrypted_types)); | 511 encrypted_types)); |
505 } | 512 } |
506 | 513 |
507 syncable::ModelTypeSet SyncBackendHost::GetEncryptedDataTypes() const { | 514 syncable::ModelTypeSet SyncBackendHost::GetEncryptedDataTypes() const { |
508 DCHECK(syncapi_initialized_); | 515 DCHECK(sync_manager_initialized_); |
509 return core_->syncapi()->GetEncryptedDataTypes(); | 516 return core_->sync_manager()->GetEncryptedDataTypes(); |
510 } | 517 } |
511 | 518 |
512 void SyncBackendHost::RequestNudge(const tracked_objects::Location& location) { | 519 void SyncBackendHost::RequestNudge(const tracked_objects::Location& location) { |
513 sync_thread_.message_loop()->PostTask(FROM_HERE, | 520 sync_thread_.message_loop()->PostTask(FROM_HERE, |
514 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge, | 521 NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge, |
515 location)); | 522 location)); |
516 } | 523 } |
517 | 524 |
518 void SyncBackendHost::ActivateDataType( | 525 void SyncBackendHost::ActivateDataType( |
519 DataTypeController* data_type_controller, | 526 DataTypeController* data_type_controller, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 } | 559 } |
553 | 560 |
554 bool SyncBackendHost::RequestClearServerData() { | 561 bool SyncBackendHost::RequestClearServerData() { |
555 sync_thread_.message_loop()->PostTask(FROM_HERE, | 562 sync_thread_.message_loop()->PostTask(FROM_HERE, |
556 NewRunnableMethod(core_.get(), | 563 NewRunnableMethod(core_.get(), |
557 &SyncBackendHost::Core::DoRequestClearServerData)); | 564 &SyncBackendHost::Core::DoRequestClearServerData)); |
558 return true; | 565 return true; |
559 } | 566 } |
560 | 567 |
561 SyncBackendHost::Core::~Core() { | 568 SyncBackendHost::Core::~Core() { |
| 569 DCHECK(!sync_manager_.get()); |
562 } | 570 } |
563 | 571 |
564 void SyncBackendHost::Core::NotifyPassphraseRequired( | 572 void SyncBackendHost::Core::NotifyPassphraseRequired( |
565 sync_api::PassphraseRequiredReason reason) { | 573 sync_api::PassphraseRequiredReason reason) { |
566 if (!host_ || !host_->frontend_) | 574 if (!host_ || !host_->frontend_) |
567 return; | 575 return; |
568 | 576 |
569 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); | 577 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); |
570 | 578 |
571 // When setting a passphrase fails, unset our waiting flag. | 579 // When setting a passphrase fails, unset our waiting flag. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 http_bridge_factory(http_bridge_factory), | 650 http_bridge_factory(http_bridge_factory), |
643 credentials(credentials), | 651 credentials(credentials), |
644 delete_sync_data_folder(delete_sync_data_folder), | 652 delete_sync_data_folder(delete_sync_data_folder), |
645 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 653 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
646 setup_for_test_mode(setup_for_test_mode) { | 654 setup_for_test_mode(setup_for_test_mode) { |
647 } | 655 } |
648 | 656 |
649 SyncBackendHost::Core::DoInitializeOptions::~DoInitializeOptions() {} | 657 SyncBackendHost::Core::DoInitializeOptions::~DoInitializeOptions() {} |
650 | 658 |
651 sync_api::UserShare* SyncBackendHost::GetUserShare() const { | 659 sync_api::UserShare* SyncBackendHost::GetUserShare() const { |
652 DCHECK(syncapi_initialized_); | 660 DCHECK(sync_manager_initialized_); |
653 return core_->syncapi()->GetUserShare(); | 661 return core_->sync_manager()->GetUserShare(); |
654 } | 662 } |
655 | 663 |
656 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { | 664 SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { |
657 DCHECK(syncapi_initialized_); | 665 DCHECK(sync_manager_initialized_); |
658 return core_->syncapi()->GetDetailedStatus(); | 666 return core_->sync_manager()->GetDetailedStatus(); |
659 } | 667 } |
660 | 668 |
661 SyncBackendHost::StatusSummary SyncBackendHost::GetStatusSummary() { | 669 SyncBackendHost::StatusSummary SyncBackendHost::GetStatusSummary() { |
662 DCHECK(syncapi_initialized_); | 670 DCHECK(sync_manager_initialized_); |
663 return core_->syncapi()->GetStatusSummary(); | 671 return core_->sync_manager()->GetStatusSummary(); |
664 } | 672 } |
665 | 673 |
666 string16 SyncBackendHost::GetAuthenticatedUsername() const { | 674 string16 SyncBackendHost::GetAuthenticatedUsername() const { |
667 DCHECK(syncapi_initialized_); | 675 DCHECK(sync_manager_initialized_); |
668 return UTF8ToUTF16(core_->syncapi()->GetAuthenticatedUsername()); | 676 return UTF8ToUTF16(core_->sync_manager()->GetAuthenticatedUsername()); |
669 } | 677 } |
670 | 678 |
671 const GoogleServiceAuthError& SyncBackendHost::GetAuthError() const { | 679 const GoogleServiceAuthError& SyncBackendHost::GetAuthError() const { |
672 return last_auth_error_; | 680 return last_auth_error_; |
673 } | 681 } |
674 | 682 |
675 const SyncSessionSnapshot* SyncBackendHost::GetLastSessionSnapshot() const { | 683 const SyncSessionSnapshot* SyncBackendHost::GetLastSessionSnapshot() const { |
676 return last_snapshot_.get(); | 684 return last_snapshot_.get(); |
677 } | 685 } |
678 | 686 |
679 void SyncBackendHost::GetWorkers(std::vector<ModelSafeWorker*>* out) { | 687 void SyncBackendHost::GetWorkers(std::vector<ModelSafeWorker*>* out) { |
680 base::AutoLock lock(registrar_lock_); | 688 base::AutoLock lock(registrar_lock_); |
681 out->clear(); | 689 out->clear(); |
682 for (WorkerMap::const_iterator it = registrar_.workers.begin(); | 690 for (WorkerMap::const_iterator it = registrar_.workers.begin(); |
683 it != registrar_.workers.end(); ++it) { | 691 it != registrar_.workers.end(); ++it) { |
684 out->push_back((*it).second); | 692 out->push_back((*it).second); |
685 } | 693 } |
686 } | 694 } |
687 | 695 |
688 void SyncBackendHost::GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 696 void SyncBackendHost::GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
689 base::AutoLock lock(registrar_lock_); | 697 base::AutoLock lock(registrar_lock_); |
690 ModelSafeRoutingInfo copy(registrar_.routing_info); | 698 ModelSafeRoutingInfo copy(registrar_.routing_info); |
691 out->swap(copy); | 699 out->swap(copy); |
692 } | 700 } |
693 | 701 |
694 bool SyncBackendHost::HasUnsyncedItems() const { | 702 bool SyncBackendHost::HasUnsyncedItems() const { |
695 DCHECK(syncapi_initialized_); | 703 DCHECK(sync_manager_initialized_); |
696 return core_->syncapi()->HasUnsyncedItems(); | 704 return core_->sync_manager()->HasUnsyncedItems(); |
697 } | 705 } |
698 | 706 |
699 void SyncBackendHost::LogUnsyncedItems(int level) const { | 707 void SyncBackendHost::LogUnsyncedItems(int level) const { |
700 DCHECK(syncapi_initialized_); | 708 DCHECK(sync_manager_initialized_); |
701 return core_->syncapi()->LogUnsyncedItems(level); | 709 return core_->sync_manager()->LogUnsyncedItems(level); |
702 } | 710 } |
703 | 711 |
704 SyncBackendHost::Core::Core(const std::string& name, SyncBackendHost* backend) | 712 SyncBackendHost::Core::Core(const std::string& name, SyncBackendHost* backend) |
705 : host_(backend), | 713 : name_(name), |
706 syncapi_(new sync_api::SyncManager(name)), | 714 host_(backend), |
707 sync_manager_observer_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 715 sync_manager_observer_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
708 parent_router_(NULL), | 716 parent_router_(NULL), |
709 processing_passphrase_(false), | 717 processing_passphrase_(false), |
710 deferred_nudge_for_cleanup_requested_(false) { | 718 deferred_nudge_for_cleanup_requested_(false) { |
711 } | 719 } |
712 | 720 |
713 // Helper to construct a user agent string (ASCII) suitable for use by | 721 // Helper to construct a user agent string (ASCII) suitable for use by |
714 // the syncapi for any HTTP communication. This string is used by the sync | 722 // the syncapi for any HTTP communication. This string is used by the sync |
715 // backend for classifying client types when calculating statistics. | 723 // backend for classifying client types when calculating statistics. |
716 std::string MakeUserAgentForSyncapi() { | 724 std::string MakeUserAgentForSyncApi() { |
717 std::string user_agent; | 725 std::string user_agent; |
718 user_agent = "Chrome "; | 726 user_agent = "Chrome "; |
719 #if defined(OS_WIN) | 727 #if defined(OS_WIN) |
720 user_agent += "WIN "; | 728 user_agent += "WIN "; |
721 #elif defined(OS_LINUX) | 729 #elif defined(OS_LINUX) |
722 user_agent += "LINUX "; | 730 user_agent += "LINUX "; |
723 #elif defined(OS_FREEBSD) | 731 #elif defined(OS_FREEBSD) |
724 user_agent += "FREEBSD "; | 732 user_agent += "FREEBSD "; |
725 #elif defined(OS_OPENBSD) | 733 #elif defined(OS_OPENBSD) |
726 user_agent += "OPENBSD "; | 734 user_agent += "OPENBSD "; |
(...skipping 21 matching lines...) Expand all Loading... |
748 // initialization, if necessary. | 756 // initialization, if necessary. |
749 if (options.delete_sync_data_folder) { | 757 if (options.delete_sync_data_folder) { |
750 DeleteSyncDataFolder(); | 758 DeleteSyncDataFolder(); |
751 } | 759 } |
752 | 760 |
753 // Make sure that the directory exists before initializing the backend. | 761 // Make sure that the directory exists before initializing the backend. |
754 // If it already exists, this will do no harm. | 762 // If it already exists, this will do no harm. |
755 bool success = file_util::CreateDirectory(host_->sync_data_folder_path()); | 763 bool success = file_util::CreateDirectory(host_->sync_data_folder_path()); |
756 DCHECK(success); | 764 DCHECK(success); |
757 | 765 |
758 syncapi_->AddObserver(this); | 766 sync_manager_.reset(new sync_api::SyncManager(name_)), |
| 767 sync_manager_->AddObserver(this); |
759 const FilePath& path_str = host_->sync_data_folder_path(); | 768 const FilePath& path_str = host_->sync_data_folder_path(); |
760 success = syncapi_->Init( | 769 success = sync_manager_->Init( |
761 path_str, | 770 path_str, |
762 (options.service_url.host() + options.service_url.path()).c_str(), | 771 (options.service_url.host() + options.service_url.path()).c_str(), |
763 options.service_url.EffectiveIntPort(), | 772 options.service_url.EffectiveIntPort(), |
764 options.service_url.SchemeIsSecure(), | 773 options.service_url.SchemeIsSecure(), |
765 options.http_bridge_factory, | 774 options.http_bridge_factory, |
766 host_, // ModelSafeWorkerRegistrar. | 775 host_, // ModelSafeWorkerRegistrar. |
767 MakeUserAgentForSyncapi().c_str(), | 776 MakeUserAgentForSyncApi().c_str(), |
768 options.credentials, | 777 options.credentials, |
769 sync_notifier_.get(), | 778 sync_notifier_.get(), |
770 options.restored_key_for_bootstrapping, | 779 options.restored_key_for_bootstrapping, |
771 options.setup_for_test_mode); | 780 options.setup_for_test_mode); |
772 DCHECK(success) << "Syncapi initialization failed!"; | 781 DCHECK(success) << "Syncapi initialization failed!"; |
773 } | 782 } |
774 | 783 |
775 void SyncBackendHost::Core::DoUpdateCredentials( | 784 void SyncBackendHost::Core::DoUpdateCredentials( |
776 const SyncCredentials& credentials) { | 785 const SyncCredentials& credentials) { |
777 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); | 786 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); |
778 syncapi_->UpdateCredentials(credentials); | 787 sync_manager_->UpdateCredentials(credentials); |
779 } | 788 } |
780 | 789 |
781 void SyncBackendHost::Core::DoUpdateEnabledTypes() { | 790 void SyncBackendHost::Core::DoUpdateEnabledTypes() { |
782 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); | 791 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); |
783 syncapi_->UpdateEnabledTypes(); | 792 sync_manager_->UpdateEnabledTypes(); |
784 } | 793 } |
785 | 794 |
786 void SyncBackendHost::Core::DoStartSyncing() { | 795 void SyncBackendHost::Core::DoStartSyncing() { |
787 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); | 796 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); |
788 syncapi_->StartSyncingNormally(); | 797 sync_manager_->StartSyncingNormally(); |
789 if (deferred_nudge_for_cleanup_requested_) | 798 if (deferred_nudge_for_cleanup_requested_) |
790 syncapi_->RequestNudge(FROM_HERE); | 799 sync_manager_->RequestNudge(FROM_HERE); |
791 deferred_nudge_for_cleanup_requested_ = false; | 800 deferred_nudge_for_cleanup_requested_ = false; |
792 } | 801 } |
793 | 802 |
794 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase, | 803 void SyncBackendHost::Core::DoSetPassphrase(const std::string& passphrase, |
795 bool is_explicit) { | 804 bool is_explicit) { |
796 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); | 805 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); |
797 syncapi_->SetPassphrase(passphrase, is_explicit); | 806 sync_manager_->SetPassphrase(passphrase, is_explicit); |
798 } | 807 } |
799 | 808 |
800 bool SyncBackendHost::Core::processing_passphrase() const { | 809 bool SyncBackendHost::Core::processing_passphrase() const { |
801 DCHECK(MessageLoop::current() == host_->frontend_loop_); | 810 DCHECK(MessageLoop::current() == host_->frontend_loop_); |
802 return processing_passphrase_; | 811 return processing_passphrase_; |
803 } | 812 } |
804 | 813 |
805 void SyncBackendHost::Core::set_processing_passphrase() { | 814 void SyncBackendHost::Core::set_processing_passphrase() { |
806 DCHECK(MessageLoop::current() == host_->frontend_loop_); | 815 DCHECK(MessageLoop::current() == host_->frontend_loop_); |
807 processing_passphrase_ = true; | 816 processing_passphrase_ = true; |
808 } | 817 } |
809 | 818 |
810 void SyncBackendHost::Core::DoEncryptDataTypes( | 819 void SyncBackendHost::Core::DoEncryptDataTypes( |
811 const syncable::ModelTypeSet& encrypted_types) { | 820 const syncable::ModelTypeSet& encrypted_types) { |
812 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); | 821 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); |
813 syncapi_->EncryptDataTypes(encrypted_types); | 822 sync_manager_->EncryptDataTypes(encrypted_types); |
814 } | 823 } |
815 | 824 |
816 void SyncBackendHost::Core::DoRequestConfig( | 825 void SyncBackendHost::Core::DoRequestConfig( |
817 const syncable::ModelTypeBitSet& added_types, | 826 const syncable::ModelTypeBitSet& added_types, |
818 sync_api::ConfigureReason reason) { | 827 sync_api::ConfigureReason reason) { |
819 syncapi_->RequestConfig(added_types, reason); | 828 sync_manager_->RequestConfig(added_types, reason); |
820 } | 829 } |
821 | 830 |
822 void SyncBackendHost::Core::DoStartConfiguration(Callback0::Type* callback) { | 831 void SyncBackendHost::Core::DoStartConfiguration(Callback0::Type* callback) { |
823 syncapi_->StartConfigurationMode(callback); | 832 sync_manager_->StartConfigurationMode(callback); |
824 } | 833 } |
825 | 834 |
826 UIModelWorker* SyncBackendHost::ui_worker() { | 835 UIModelWorker* SyncBackendHost::ui_worker() { |
827 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; | 836 ModelSafeWorker* w = registrar_.workers[GROUP_UI]; |
828 if (w == NULL) | 837 if (w == NULL) |
829 return NULL; | 838 return NULL; |
830 if (w->GetModelSafeGroup() != GROUP_UI) | 839 if (w->GetModelSafeGroup() != GROUP_UI) |
831 NOTREACHED(); | 840 NOTREACHED(); |
832 return static_cast<UIModelWorker*>(w); | 841 return static_cast<UIModelWorker*>(w); |
833 } | 842 } |
834 | 843 |
835 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 844 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
836 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); | 845 DCHECK(MessageLoop::current() == host_->sync_thread_.message_loop()); |
837 | 846 |
838 save_changes_timer_.Stop(); | 847 save_changes_timer_.Stop(); |
839 syncapi_->Shutdown(); // Stops the SyncerThread. | 848 sync_manager_->Shutdown(); // Stops the SyncerThread. |
840 syncapi_->RemoveObserver(this); | 849 sync_manager_->RemoveObserver(this); |
841 DisconnectChildJsEventRouter(); | 850 DisconnectChildJsEventRouter(); |
| 851 sync_manager_.reset(); |
842 host_->ui_worker()->OnSyncerShutdownComplete(); | 852 host_->ui_worker()->OnSyncerShutdownComplete(); |
843 | 853 |
844 if (sync_disabled) | 854 if (sync_disabled) |
845 DeleteSyncDataFolder(); | 855 DeleteSyncDataFolder(); |
846 | 856 |
847 host_ = NULL; | 857 host_ = NULL; |
848 } | 858 } |
849 | 859 |
850 ChangeProcessor* SyncBackendHost::Core::GetProcessor( | 860 ChangeProcessor* SyncBackendHost::Core::GetProcessor( |
851 syncable::ModelType model_type) { | 861 syncable::ModelType model_type) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 | 965 |
956 void SyncBackendHost::Core::OnInitializationComplete() { | 966 void SyncBackendHost::Core::OnInitializationComplete() { |
957 if (!host_ || !host_->frontend_) | 967 if (!host_ || !host_->frontend_) |
958 return; // We may have been told to Shutdown before initialization | 968 return; // We may have been told to Shutdown before initialization |
959 // completed. | 969 // completed. |
960 | 970 |
961 // We could be on some random sync backend thread, so MessageLoop::current() | 971 // We could be on some random sync backend thread, so MessageLoop::current() |
962 // can definitely be null in here. | 972 // can definitely be null in here. |
963 host_->frontend_loop_->PostTask(FROM_HERE, | 973 host_->frontend_loop_->PostTask(FROM_HERE, |
964 NewRunnableMethod(this, | 974 NewRunnableMethod(this, |
965 &Core::HandleInitalizationCompletedOnFrontendLoop)); | 975 &Core::HandleInitializationCompletedOnFrontendLoop)); |
966 | 976 |
967 // Initialization is complete, so we can schedule recurring SaveChanges. | 977 // Initialization is complete, so we can schedule recurring SaveChanges. |
968 host_->sync_thread_.message_loop()->PostTask(FROM_HERE, | 978 host_->sync_thread_.message_loop()->PostTask(FROM_HERE, |
969 NewRunnableMethod(this, &Core::StartSavingChanges)); | 979 NewRunnableMethod(this, &Core::StartSavingChanges)); |
970 } | 980 } |
971 | 981 |
972 void SyncBackendHost::Core::HandleInitalizationCompletedOnFrontendLoop() { | 982 void SyncBackendHost::Core::HandleInitializationCompletedOnFrontendLoop() { |
973 if (!host_) | 983 if (!host_) |
974 return; | 984 return; |
975 host_->HandleInitializationCompletedOnFrontendLoop(); | 985 host_->HandleInitializationCompletedOnFrontendLoop(); |
976 } | 986 } |
977 | 987 |
978 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop() { | 988 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop() { |
979 if (!frontend_) | 989 if (!frontend_) |
980 return; | 990 return; |
981 syncapi_initialized_ = true; | 991 sync_manager_initialized_ = true; |
982 // Now that the syncapi is initialized, we can update the cryptographer (and | 992 // Now that the syncapi is initialized, we can update the cryptographer (and |
983 // can handle any ON_PASSPHRASE_REQUIRED notifications that may arise). | 993 // can handle any ON_PASSPHRASE_REQUIRED notifications that may arise). |
984 core_->syncapi()->RefreshEncryption(); | 994 core_->sync_manager()->RefreshEncryption(); |
985 frontend_->OnBackendInitialized(); | 995 frontend_->OnBackendInitialized(); |
986 } | 996 } |
987 | 997 |
988 bool SyncBackendHost::Core::IsCurrentThreadSafeForModel( | 998 bool SyncBackendHost::Core::IsCurrentThreadSafeForModel( |
989 syncable::ModelType model_type) { | 999 syncable::ModelType model_type) { |
990 base::AutoLock lock(host_->registrar_lock_); | 1000 base::AutoLock lock(host_->registrar_lock_); |
991 | 1001 |
992 browser_sync::ModelSafeRoutingInfo::const_iterator routing_it = | 1002 browser_sync::ModelSafeRoutingInfo::const_iterator routing_it = |
993 host_->registrar_.routing_info.find(model_type); | 1003 host_->registrar_.routing_info.find(model_type); |
994 if (routing_it == host_->registrar_.routing_info.end()) | 1004 if (routing_it == host_->registrar_.routing_info.end()) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 } | 1126 } |
1117 | 1127 |
1118 void SyncBackendHost::Core::StartSavingChanges() { | 1128 void SyncBackendHost::Core::StartSavingChanges() { |
1119 save_changes_timer_.Start( | 1129 save_changes_timer_.Start( |
1120 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), | 1130 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), |
1121 this, &Core::SaveChanges); | 1131 this, &Core::SaveChanges); |
1122 } | 1132 } |
1123 | 1133 |
1124 void SyncBackendHost::Core::DoRequestNudge( | 1134 void SyncBackendHost::Core::DoRequestNudge( |
1125 const tracked_objects::Location& nudge_location) { | 1135 const tracked_objects::Location& nudge_location) { |
1126 syncapi_->RequestNudge(nudge_location); | 1136 sync_manager_->RequestNudge(nudge_location); |
1127 } | 1137 } |
1128 | 1138 |
1129 void SyncBackendHost::Core::DoRequestClearServerData() { | 1139 void SyncBackendHost::Core::DoRequestClearServerData() { |
1130 syncapi_->RequestClearServerData(); | 1140 sync_manager_->RequestClearServerData(); |
1131 } | 1141 } |
1132 | 1142 |
1133 void SyncBackendHost::Core::SaveChanges() { | 1143 void SyncBackendHost::Core::SaveChanges() { |
1134 syncapi_->SaveChanges(); | 1144 sync_manager_->SaveChanges(); |
1135 } | 1145 } |
1136 | 1146 |
1137 void SyncBackendHost::Core::DeleteSyncDataFolder() { | 1147 void SyncBackendHost::Core::DeleteSyncDataFolder() { |
1138 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { | 1148 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { |
1139 if (!file_util::Delete(host_->sync_data_folder_path(), true)) | 1149 if (!file_util::Delete(host_->sync_data_folder_path(), true)) |
1140 LOG(DFATAL) << "Could not delete the Sync Data folder."; | 1150 LOG(DFATAL) << "Could not delete the Sync Data folder."; |
1141 } | 1151 } |
1142 } | 1152 } |
1143 | 1153 |
1144 void SyncBackendHost::Core::SetParentJsEventRouter(JsEventRouter* router) { | 1154 void SyncBackendHost::Core::SetParentJsEventRouter(JsEventRouter* router) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 FROM_HERE, | 1189 FROM_HERE, |
1180 NewRunnableMethod(this, | 1190 NewRunnableMethod(this, |
1181 &SyncBackendHost::Core::DoProcessMessage, | 1191 &SyncBackendHost::Core::DoProcessMessage, |
1182 name, args, sender)); | 1192 name, args, sender)); |
1183 } | 1193 } |
1184 | 1194 |
1185 void SyncBackendHost::Core::ConnectChildJsEventRouter() { | 1195 void SyncBackendHost::Core::ConnectChildJsEventRouter() { |
1186 DCHECK_EQ(MessageLoop::current(), host_->sync_thread_.message_loop()); | 1196 DCHECK_EQ(MessageLoop::current(), host_->sync_thread_.message_loop()); |
1187 // We need this check since AddObserver() can be called at most once | 1197 // We need this check since AddObserver() can be called at most once |
1188 // for a given observer. | 1198 // for a given observer. |
1189 if (!syncapi_->GetJsBackend()->GetParentJsEventRouter()) { | 1199 if (!sync_manager_->GetJsBackend()->GetParentJsEventRouter()) { |
1190 syncapi_->GetJsBackend()->SetParentJsEventRouter(this); | 1200 sync_manager_->GetJsBackend()->SetParentJsEventRouter(this); |
1191 syncapi_->AddObserver(&sync_manager_observer_); | 1201 sync_manager_->AddObserver(&sync_manager_observer_); |
1192 } | 1202 } |
1193 } | 1203 } |
1194 | 1204 |
1195 void SyncBackendHost::Core::DisconnectChildJsEventRouter() { | 1205 void SyncBackendHost::Core::DisconnectChildJsEventRouter() { |
1196 DCHECK_EQ(MessageLoop::current(), host_->sync_thread_.message_loop()); | 1206 DCHECK_EQ(MessageLoop::current(), host_->sync_thread_.message_loop()); |
1197 syncapi_->GetJsBackend()->RemoveParentJsEventRouter(); | 1207 sync_manager_->GetJsBackend()->RemoveParentJsEventRouter(); |
1198 syncapi_->RemoveObserver(&sync_manager_observer_); | 1208 sync_manager_->RemoveObserver(&sync_manager_observer_); |
1199 } | 1209 } |
1200 | 1210 |
1201 void SyncBackendHost::Core::DoProcessMessage( | 1211 void SyncBackendHost::Core::DoProcessMessage( |
1202 const std::string& name, const JsArgList& args, | 1212 const std::string& name, const JsArgList& args, |
1203 const JsEventHandler* sender) { | 1213 const JsEventHandler* sender) { |
1204 DCHECK_EQ(MessageLoop::current(), host_->sync_thread_.message_loop()); | 1214 DCHECK_EQ(MessageLoop::current(), host_->sync_thread_.message_loop()); |
1205 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); | 1215 sync_manager_->GetJsBackend()->ProcessMessage(name, args, sender); |
1206 } | 1216 } |
1207 | 1217 |
1208 void SyncBackendHost::Core::DeferNudgeForCleanup() { | 1218 void SyncBackendHost::Core::DeferNudgeForCleanup() { |
1209 DCHECK_EQ(MessageLoop::current(), host_->sync_thread_.message_loop()); | 1219 DCHECK_EQ(MessageLoop::current(), host_->sync_thread_.message_loop()); |
1210 deferred_nudge_for_cleanup_requested_ = true; | 1220 deferred_nudge_for_cleanup_requested_ = true; |
1211 } | 1221 } |
1212 | 1222 |
1213 } // namespace browser_sync | 1223 } // namespace browser_sync |
OLD | NEW |