| 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 // post a task to shutdown sync. But if this function posts any other tasks | 475 // post a task to shutdown sync. But if this function posts any other tasks |
| 475 // on the UI thread and if shutdown wins then that tasks would execute on | 476 // on the UI thread and if shutdown wins then that tasks would execute on |
| 476 // a freed pointer. This is because UI thread is not shut down. | 477 // a freed pointer. This is because UI thread is not shut down. |
| 477 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 478 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 478 OnInitializationComplete( | 479 OnInitializationComplete( |
| 479 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 480 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
| 480 success)); | 481 success)); |
| 481 if (!success) | 482 if (!success) |
| 482 return false; | 483 return false; |
| 483 | 484 |
| 484 sync_notifier_->AddObserver(this); | |
| 485 | |
| 486 return success; | 485 return success; |
| 487 } | 486 } |
| 488 | 487 |
| 489 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, | 488 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, |
| 490 const base::Closure& done_callback) { | 489 const base::Closure& done_callback) { |
| 491 DCHECK(initialized_); | 490 DCHECK(initialized_); |
| 492 DCHECK(thread_checker_.CalledOnValidThread()); | 491 DCHECK(thread_checker_.CalledOnValidThread()); |
| 493 GetSessionName( | 492 GetSessionName( |
| 494 blocking_task_runner_, | 493 blocking_task_runner_, |
| 495 base::Bind( | 494 base::Bind( |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 credentials.email, credentials.sync_token); | 717 credentials.email, credentials.sync_token); |
| 719 if (initialized_) { | 718 if (initialized_) { |
| 720 scheduler_->OnCredentialsUpdated(); | 719 scheduler_->OnCredentialsUpdated(); |
| 721 } | 720 } |
| 722 } | 721 } |
| 723 } | 722 } |
| 724 | 723 |
| 725 void SyncManagerImpl::UpdateEnabledTypes( | 724 void SyncManagerImpl::UpdateEnabledTypes( |
| 726 const ModelTypeSet& enabled_types) { | 725 const ModelTypeSet& enabled_types) { |
| 727 DCHECK(thread_checker_.CalledOnValidThread()); | 726 DCHECK(thread_checker_.CalledOnValidThread()); |
| 728 sync_notifier_->UpdateEnabledTypes(enabled_types); | 727 sync_notifier_->UpdateRegisteredIds(this, |
| 728 ModelTypeSetToObjectIdSet(enabled_types)); |
| 729 } | 729 } |
| 730 | 730 |
| 731 void SyncManagerImpl::SetEncryptionPassphrase( | 731 void SyncManagerImpl::SetEncryptionPassphrase( |
| 732 const std::string& passphrase, | 732 const std::string& passphrase, |
| 733 bool is_explicit) { | 733 bool is_explicit) { |
| 734 DCHECK(thread_checker_.CalledOnValidThread()); | 734 DCHECK(thread_checker_.CalledOnValidThread()); |
| 735 // We do not accept empty passphrases. | 735 // We do not accept empty passphrases. |
| 736 if (passphrase.empty()) { | 736 if (passphrase.empty()) { |
| 737 NOTREACHED() << "Cannot encrypt with an empty passphrase."; | 737 NOTREACHED() << "Cannot encrypt with an empty passphrase."; |
| 738 return; | 738 return; |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 | 1188 |
| 1189 scheduler_.reset(); | 1189 scheduler_.reset(); |
| 1190 session_context_.reset(); | 1190 session_context_.reset(); |
| 1191 | 1191 |
| 1192 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1192 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
| 1193 RemoveObserver(&js_sync_manager_observer_); | 1193 RemoveObserver(&js_sync_manager_observer_); |
| 1194 | 1194 |
| 1195 RemoveObserver(&debug_info_event_listener_); | 1195 RemoveObserver(&debug_info_event_listener_); |
| 1196 | 1196 |
| 1197 if (sync_notifier_.get()) { | 1197 if (sync_notifier_.get()) { |
| 1198 sync_notifier_->RemoveObserver(this); | 1198 sync_notifier_->UpdateRegisteredIds(this, ObjectIdSet()); |
| 1199 } | 1199 } |
| 1200 sync_notifier_.reset(); | 1200 sync_notifier_.reset(); |
| 1201 | 1201 |
| 1202 if (connection_manager_.get()) { | 1202 if (connection_manager_.get()) { |
| 1203 connection_manager_->RemoveListener(this); | 1203 connection_manager_->RemoveListener(this); |
| 1204 } | 1204 } |
| 1205 connection_manager_.reset(); | 1205 connection_manager_.reset(); |
| 1206 | 1206 |
| 1207 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1207 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1208 observing_ip_address_changes_ = false; | 1208 observing_ip_address_changes_ = false; |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1774 js_event_handler_.Call(FROM_HERE, | 1774 js_event_handler_.Call(FROM_HERE, |
| 1775 &JsEventHandler::HandleJsEvent, | 1775 &JsEventHandler::HandleJsEvent, |
| 1776 "onNotificationStateChange", | 1776 "onNotificationStateChange", |
| 1777 JsEventDetails(&details)); | 1777 JsEventDetails(&details)); |
| 1778 } | 1778 } |
| 1779 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth | 1779 // TODO(akalin): Treat a CREDENTIALS_REJECTED state as an auth |
| 1780 // error. | 1780 // error. |
| 1781 } | 1781 } |
| 1782 | 1782 |
| 1783 void SyncManagerImpl::OnIncomingNotification( | 1783 void SyncManagerImpl::OnIncomingNotification( |
| 1784 const ModelTypePayloadMap& type_payloads, | 1784 const ObjectIdPayloadMap& id_payloads, |
| 1785 IncomingNotificationSource source) { | 1785 IncomingNotificationSource source) { |
| 1786 DCHECK(thread_checker_.CalledOnValidThread()); | 1786 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1787 const ModelTypePayloadMap& type_payloads = |
| 1788 ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); |
| 1787 if (source == LOCAL_NOTIFICATION) { | 1789 if (source == LOCAL_NOTIFICATION) { |
| 1788 scheduler_->ScheduleNudgeWithPayloadsAsync( | 1790 scheduler_->ScheduleNudgeWithPayloadsAsync( |
| 1789 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 1791 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
| 1790 NUDGE_SOURCE_LOCAL_REFRESH, | 1792 NUDGE_SOURCE_LOCAL_REFRESH, |
| 1791 type_payloads, FROM_HERE); | 1793 type_payloads, FROM_HERE); |
| 1792 } else if (!type_payloads.empty()) { | 1794 } else if (!type_payloads.empty()) { |
| 1793 scheduler_->ScheduleNudgeWithPayloadsAsync( | 1795 scheduler_->ScheduleNudgeWithPayloadsAsync( |
| 1794 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), | 1796 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), |
| 1795 NUDGE_SOURCE_NOTIFICATION, | 1797 NUDGE_SOURCE_NOTIFICATION, |
| 1796 type_payloads, FROM_HERE); | 1798 type_payloads, FROM_HERE); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1861 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1863 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1862 return kDefaultNudgeDelayMilliseconds; | 1864 return kDefaultNudgeDelayMilliseconds; |
| 1863 } | 1865 } |
| 1864 | 1866 |
| 1865 // static. | 1867 // static. |
| 1866 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1868 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1867 return kPreferencesNudgeDelayMilliseconds; | 1869 return kPreferencesNudgeDelayMilliseconds; |
| 1868 } | 1870 } |
| 1869 | 1871 |
| 1870 } // namespace syncer | 1872 } // namespace syncer |
| OLD | NEW |