OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "sync/internal_api/public/util/experiments.h" | 33 #include "sync/internal_api/public/util/experiments.h" |
34 #include "sync/internal_api/public/write_node.h" | 34 #include "sync/internal_api/public/write_node.h" |
35 #include "sync/internal_api/public/write_transaction.h" | 35 #include "sync/internal_api/public/write_transaction.h" |
36 #include "sync/internal_api/syncapi_internal.h" | 36 #include "sync/internal_api/syncapi_internal.h" |
37 #include "sync/internal_api/syncapi_server_connection_manager.h" | 37 #include "sync/internal_api/syncapi_server_connection_manager.h" |
38 #include "sync/js/js_arg_list.h" | 38 #include "sync/js/js_arg_list.h" |
39 #include "sync/js/js_event_details.h" | 39 #include "sync/js/js_event_details.h" |
40 #include "sync/js/js_event_handler.h" | 40 #include "sync/js/js_event_handler.h" |
41 #include "sync/js/js_reply_handler.h" | 41 #include "sync/js/js_reply_handler.h" |
42 #include "sync/notifier/invalidation_util.h" | 42 #include "sync/notifier/invalidation_util.h" |
43 #include "sync/notifier/sync_notifier.h" | 43 #include "sync/notifier/invalidator.h" |
44 #include "sync/protocol/proto_value_conversions.h" | 44 #include "sync/protocol/proto_value_conversions.h" |
45 #include "sync/protocol/sync.pb.h" | 45 #include "sync/protocol/sync.pb.h" |
46 #include "sync/syncable/directory.h" | 46 #include "sync/syncable/directory.h" |
47 #include "sync/syncable/entry.h" | 47 #include "sync/syncable/entry.h" |
48 #include "sync/syncable/in_memory_directory_backing_store.h" | 48 #include "sync/syncable/in_memory_directory_backing_store.h" |
49 #include "sync/syncable/on_disk_directory_backing_store.h" | 49 #include "sync/syncable/on_disk_directory_backing_store.h" |
50 #include "sync/util/get_session_name.h" | 50 #include "sync/util/get_session_name.h" |
51 | 51 |
52 using base::TimeDelta; | 52 using base::TimeDelta; |
53 using sync_pb::GetUpdatesCallerInfo; | 53 using sync_pb::GetUpdatesCallerInfo; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 const WeakHandle<JsEventHandler>& event_handler, | 342 const WeakHandle<JsEventHandler>& event_handler, |
343 const std::string& sync_server_and_path, | 343 const std::string& sync_server_and_path, |
344 int port, | 344 int port, |
345 bool use_ssl, | 345 bool use_ssl, |
346 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 346 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
347 scoped_ptr<HttpPostProviderFactory> post_factory, | 347 scoped_ptr<HttpPostProviderFactory> post_factory, |
348 const std::vector<ModelSafeWorker*>& workers, | 348 const std::vector<ModelSafeWorker*>& workers, |
349 ExtensionsActivityMonitor* extensions_activity_monitor, | 349 ExtensionsActivityMonitor* extensions_activity_monitor, |
350 SyncManager::ChangeDelegate* change_delegate, | 350 SyncManager::ChangeDelegate* change_delegate, |
351 const SyncCredentials& credentials, | 351 const SyncCredentials& credentials, |
352 scoped_ptr<SyncNotifier> sync_notifier, | 352 scoped_ptr<Invalidator> invalidator, |
353 const std::string& restored_key_for_bootstrapping, | 353 const std::string& restored_key_for_bootstrapping, |
354 const std::string& restored_keystore_key_for_bootstrapping, | 354 const std::string& restored_keystore_key_for_bootstrapping, |
355 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 355 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
356 Encryptor* encryptor, | 356 Encryptor* encryptor, |
357 UnrecoverableErrorHandler* unrecoverable_error_handler, | 357 UnrecoverableErrorHandler* unrecoverable_error_handler, |
358 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 358 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
359 CHECK(!initialized_); | 359 CHECK(!initialized_); |
360 DCHECK(thread_checker_.CalledOnValidThread()); | 360 DCHECK(thread_checker_.CalledOnValidThread()); |
361 DCHECK(post_factory.get()); | 361 DCHECK(post_factory.get()); |
362 DCHECK(!credentials.email.empty()); | 362 DCHECK(!credentials.email.empty()); |
363 DCHECK(!credentials.sync_token.empty()); | 363 DCHECK(!credentials.sync_token.empty()); |
364 DVLOG(1) << "SyncManager starting Init..."; | 364 DVLOG(1) << "SyncManager starting Init..."; |
365 | 365 |
366 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); | 366 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); |
367 | 367 |
368 blocking_task_runner_ = blocking_task_runner; | 368 blocking_task_runner_ = blocking_task_runner; |
369 | 369 |
370 change_delegate_ = change_delegate; | 370 change_delegate_ = change_delegate; |
371 | 371 |
372 sync_notifier_ = sync_notifier.Pass(); | 372 invalidator_ = invalidator.Pass(); |
373 sync_notifier_->RegisterHandler(this); | 373 invalidator_->RegisterHandler(this); |
374 | 374 |
375 AddObserver(&js_sync_manager_observer_); | 375 AddObserver(&js_sync_manager_observer_); |
376 SetJsEventHandler(event_handler); | 376 SetJsEventHandler(event_handler); |
377 | 377 |
378 AddObserver(&debug_info_event_listener_); | 378 AddObserver(&debug_info_event_listener_); |
379 | 379 |
380 database_path_ = database_location.Append( | 380 database_path_ = database_location.Append( |
381 syncable::Directory::kSyncDatabaseFilename); | 381 syncable::Directory::kSyncDatabaseFilename); |
382 encryptor_ = encryptor; | 382 encryptor_ = encryptor; |
383 unrecoverable_error_handler_ = unrecoverable_error_handler; | 383 unrecoverable_error_handler_ = unrecoverable_error_handler; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 418 |
419 connection_manager_.reset(new SyncAPIServerConnectionManager( | 419 connection_manager_.reset(new SyncAPIServerConnectionManager( |
420 sync_server_and_path, port, use_ssl, post_factory.release())); | 420 sync_server_and_path, port, use_ssl, post_factory.release())); |
421 connection_manager_->set_client_id(directory()->cache_guid()); | 421 connection_manager_->set_client_id(directory()->cache_guid()); |
422 connection_manager_->AddListener(this); | 422 connection_manager_->AddListener(this); |
423 | 423 |
424 // Retrieve and set the sync notifier state. | 424 // Retrieve and set the sync notifier state. |
425 std::string unique_id = directory()->cache_guid(); | 425 std::string unique_id = directory()->cache_guid(); |
426 DVLOG(1) << "Read notification unique ID: " << unique_id; | 426 DVLOG(1) << "Read notification unique ID: " << unique_id; |
427 allstatus_.SetUniqueId(unique_id); | 427 allstatus_.SetUniqueId(unique_id); |
428 sync_notifier_->SetUniqueId(unique_id); | 428 invalidator_->SetUniqueId(unique_id); |
429 | 429 |
430 std::string state = directory()->GetNotificationState(); | 430 std::string state = directory()->GetNotificationState(); |
431 if (VLOG_IS_ON(1)) { | 431 if (VLOG_IS_ON(1)) { |
432 std::string encoded_state; | 432 std::string encoded_state; |
433 base::Base64Encode(state, &encoded_state); | 433 base::Base64Encode(state, &encoded_state); |
434 DVLOG(1) << "Read notification state: " << encoded_state; | 434 DVLOG(1) << "Read notification state: " << encoded_state; |
435 } | 435 } |
436 | 436 |
437 // TODO(tim): Remove once invalidation state has been migrated to new | 437 // TODO(tim): Remove once invalidation state has been migrated to new |
438 // InvalidationStateTracker store. Bug 124140. | 438 // InvalidationStateTracker store. Bug 124140. |
439 sync_notifier_->SetStateDeprecated(state); | 439 invalidator_->SetStateDeprecated(state); |
440 | 440 |
441 // Build a SyncSessionContext and store the worker in it. | 441 // Build a SyncSessionContext and store the worker in it. |
442 DVLOG(1) << "Sync is bringing up SyncSessionContext."; | 442 DVLOG(1) << "Sync is bringing up SyncSessionContext."; |
443 std::vector<SyncEngineEventListener*> listeners; | 443 std::vector<SyncEngineEventListener*> listeners; |
444 listeners.push_back(&allstatus_); | 444 listeners.push_back(&allstatus_); |
445 listeners.push_back(this); | 445 listeners.push_back(this); |
446 session_context_ = internal_components_factory->BuildContext( | 446 session_context_ = internal_components_factory->BuildContext( |
447 connection_manager_.get(), | 447 connection_manager_.get(), |
448 directory(), | 448 directory(), |
449 workers, | 449 workers, |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 DCHECK(thread_checker_.CalledOnValidThread()); | 646 DCHECK(thread_checker_.CalledOnValidThread()); |
647 DCHECK(initialized_); | 647 DCHECK(initialized_); |
648 DCHECK_EQ(credentials.email, share_.name); | 648 DCHECK_EQ(credentials.email, share_.name); |
649 DCHECK(!credentials.email.empty()); | 649 DCHECK(!credentials.email.empty()); |
650 DCHECK(!credentials.sync_token.empty()); | 650 DCHECK(!credentials.sync_token.empty()); |
651 | 651 |
652 observing_ip_address_changes_ = true; | 652 observing_ip_address_changes_ = true; |
653 if (!connection_manager_->set_auth_token(credentials.sync_token)) | 653 if (!connection_manager_->set_auth_token(credentials.sync_token)) |
654 return; // Auth token is known to be invalid, so exit early. | 654 return; // Auth token is known to be invalid, so exit early. |
655 | 655 |
656 sync_notifier_->UpdateCredentials(credentials.email, credentials.sync_token); | 656 invalidator_->UpdateCredentials(credentials.email, credentials.sync_token); |
657 scheduler_->OnCredentialsUpdated(); | 657 scheduler_->OnCredentialsUpdated(); |
658 } | 658 } |
659 | 659 |
660 void SyncManagerImpl::UpdateEnabledTypes( | 660 void SyncManagerImpl::UpdateEnabledTypes( |
661 const ModelTypeSet& enabled_types) { | 661 const ModelTypeSet& enabled_types) { |
662 DCHECK(thread_checker_.CalledOnValidThread()); | 662 DCHECK(thread_checker_.CalledOnValidThread()); |
663 DCHECK(initialized_); | 663 DCHECK(initialized_); |
664 sync_notifier_->UpdateRegisteredIds( | 664 invalidator_->UpdateRegisteredIds( |
665 this, | 665 this, |
666 ModelTypeSetToObjectIdSet(enabled_types)); | 666 ModelTypeSetToObjectIdSet(enabled_types)); |
667 } | 667 } |
668 | 668 |
669 void SyncManagerImpl::RegisterInvalidationHandler( | 669 void SyncManagerImpl::RegisterInvalidationHandler( |
670 SyncNotifierObserver* handler) { | 670 InvalidationHandler* handler) { |
671 DCHECK(thread_checker_.CalledOnValidThread()); | 671 DCHECK(thread_checker_.CalledOnValidThread()); |
672 DCHECK(initialized_); | 672 DCHECK(initialized_); |
673 sync_notifier_->RegisterHandler(handler); | 673 invalidator_->RegisterHandler(handler); |
674 } | 674 } |
675 | 675 |
676 void SyncManagerImpl::UpdateRegisteredInvalidationIds( | 676 void SyncManagerImpl::UpdateRegisteredInvalidationIds( |
677 SyncNotifierObserver* handler, | 677 InvalidationHandler* handler, |
678 const ObjectIdSet& ids) { | 678 const ObjectIdSet& ids) { |
679 DCHECK(thread_checker_.CalledOnValidThread()); | 679 DCHECK(thread_checker_.CalledOnValidThread()); |
680 DCHECK(initialized_); | 680 DCHECK(initialized_); |
681 sync_notifier_->UpdateRegisteredIds(handler, ids); | 681 invalidator_->UpdateRegisteredIds(handler, ids); |
682 } | 682 } |
683 | 683 |
684 void SyncManagerImpl::UnregisterInvalidationHandler( | 684 void SyncManagerImpl::UnregisterInvalidationHandler( |
685 SyncNotifierObserver* handler) { | 685 InvalidationHandler* handler) { |
686 DCHECK(thread_checker_.CalledOnValidThread()); | 686 DCHECK(thread_checker_.CalledOnValidThread()); |
687 DCHECK(initialized_); | 687 DCHECK(initialized_); |
688 sync_notifier_->UnregisterHandler(handler); | 688 invalidator_->UnregisterHandler(handler); |
689 } | 689 } |
690 | 690 |
691 bool SyncManagerImpl::GetKeystoreKeyBootstrapToken(std::string* token) { | 691 bool SyncManagerImpl::GetKeystoreKeyBootstrapToken(std::string* token) { |
692 ReadTransaction trans(FROM_HERE, GetUserShare()); | 692 ReadTransaction trans(FROM_HERE, GetUserShare()); |
693 return trans.GetCryptographer()->GetKeystoreKeyBootstrapToken(token); | 693 return trans.GetCryptographer()->GetKeystoreKeyBootstrapToken(token); |
694 } | 694 } |
695 | 695 |
696 void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) { | 696 void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) { |
697 DCHECK(thread_checker_.CalledOnValidThread()); | 697 DCHECK(thread_checker_.CalledOnValidThread()); |
698 observers_.AddObserver(observer); | 698 observers_.AddObserver(observer); |
(...skipping 25 matching lines...) Expand all Loading... |
724 if (sync_encryption_handler_.get()) { | 724 if (sync_encryption_handler_.get()) { |
725 sync_encryption_handler_->RemoveObserver(&debug_info_event_listener_); | 725 sync_encryption_handler_->RemoveObserver(&debug_info_event_listener_); |
726 sync_encryption_handler_->RemoveObserver(this); | 726 sync_encryption_handler_->RemoveObserver(this); |
727 } | 727 } |
728 | 728 |
729 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 729 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
730 RemoveObserver(&js_sync_manager_observer_); | 730 RemoveObserver(&js_sync_manager_observer_); |
731 | 731 |
732 RemoveObserver(&debug_info_event_listener_); | 732 RemoveObserver(&debug_info_event_listener_); |
733 | 733 |
734 // |sync_notifier_| and |connection_manager_| may end up being NULL here in | 734 // |invalidator_| and |connection_manager_| may end up being NULL here in |
735 // tests (in synchronous initialization mode). | 735 // tests (in synchronous initialization mode). |
736 // | 736 // |
737 // TODO(akalin): Fix this behavior. | 737 // TODO(akalin): Fix this behavior. |
738 | 738 |
739 if (sync_notifier_.get()) | 739 if (invalidator_.get()) |
740 sync_notifier_->UnregisterHandler(this); | 740 invalidator_->UnregisterHandler(this); |
741 sync_notifier_.reset(); | 741 invalidator_.reset(); |
742 | 742 |
743 if (connection_manager_.get()) | 743 if (connection_manager_.get()) |
744 connection_manager_->RemoveListener(this); | 744 connection_manager_->RemoveListener(this); |
745 connection_manager_.reset(); | 745 connection_manager_.reset(); |
746 | 746 |
747 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 747 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
748 observing_ip_address_changes_ = false; | 748 observing_ip_address_changes_ = false; |
749 | 749 |
750 if (initialized_ && directory()) { | 750 if (initialized_ && directory()) { |
751 directory()->SaveChanges(); | 751 directory()->SaveChanges(); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 OnSyncCycleCompleted(event.snapshot)); | 1012 OnSyncCycleCompleted(event.snapshot)); |
1013 } | 1013 } |
1014 | 1014 |
1015 // This is here for tests, which are still using p2p notifications. | 1015 // This is here for tests, which are still using p2p notifications. |
1016 // | 1016 // |
1017 // TODO(chron): Consider changing this back to track has_more_to_sync | 1017 // TODO(chron): Consider changing this back to track has_more_to_sync |
1018 // only notify peers if a successful commit has occurred. | 1018 // only notify peers if a successful commit has occurred. |
1019 bool is_notifiable_commit = | 1019 bool is_notifiable_commit = |
1020 (event.snapshot.model_neutral_state().num_successful_commits > 0); | 1020 (event.snapshot.model_neutral_state().num_successful_commits > 0); |
1021 if (is_notifiable_commit) { | 1021 if (is_notifiable_commit) { |
1022 if (sync_notifier_.get()) { | 1022 if (invalidator_.get()) { |
1023 const ModelTypeSet changed_types = | 1023 const ModelTypeSet changed_types = |
1024 ModelTypeStateMapToSet(event.snapshot.source().types); | 1024 ModelTypeStateMapToSet(event.snapshot.source().types); |
1025 sync_notifier_->SendNotification(changed_types); | 1025 invalidator_->SendNotification(changed_types); |
1026 } else { | 1026 } else { |
1027 DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; | 1027 DVLOG(1) << "Not sending notification: invalidator_ is NULL"; |
1028 } | 1028 } |
1029 } | 1029 } |
1030 } | 1030 } |
1031 | 1031 |
1032 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { | 1032 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { |
1033 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1033 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
1034 OnStopSyncingPermanently()); | 1034 OnStopSyncingPermanently()); |
1035 return; | 1035 return; |
1036 } | 1036 } |
1037 | 1037 |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1368 int SyncManagerImpl::GetDefaultNudgeDelay() { |
1369 return kDefaultNudgeDelayMilliseconds; | 1369 return kDefaultNudgeDelayMilliseconds; |
1370 } | 1370 } |
1371 | 1371 |
1372 // static. | 1372 // static. |
1373 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1373 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
1374 return kPreferencesNudgeDelayMilliseconds; | 1374 return kPreferencesNudgeDelayMilliseconds; |
1375 } | 1375 } |
1376 | 1376 |
1377 } // namespace syncer | 1377 } // namespace syncer |
OLD | NEW |