| 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/engine/sync_scheduler_impl.h" | 5 #include "sync/engine/sync_scheduler_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 mode_(NORMAL_MODE), | 166 mode_(NORMAL_MODE), |
| 167 delay_provider_(delay_provider), | 167 delay_provider_(delay_provider), |
| 168 syncer_(syncer), | 168 syncer_(syncer), |
| 169 session_context_(context), | 169 session_context_(context), |
| 170 no_scheduling_allowed_(false), | 170 no_scheduling_allowed_(false), |
| 171 do_poll_after_credentials_updated_(false) { | 171 do_poll_after_credentials_updated_(false) { |
| 172 } | 172 } |
| 173 | 173 |
| 174 SyncSchedulerImpl::~SyncSchedulerImpl() { | 174 SyncSchedulerImpl::~SyncSchedulerImpl() { |
| 175 DCHECK(CalledOnValidThread()); | 175 DCHECK(CalledOnValidThread()); |
| 176 StopImpl(); | 176 Stop(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void SyncSchedulerImpl::OnCredentialsUpdated() { | 179 void SyncSchedulerImpl::OnCredentialsUpdated() { |
| 180 DCHECK(CalledOnValidThread()); | 180 DCHECK(CalledOnValidThread()); |
| 181 | 181 |
| 182 if (HttpResponse::SYNC_AUTH_ERROR == | 182 if (HttpResponse::SYNC_AUTH_ERROR == |
| 183 session_context_->connection_manager()->server_status()) { | 183 session_context_->connection_manager()->server_status()) { |
| 184 OnServerConnectionErrorFixed(); | 184 OnServerConnectionErrorFixed(); |
| 185 } | 185 } |
| 186 } | 186 } |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 weak_ptr_factory_.GetWeakPtr())); | 637 weak_ptr_factory_.GetWeakPtr())); |
| 638 } else { | 638 } else { |
| 639 pending_wakeup_timer_.Start( | 639 pending_wakeup_timer_.Start( |
| 640 FROM_HERE, | 640 FROM_HERE, |
| 641 wait_interval_->length, | 641 wait_interval_->length, |
| 642 base::Bind(&SyncSchedulerImpl::ExponentialBackoffRetry, | 642 base::Bind(&SyncSchedulerImpl::ExponentialBackoffRetry, |
| 643 weak_ptr_factory_.GetWeakPtr())); | 643 weak_ptr_factory_.GetWeakPtr())); |
| 644 } | 644 } |
| 645 } | 645 } |
| 646 | 646 |
| 647 void SyncSchedulerImpl::RequestStop() { | 647 void SyncSchedulerImpl::Stop() { |
| 648 syncer_->RequestEarlyExit(); // Safe to call from any thread. | |
| 649 DCHECK(weak_handle_this_.IsInitialized()); | |
| 650 SDVLOG(3) << "Posting StopImpl"; | |
| 651 weak_handle_this_.Call(FROM_HERE, | |
| 652 &SyncSchedulerImpl::StopImpl); | |
| 653 } | |
| 654 | |
| 655 void SyncSchedulerImpl::StopImpl() { | |
| 656 DCHECK(CalledOnValidThread()); | 648 DCHECK(CalledOnValidThread()); |
| 657 SDVLOG(2) << "StopImpl called"; | 649 SDVLOG(2) << "Stop called"; |
| 658 | 650 |
| 659 // Kill any in-flight method calls. | 651 // Kill any in-flight method calls. |
| 660 weak_ptr_factory_.InvalidateWeakPtrs(); | 652 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 661 wait_interval_.reset(); | 653 wait_interval_.reset(); |
| 662 NotifyRetryTime(base::Time()); | 654 NotifyRetryTime(base::Time()); |
| 663 poll_timer_.Stop(); | 655 poll_timer_.Stop(); |
| 664 pending_wakeup_timer_.Stop(); | 656 pending_wakeup_timer_.Stop(); |
| 665 pending_configure_params_.reset(); | 657 pending_configure_params_.reset(); |
| 666 if (started_) | 658 if (started_) |
| 667 started_ = false; | 659 started_ = false; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 void SyncSchedulerImpl::OnReceivedClientInvalidationHintBufferSize(int size) { | 847 void SyncSchedulerImpl::OnReceivedClientInvalidationHintBufferSize(int size) { |
| 856 if (size > 0) | 848 if (size > 0) |
| 857 nudge_tracker_.SetHintBufferSize(size); | 849 nudge_tracker_.SetHintBufferSize(size); |
| 858 else | 850 else |
| 859 NOTREACHED() << "Hint buffer size should be > 0."; | 851 NOTREACHED() << "Hint buffer size should be > 0."; |
| 860 } | 852 } |
| 861 | 853 |
| 862 void SyncSchedulerImpl::OnShouldStopSyncingPermanently() { | 854 void SyncSchedulerImpl::OnShouldStopSyncingPermanently() { |
| 863 DCHECK(CalledOnValidThread()); | 855 DCHECK(CalledOnValidThread()); |
| 864 SDVLOG(2) << "OnShouldStopSyncingPermanently"; | 856 SDVLOG(2) << "OnShouldStopSyncingPermanently"; |
| 865 syncer_->RequestEarlyExit(); // Thread-safe. | 857 Stop(); |
| 866 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); | 858 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); |
| 867 } | 859 } |
| 868 | 860 |
| 869 void SyncSchedulerImpl::OnActionableError( | 861 void SyncSchedulerImpl::OnActionableError( |
| 870 const sessions::SyncSessionSnapshot& snap) { | 862 const sessions::SyncSessionSnapshot& snap) { |
| 871 DCHECK(CalledOnValidThread()); | 863 DCHECK(CalledOnValidThread()); |
| 872 SDVLOG(2) << "OnActionableError"; | 864 SDVLOG(2) << "OnActionableError"; |
| 873 SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR); | 865 SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR); |
| 874 event.snapshot = snap; | 866 event.snapshot = snap; |
| 875 session_context_->NotifyListeners(event); | 867 session_context_->NotifyListeners(event); |
| 876 } | 868 } |
| 877 | 869 |
| 878 void SyncSchedulerImpl::OnSyncProtocolError( | 870 void SyncSchedulerImpl::OnSyncProtocolError( |
| 879 const sessions::SyncSessionSnapshot& snapshot) { | 871 const sessions::SyncSessionSnapshot& snapshot) { |
| 880 DCHECK(CalledOnValidThread()); | 872 DCHECK(CalledOnValidThread()); |
| 881 if (ShouldRequestEarlyExit( | 873 if (ShouldRequestEarlyExit( |
| 882 snapshot.model_neutral_state().sync_protocol_error)) { | 874 snapshot.model_neutral_state().sync_protocol_error)) { |
| 883 SDVLOG(2) << "Sync Scheduler requesting early exit."; | 875 SDVLOG(2) << "Sync Scheduler requesting early exit."; |
| 884 syncer_->RequestEarlyExit(); // Thread-safe. | 876 Stop(); |
| 885 } | 877 } |
| 886 if (IsActionableError(snapshot.model_neutral_state().sync_protocol_error)) | 878 if (IsActionableError(snapshot.model_neutral_state().sync_protocol_error)) |
| 887 OnActionableError(snapshot); | 879 OnActionableError(snapshot); |
| 888 } | 880 } |
| 889 | 881 |
| 890 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { | 882 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { |
| 891 DCHECK(CalledOnValidThread()); | 883 DCHECK(CalledOnValidThread()); |
| 892 session_context_->set_notifications_enabled(notifications_enabled); | 884 session_context_->set_notifications_enabled(notifications_enabled); |
| 893 if (notifications_enabled) | 885 if (notifications_enabled) |
| 894 nudge_tracker_.OnInvalidationsEnabled(); | 886 nudge_tracker_.OnInvalidationsEnabled(); |
| 895 else | 887 else |
| 896 nudge_tracker_.OnInvalidationsDisabled(); | 888 nudge_tracker_.OnInvalidationsDisabled(); |
| 897 } | 889 } |
| 898 | 890 |
| 899 base::TimeDelta SyncSchedulerImpl::GetSessionsCommitDelay() const { | 891 base::TimeDelta SyncSchedulerImpl::GetSessionsCommitDelay() const { |
| 900 DCHECK(CalledOnValidThread()); | 892 DCHECK(CalledOnValidThread()); |
| 901 return sessions_commit_delay_; | 893 return sessions_commit_delay_; |
| 902 } | 894 } |
| 903 | 895 |
| 904 #undef SDVLOG_LOC | 896 #undef SDVLOG_LOC |
| 905 | 897 |
| 906 #undef SDVLOG | 898 #undef SDVLOG |
| 907 | 899 |
| 908 #undef SLOG | 900 #undef SLOG |
| 909 | 901 |
| 910 #undef ENUM_CASE | 902 #undef ENUM_CASE |
| 911 | 903 |
| 912 } // namespace syncer | 904 } // namespace syncer |
| OLD | NEW |