| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 using sync_pb::GetUpdatesCallerInfo; | 56 using sync_pb::GetUpdatesCallerInfo; |
| 57 | 57 |
| 58 namespace syncer { | 58 namespace syncer { |
| 59 | 59 |
| 60 using sessions::SyncSessionContext; | 60 using sessions::SyncSessionContext; |
| 61 using syncable::ImmutableWriteTransactionInfo; | 61 using syncable::ImmutableWriteTransactionInfo; |
| 62 using syncable::SPECIFICS; | 62 using syncable::SPECIFICS; |
| 63 | 63 |
| 64 namespace { | 64 namespace { |
| 65 | 65 |
| 66 const char kHandlerName[] = "SyncManagerImpl"; |
| 67 |
| 66 // Delays for syncer nudges. | 68 // Delays for syncer nudges. |
| 67 static const int kDefaultNudgeDelayMilliseconds = 200; | 69 static const int kDefaultNudgeDelayMilliseconds = 200; |
| 68 static const int kPreferencesNudgeDelayMilliseconds = 2000; | 70 static const int kPreferencesNudgeDelayMilliseconds = 2000; |
| 69 static const int kSyncRefreshDelayMsec = 500; | 71 static const int kSyncRefreshDelayMsec = 500; |
| 70 static const int kSyncSchedulerDelayMsec = 250; | 72 static const int kSyncSchedulerDelayMsec = 250; |
| 71 | 73 |
| 72 // The maximum number of times we will automatically overwrite the nigori node | 74 // The maximum number of times we will automatically overwrite the nigori node |
| 73 // because the encryption keys don't match (per chrome instantiation). | 75 // because the encryption keys don't match (per chrome instantiation). |
| 74 static const int kNigoriOverwriteLimit = 10; | 76 static const int kNigoriOverwriteLimit = 10; |
| 75 | 77 |
| (...skipping 313 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); |
| 403 } |
| 399 | 404 |
| 400 AddObserver(&js_sync_manager_observer_); | 405 AddObserver(&js_sync_manager_observer_); |
| 401 SetJsEventHandler(event_handler); | 406 SetJsEventHandler(event_handler); |
| 402 | 407 |
| 403 AddObserver(&debug_info_event_listener_); | 408 AddObserver(&debug_info_event_listener_); |
| 404 | 409 |
| 405 database_path_ = database_location.Append( | 410 database_path_ = database_location.Append( |
| 406 syncable::Directory::kSyncDatabaseFilename); | 411 syncable::Directory::kSyncDatabaseFilename); |
| 407 encryptor_ = encryptor; | 412 encryptor_ = encryptor; |
| 408 unrecoverable_error_handler_ = unrecoverable_error_handler; | 413 unrecoverable_error_handler_ = unrecoverable_error_handler; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 return; // Auth token is known to be invalid, so exit early. | 732 return; // Auth token is known to be invalid, so exit early. |
| 728 | 733 |
| 729 sync_notifier_->UpdateCredentials(credentials.email, credentials.sync_token); | 734 sync_notifier_->UpdateCredentials(credentials.email, credentials.sync_token); |
| 730 scheduler_->OnCredentialsUpdated(); | 735 scheduler_->OnCredentialsUpdated(); |
| 731 } | 736 } |
| 732 | 737 |
| 733 void SyncManagerImpl::UpdateEnabledTypes( | 738 void SyncManagerImpl::UpdateEnabledTypes( |
| 734 const ModelTypeSet& enabled_types) { | 739 const ModelTypeSet& enabled_types) { |
| 735 DCHECK(thread_checker_.CalledOnValidThread()); | 740 DCHECK(thread_checker_.CalledOnValidThread()); |
| 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, SyncNotifierObserver* handler) { |
| 748 DCHECK(thread_checker_.CalledOnValidThread()); |
| 749 sync_notifier_->SetHandler(handler_name, handler); |
| 750 } |
| 751 |
| 741 void SyncManagerImpl::UpdateRegisteredInvalidationIds( | 752 void SyncManagerImpl::UpdateRegisteredInvalidationIds( |
| 742 SyncNotifierObserver* handler, const ObjectIdSet& ids) { | 753 const std::string& handler_name, const ObjectIdSet& ids) { |
| 743 DCHECK(thread_checker_.CalledOnValidThread()); | 754 DCHECK(thread_checker_.CalledOnValidThread()); |
| 744 sync_notifier_->UpdateRegisteredIds(handler, ids); | 755 sync_notifier_->UpdateRegisteredIds(handler_name, ids); |
| 745 } | 756 } |
| 746 | 757 |
| 747 void SyncManagerImpl::SetEncryptionPassphrase( | 758 void SyncManagerImpl::SetEncryptionPassphrase( |
| 748 const std::string& passphrase, | 759 const std::string& passphrase, |
| 749 bool is_explicit) { | 760 bool is_explicit) { |
| 750 DCHECK(thread_checker_.CalledOnValidThread()); | 761 DCHECK(thread_checker_.CalledOnValidThread()); |
| 751 // We do not accept empty passphrases. | 762 // We do not accept empty passphrases. |
| 752 if (passphrase.empty()) { | 763 if (passphrase.empty()) { |
| 753 NOTREACHED() << "Cannot encrypt with an empty passphrase."; | 764 NOTREACHED() << "Cannot encrypt with an empty passphrase."; |
| 754 return; | 765 return; |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 | 1220 |
| 1210 scheduler_.reset(); | 1221 scheduler_.reset(); |
| 1211 session_context_.reset(); | 1222 session_context_.reset(); |
| 1212 | 1223 |
| 1213 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1224 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
| 1214 RemoveObserver(&js_sync_manager_observer_); | 1225 RemoveObserver(&js_sync_manager_observer_); |
| 1215 | 1226 |
| 1216 RemoveObserver(&debug_info_event_listener_); | 1227 RemoveObserver(&debug_info_event_listener_); |
| 1217 | 1228 |
| 1218 if (sync_notifier_.get()) { | 1229 if (sync_notifier_.get()) { |
| 1219 sync_notifier_->UpdateRegisteredIds(this, ObjectIdSet()); | 1230 sync_notifier_->SetHandler(kHandlerName, NULL); |
| 1220 } | 1231 } |
| 1221 sync_notifier_.reset(); | 1232 sync_notifier_.reset(); |
| 1222 | 1233 |
| 1223 if (connection_manager_.get()) { | 1234 if (connection_manager_.get()) { |
| 1224 connection_manager_->RemoveListener(this); | 1235 connection_manager_->RemoveListener(this); |
| 1225 } | 1236 } |
| 1226 connection_manager_.reset(); | 1237 connection_manager_.reset(); |
| 1227 | 1238 |
| 1228 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1239 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 1229 observing_ip_address_changes_ = false; | 1240 observing_ip_address_changes_ = false; |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1886 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1897 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1887 return kDefaultNudgeDelayMilliseconds; | 1898 return kDefaultNudgeDelayMilliseconds; |
| 1888 } | 1899 } |
| 1889 | 1900 |
| 1890 // static. | 1901 // static. |
| 1891 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1902 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1892 return kPreferencesNudgeDelayMilliseconds; | 1903 return kPreferencesNudgeDelayMilliseconds; |
| 1893 } | 1904 } |
| 1894 | 1905 |
| 1895 } // namespace syncer | 1906 } // namespace syncer |
| OLD | NEW |