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 21 matching lines...) Expand all Loading... |
32 #include "sync/internal_api/public/user_share.h" | 32 #include "sync/internal_api/public/user_share.h" |
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/notifications_disabled_reason.h" | 43 #include "sync/notifier/notifications_disabled_reason.h" |
43 #include "sync/notifier/sync_notifier.h" | 44 #include "sync/notifier/sync_notifier.h" |
44 #include "sync/protocol/encryption.pb.h" | 45 #include "sync/protocol/encryption.pb.h" |
45 #include "sync/protocol/proto_value_conversions.h" | 46 #include "sync/protocol/proto_value_conversions.h" |
46 #include "sync/protocol/sync.pb.h" | 47 #include "sync/protocol/sync.pb.h" |
47 #include "sync/syncable/directory.h" | 48 #include "sync/syncable/directory.h" |
48 #include "sync/syncable/entry.h" | 49 #include "sync/syncable/entry.h" |
49 #include "sync/syncable/in_memory_directory_backing_store.h" | 50 #include "sync/syncable/in_memory_directory_backing_store.h" |
50 #include "sync/syncable/nigori_util.h" | 51 #include "sync/syncable/nigori_util.h" |
51 #include "sync/syncable/on_disk_directory_backing_store.h" | 52 #include "sync/syncable/on_disk_directory_backing_store.h" |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 // post a task to shutdown sync. But if this function posts any other tasks | 480 // post a task to shutdown sync. But if this function posts any other tasks |
480 // on the UI thread and if shutdown wins then that tasks would execute on | 481 // on the UI thread and if shutdown wins then that tasks would execute on |
481 // a freed pointer. This is because UI thread is not shut down. | 482 // a freed pointer. This is because UI thread is not shut down. |
482 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 483 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
483 OnInitializationComplete( | 484 OnInitializationComplete( |
484 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 485 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
485 success)); | 486 success)); |
486 if (!success) | 487 if (!success) |
487 return false; | 488 return false; |
488 | 489 |
489 sync_notifier_->AddObserver(this); | |
490 | |
491 return success; | 490 return success; |
492 } | 491 } |
493 | 492 |
494 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, | 493 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, |
495 const base::Closure& done_callback) { | 494 const base::Closure& done_callback) { |
496 DCHECK(initialized_); | 495 DCHECK(initialized_); |
497 DCHECK(thread_checker_.CalledOnValidThread()); | 496 DCHECK(thread_checker_.CalledOnValidThread()); |
498 GetSessionName( | 497 GetSessionName( |
499 blocking_task_runner_, | 498 blocking_task_runner_, |
500 base::Bind( | 499 base::Bind( |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 credentials.email, credentials.sync_token); | 722 credentials.email, credentials.sync_token); |
724 if (initialized_) { | 723 if (initialized_) { |
725 scheduler_->OnCredentialsUpdated(); | 724 scheduler_->OnCredentialsUpdated(); |
726 } | 725 } |
727 } | 726 } |
728 } | 727 } |
729 | 728 |
730 void SyncManagerImpl::UpdateEnabledTypes( | 729 void SyncManagerImpl::UpdateEnabledTypes( |
731 const ModelTypeSet& enabled_types) { | 730 const ModelTypeSet& enabled_types) { |
732 DCHECK(thread_checker_.CalledOnValidThread()); | 731 DCHECK(thread_checker_.CalledOnValidThread()); |
733 sync_notifier_->UpdateEnabledTypes(enabled_types); | 732 sync_notifier_->UpdateRegisteredIds(this, |
| 733 ModelTypeSetToObjectIdSet(enabled_types)); |
734 } | 734 } |
735 | 735 |
736 void SyncManagerImpl::SetEncryptionPassphrase( | 736 void SyncManagerImpl::SetEncryptionPassphrase( |
737 const std::string& passphrase, | 737 const std::string& passphrase, |
738 bool is_explicit) { | 738 bool is_explicit) { |
739 DCHECK(thread_checker_.CalledOnValidThread()); | 739 DCHECK(thread_checker_.CalledOnValidThread()); |
740 // We do not accept empty passphrases. | 740 // We do not accept empty passphrases. |
741 if (passphrase.empty()) { | 741 if (passphrase.empty()) { |
742 NOTREACHED() << "Cannot encrypt with an empty passphrase."; | 742 NOTREACHED() << "Cannot encrypt with an empty passphrase."; |
743 return; | 743 return; |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 | 1193 |
1194 scheduler_.reset(); | 1194 scheduler_.reset(); |
1195 session_context_.reset(); | 1195 session_context_.reset(); |
1196 | 1196 |
1197 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1197 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
1198 RemoveObserver(&js_sync_manager_observer_); | 1198 RemoveObserver(&js_sync_manager_observer_); |
1199 | 1199 |
1200 RemoveObserver(&debug_info_event_listener_); | 1200 RemoveObserver(&debug_info_event_listener_); |
1201 | 1201 |
1202 if (sync_notifier_.get()) { | 1202 if (sync_notifier_.get()) { |
1203 sync_notifier_->RemoveObserver(this); | 1203 sync_notifier_->UpdateRegisteredIds(this, ObjectIdSet()); |
1204 } | 1204 } |
1205 sync_notifier_.reset(); | 1205 sync_notifier_.reset(); |
1206 | 1206 |
1207 if (connection_manager_.get()) { | 1207 if (connection_manager_.get()) { |
1208 connection_manager_->RemoveListener(this); | 1208 connection_manager_->RemoveListener(this); |
1209 } | 1209 } |
1210 connection_manager_.reset(); | 1210 connection_manager_.reset(); |
1211 | 1211 |
1212 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1212 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
1213 observing_ip_address_changes_ = false; | 1213 observing_ip_address_changes_ = false; |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1779 js_event_handler_.Call(FROM_HERE, | 1779 js_event_handler_.Call(FROM_HERE, |
1780 &JsEventHandler::HandleJsEvent, | 1780 &JsEventHandler::HandleJsEvent, |
1781 "onNotificationStateChange", | 1781 "onNotificationStateChange", |
1782 JsEventDetails(&details)); | 1782 JsEventDetails(&details)); |
1783 } | 1783 } |
1784 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth | 1784 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
1785 // error. | 1785 // error. |
1786 } | 1786 } |
1787 | 1787 |
1788 void SyncManagerImpl::OnIncomingNotification( | 1788 void SyncManagerImpl::OnIncomingNotification( |
1789 const ModelTypePayloadMap& type_payloads, | 1789 const ObjectIdPayloadMap& id_payloads, |
1790 IncomingNotificationSource source) { | 1790 IncomingNotificationSource source) { |
1791 DCHECK(thread_checker_.CalledOnValidThread()); | 1791 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1792 const ModelTypePayloadMap& type_payloads = |
| 1793 ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); |
1792 if (source == LOCAL_NOTIFICATION) { | 1794 if (source == LOCAL_NOTIFICATION) { |
1793 scheduler_->ScheduleNudgeWithPayloadsAsync( | 1795 scheduler_->ScheduleNudgeWithPayloadsAsync( |
1794 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 1796 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
1795 NUDGE_SOURCE_LOCAL_REFRESH, | 1797 NUDGE_SOURCE_LOCAL_REFRESH, |
1796 type_payloads, FROM_HERE); | 1798 type_payloads, FROM_HERE); |
1797 } else if (!type_payloads.empty()) { | 1799 } else if (!type_payloads.empty()) { |
1798 scheduler_->ScheduleNudgeWithPayloadsAsync( | 1800 scheduler_->ScheduleNudgeWithPayloadsAsync( |
1799 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), | 1801 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), |
1800 NUDGE_SOURCE_NOTIFICATION, | 1802 NUDGE_SOURCE_NOTIFICATION, |
1801 type_payloads, FROM_HERE); | 1803 type_payloads, FROM_HERE); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1873 } | 1875 } |
1874 | 1876 |
1875 void SyncManagerImpl::SimulateDisableNotificationsForTest(int reason) { | 1877 void SyncManagerImpl::SimulateDisableNotificationsForTest(int reason) { |
1876 DCHECK(thread_checker_.CalledOnValidThread()); | 1878 DCHECK(thread_checker_.CalledOnValidThread()); |
1877 OnNotificationsDisabled(static_cast<NotificationsDisabledReason>(reason)); | 1879 OnNotificationsDisabled(static_cast<NotificationsDisabledReason>(reason)); |
1878 } | 1880 } |
1879 | 1881 |
1880 void SyncManagerImpl::TriggerOnIncomingNotificationForTest( | 1882 void SyncManagerImpl::TriggerOnIncomingNotificationForTest( |
1881 ModelTypeSet model_types) { | 1883 ModelTypeSet model_types) { |
1882 DCHECK(thread_checker_.CalledOnValidThread()); | 1884 DCHECK(thread_checker_.CalledOnValidThread()); |
1883 ModelTypePayloadMap model_types_with_payloads = | 1885 const ModelTypePayloadMap& type_payloads = |
1884 ModelTypePayloadMapFromEnumSet(model_types, | 1886 ModelTypePayloadMapFromEnumSet(model_types, std::string()); |
1885 std::string()); | |
1886 | 1887 |
1887 OnIncomingNotification(model_types_with_payloads, REMOTE_NOTIFICATION); | 1888 OnIncomingNotification(ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), |
| 1889 REMOTE_NOTIFICATION); |
1888 } | 1890 } |
1889 | 1891 |
1890 // static. | 1892 // static. |
1891 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1893 int SyncManagerImpl::GetDefaultNudgeDelay() { |
1892 return kDefaultNudgeDelayMilliseconds; | 1894 return kDefaultNudgeDelayMilliseconds; |
1893 } | 1895 } |
1894 | 1896 |
1895 // static. | 1897 // static. |
1896 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1898 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
1897 return kPreferencesNudgeDelayMilliseconds; | 1899 return kPreferencesNudgeDelayMilliseconds; |
1898 } | 1900 } |
1899 | 1901 |
1900 } // namespace syncer | 1902 } // namespace syncer |
OLD | NEW |