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