| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 using sync_pb::GetUpdatesCallerInfo; | 55 using sync_pb::GetUpdatesCallerInfo; |
| 56 | 56 |
| 57 namespace syncer { | 57 namespace syncer { |
| 58 | 58 |
| 59 using sessions::SyncSessionContext; | 59 using sessions::SyncSessionContext; |
| 60 using syncable::ImmutableWriteTransactionInfo; | 60 using syncable::ImmutableWriteTransactionInfo; |
| 61 using syncable::SPECIFICS; | 61 using syncable::SPECIFICS; |
| 62 | 62 |
| 63 namespace { | 63 namespace { |
| 64 | 64 |
| 65 const char kHandlerName[] = "SyncManagerImpl"; |
| 66 |
| 65 // Delays for syncer nudges. | 67 // Delays for syncer nudges. |
| 66 static const int kDefaultNudgeDelayMilliseconds = 200; | 68 static const int kDefaultNudgeDelayMilliseconds = 200; |
| 67 static const int kPreferencesNudgeDelayMilliseconds = 2000; | 69 static const int kPreferencesNudgeDelayMilliseconds = 2000; |
| 68 static const int kSyncRefreshDelayMsec = 500; | 70 static const int kSyncRefreshDelayMsec = 500; |
| 69 static const int kSyncSchedulerDelayMsec = 250; | 71 static const int kSyncSchedulerDelayMsec = 250; |
| 70 | 72 |
| 71 // The maximum number of times we will automatically overwrite the nigori node | 73 // The maximum number of times we will automatically overwrite the nigori node |
| 72 // because the encryption keys don't match (per chrome instantiation). | 74 // because the encryption keys don't match (per chrome instantiation). |
| 73 static const int kNigoriOverwriteLimit = 10; | 75 static const int kNigoriOverwriteLimit = 10; |
| 74 | 76 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 DCHECK(!credentials.sync_token.empty()); | 391 DCHECK(!credentials.sync_token.empty()); |
| 390 DVLOG(1) << "SyncManager starting Init..."; | 392 DVLOG(1) << "SyncManager starting Init..."; |
| 391 | 393 |
| 392 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); | 394 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); |
| 393 | 395 |
| 394 blocking_task_runner_ = blocking_task_runner; | 396 blocking_task_runner_ = blocking_task_runner; |
| 395 | 397 |
| 396 change_delegate_ = change_delegate; | 398 change_delegate_ = change_delegate; |
| 397 | 399 |
| 398 sync_notifier_ = sync_notifier.Pass(); | 400 sync_notifier_ = sync_notifier.Pass(); |
| 401 if (sync_notifier_.get()) |
| 402 sync_notifier_->SetHandler(kHandlerName, this); |
| 399 | 403 |
| 400 AddObserver(&js_sync_manager_observer_); | 404 AddObserver(&js_sync_manager_observer_); |
| 401 SetJsEventHandler(event_handler); | 405 SetJsEventHandler(event_handler); |
| 402 | 406 |
| 403 AddObserver(&debug_info_event_listener_); | 407 AddObserver(&debug_info_event_listener_); |
| 404 | 408 |
| 405 database_path_ = database_location.Append( | 409 database_path_ = database_location.Append( |
| 406 syncable::Directory::kSyncDatabaseFilename); | 410 syncable::Directory::kSyncDatabaseFilename); |
| 407 encryptor_ = encryptor; | 411 encryptor_ = encryptor; |
| 408 unrecoverable_error_handler_ = unrecoverable_error_handler; | 412 unrecoverable_error_handler_ = unrecoverable_error_handler; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 if (!connection_manager_->set_auth_token(credentials.sync_token)) | 730 if (!connection_manager_->set_auth_token(credentials.sync_token)) |
| 727 return; // Auth token is known to be invalid, so exit early. | 731 return; // Auth token is known to be invalid, so exit early. |
| 728 | 732 |
| 729 sync_notifier_->UpdateCredentials(credentials.email, credentials.sync_token); | 733 sync_notifier_->UpdateCredentials(credentials.email, credentials.sync_token); |
| 730 scheduler_->OnCredentialsUpdated(); | 734 scheduler_->OnCredentialsUpdated(); |
| 731 } | 735 } |
| 732 | 736 |
| 733 void SyncManagerImpl::UpdateEnabledTypes( | 737 void SyncManagerImpl::UpdateEnabledTypes( |
| 734 const ModelTypeSet& enabled_types) { | 738 const ModelTypeSet& enabled_types) { |
| 735 DCHECK(thread_checker_.CalledOnValidThread()); | 739 DCHECK(thread_checker_.CalledOnValidThread()); |
| 740 DCHECK(initialized_); |
| 736 sync_notifier_->UpdateRegisteredIds( | 741 sync_notifier_->UpdateRegisteredIds( |
| 737 this, | 742 kHandlerName, |
| 738 ModelTypeSetToObjectIdSet(enabled_types)); | 743 ModelTypeSetToObjectIdSet(enabled_types)); |
| 739 } | 744 } |
| 740 | 745 |
| 746 void SyncManagerImpl::SetInvalidationHandler( |
| 747 const std::string& handler_name, |
| 748 SyncNotifierObserver* handler) { |
| 749 DCHECK(thread_checker_.CalledOnValidThread()); |
| 750 // We may be called when initialization fails, so |initialized_| may |
| 751 // be false. |
| 752 sync_notifier_->SetHandler(handler_name, handler); |
| 753 } |
| 754 |
| 741 void SyncManagerImpl::UpdateRegisteredInvalidationIds( | 755 void SyncManagerImpl::UpdateRegisteredInvalidationIds( |
| 742 SyncNotifierObserver* handler, | 756 const std::string& handler_name, |
| 743 const ObjectIdSet& ids) { | 757 const ObjectIdSet& ids) { |
| 744 DCHECK(thread_checker_.CalledOnValidThread()); | 758 DCHECK(thread_checker_.CalledOnValidThread()); |
| 745 sync_notifier_->UpdateRegisteredIds(handler, ids); | 759 DCHECK(initialized_); |
| 760 sync_notifier_->UpdateRegisteredIds(handler_name, ids); |
| 746 } | 761 } |
| 747 | 762 |
| 748 void SyncManagerImpl::SetEncryptionPassphrase( | 763 void SyncManagerImpl::SetEncryptionPassphrase( |
| 749 const std::string& passphrase, | 764 const std::string& passphrase, |
| 750 bool is_explicit) { | 765 bool is_explicit) { |
| 751 DCHECK(thread_checker_.CalledOnValidThread()); | 766 DCHECK(thread_checker_.CalledOnValidThread()); |
| 752 // We do not accept empty passphrases. | 767 // We do not accept empty passphrases. |
| 753 if (passphrase.empty()) { | 768 if (passphrase.empty()) { |
| 754 NOTREACHED() << "Cannot encrypt with an empty passphrase."; | 769 NOTREACHED() << "Cannot encrypt with an empty passphrase."; |
| 755 return; | 770 return; |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 | 1225 |
| 1211 scheduler_.reset(); | 1226 scheduler_.reset(); |
| 1212 session_context_.reset(); | 1227 session_context_.reset(); |
| 1213 | 1228 |
| 1214 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1229 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
| 1215 RemoveObserver(&js_sync_manager_observer_); | 1230 RemoveObserver(&js_sync_manager_observer_); |
| 1216 | 1231 |
| 1217 RemoveObserver(&debug_info_event_listener_); | 1232 RemoveObserver(&debug_info_event_listener_); |
| 1218 | 1233 |
| 1219 if (sync_notifier_.get()) { | 1234 if (sync_notifier_.get()) { |
| 1220 sync_notifier_->UpdateRegisteredIds(this, ObjectIdSet()); | 1235 sync_notifier_->SetHandler(kHandlerName, NULL); |
| 1221 } | 1236 } |
| 1222 sync_notifier_.reset(); | 1237 sync_notifier_.reset(); |
| 1223 | 1238 |
| 1224 if (connection_manager_.get()) { | 1239 if (connection_manager_.get()) { |
| 1225 connection_manager_->RemoveListener(this); | 1240 connection_manager_->RemoveListener(this); |
| 1226 } | 1241 } |
| 1227 connection_manager_.reset(); | 1242 connection_manager_.reset(); |
| 1228 | 1243 |
| 1229 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1244 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1230 observing_ip_address_changes_ = false; | 1245 observing_ip_address_changes_ = false; |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1897 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1912 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1898 return kDefaultNudgeDelayMilliseconds; | 1913 return kDefaultNudgeDelayMilliseconds; |
| 1899 } | 1914 } |
| 1900 | 1915 |
| 1901 // static. | 1916 // static. |
| 1902 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1917 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1903 return kPreferencesNudgeDelayMilliseconds; | 1918 return kPreferencesNudgeDelayMilliseconds; |
| 1904 } | 1919 } |
| 1905 | 1920 |
| 1906 } // namespace syncer | 1921 } // namespace syncer |
| OLD | NEW |