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" | |
43 #include "sync/notifier/notifications_disabled_reason.h" | 42 #include "sync/notifier/notifications_disabled_reason.h" |
44 #include "sync/notifier/sync_notifier.h" | 43 #include "sync/notifier/sync_notifier.h" |
45 #include "sync/protocol/encryption.pb.h" | 44 #include "sync/protocol/encryption.pb.h" |
46 #include "sync/protocol/proto_value_conversions.h" | 45 #include "sync/protocol/proto_value_conversions.h" |
47 #include "sync/protocol/sync.pb.h" | 46 #include "sync/protocol/sync.pb.h" |
48 #include "sync/syncable/directory.h" | 47 #include "sync/syncable/directory.h" |
49 #include "sync/syncable/entry.h" | 48 #include "sync/syncable/entry.h" |
50 #include "sync/syncable/in_memory_directory_backing_store.h" | 49 #include "sync/syncable/in_memory_directory_backing_store.h" |
51 #include "sync/syncable/nigori_util.h" | 50 #include "sync/syncable/nigori_util.h" |
52 #include "sync/syncable/on_disk_directory_backing_store.h" | 51 #include "sync/syncable/on_disk_directory_backing_store.h" |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 // post a task to shutdown sync. But if this function posts any other tasks | 474 // post a task to shutdown sync. But if this function posts any other tasks |
476 // on the UI thread and if shutdown wins then that tasks would execute on | 475 // on the UI thread and if shutdown wins then that tasks would execute on |
477 // a freed pointer. This is because UI thread is not shut down. | 476 // a freed pointer. This is because UI thread is not shut down. |
478 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 477 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
479 OnInitializationComplete( | 478 OnInitializationComplete( |
480 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 479 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
481 success)); | 480 success)); |
482 if (!success) | 481 if (!success) |
483 return false; | 482 return false; |
484 | 483 |
| 484 sync_notifier_->AddObserver(this); |
| 485 |
485 return success; | 486 return success; |
486 } | 487 } |
487 | 488 |
488 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, | 489 void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, |
489 const base::Closure& done_callback) { | 490 const base::Closure& done_callback) { |
490 DCHECK(initialized_); | 491 DCHECK(initialized_); |
491 DCHECK(thread_checker_.CalledOnValidThread()); | 492 DCHECK(thread_checker_.CalledOnValidThread()); |
492 GetSessionName( | 493 GetSessionName( |
493 blocking_task_runner_, | 494 blocking_task_runner_, |
494 base::Bind( | 495 base::Bind( |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 credentials.email, credentials.sync_token); | 718 credentials.email, credentials.sync_token); |
718 if (initialized_) { | 719 if (initialized_) { |
719 scheduler_->OnCredentialsUpdated(); | 720 scheduler_->OnCredentialsUpdated(); |
720 } | 721 } |
721 } | 722 } |
722 } | 723 } |
723 | 724 |
724 void SyncManagerImpl::UpdateEnabledTypes( | 725 void SyncManagerImpl::UpdateEnabledTypes( |
725 const ModelTypeSet& enabled_types) { | 726 const ModelTypeSet& enabled_types) { |
726 DCHECK(thread_checker_.CalledOnValidThread()); | 727 DCHECK(thread_checker_.CalledOnValidThread()); |
727 sync_notifier_->UpdateRegisteredIds(this, | 728 sync_notifier_->UpdateEnabledTypes(enabled_types); |
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_->UpdateRegisteredIds(this, ObjectIdSet()); | 1198 sync_notifier_->RemoveObserver(this); |
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 ObjectIdPayloadMap& id_payloads, | 1784 const ModelTypePayloadMap& type_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); | |
1789 if (source == LOCAL_NOTIFICATION) { | 1787 if (source == LOCAL_NOTIFICATION) { |
1790 scheduler_->ScheduleNudgeWithPayloadsAsync( | 1788 scheduler_->ScheduleNudgeWithPayloadsAsync( |
1791 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 1789 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
1792 NUDGE_SOURCE_LOCAL_REFRESH, | 1790 NUDGE_SOURCE_LOCAL_REFRESH, |
1793 type_payloads, FROM_HERE); | 1791 type_payloads, FROM_HERE); |
1794 } else if (!type_payloads.empty()) { | 1792 } else if (!type_payloads.empty()) { |
1795 scheduler_->ScheduleNudgeWithPayloadsAsync( | 1793 scheduler_->ScheduleNudgeWithPayloadsAsync( |
1796 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), | 1794 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), |
1797 NUDGE_SOURCE_NOTIFICATION, | 1795 NUDGE_SOURCE_NOTIFICATION, |
1798 type_payloads, FROM_HERE); | 1796 type_payloads, FROM_HERE); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1861 int SyncManagerImpl::GetDefaultNudgeDelay() { |
1864 return kDefaultNudgeDelayMilliseconds; | 1862 return kDefaultNudgeDelayMilliseconds; |
1865 } | 1863 } |
1866 | 1864 |
1867 // static. | 1865 // static. |
1868 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1866 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
1869 return kPreferencesNudgeDelayMilliseconds; | 1867 return kPreferencesNudgeDelayMilliseconds; |
1870 } | 1868 } |
1871 | 1869 |
1872 } // namespace syncer | 1870 } // namespace syncer |
OLD | NEW |