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 StopImpl(); | 177 Stop(); |
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::RequestStop() { | 646 void SyncSchedulerImpl::Stop() { |
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() { | |
655 DCHECK(CalledOnValidThread()); | 647 DCHECK(CalledOnValidThread()); |
656 SDVLOG(2) << "StopImpl called"; | 648 SDVLOG(2) << "Stop called"; |
657 | 649 |
658 // Kill any in-flight method calls. | 650 // Kill any in-flight method calls. |
659 weak_ptr_factory_.InvalidateWeakPtrs(); | 651 weak_ptr_factory_.InvalidateWeakPtrs(); |
660 wait_interval_.reset(); | 652 wait_interval_.reset(); |
661 NotifyRetryTime(base::Time()); | 653 NotifyRetryTime(base::Time()); |
662 poll_timer_.Stop(); | 654 poll_timer_.Stop(); |
663 pending_wakeup_timer_.Stop(); | 655 pending_wakeup_timer_.Stop(); |
664 pending_configure_params_.reset(); | 656 pending_configure_params_.reset(); |
665 if (started_) | 657 if (started_) |
666 started_ = false; | 658 started_ = false; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 void SyncSchedulerImpl::OnReceivedClientInvalidationHintBufferSize(int size) { | 846 void SyncSchedulerImpl::OnReceivedClientInvalidationHintBufferSize(int size) { |
855 if (size > 0) | 847 if (size > 0) |
856 nudge_tracker_.SetHintBufferSize(size); | 848 nudge_tracker_.SetHintBufferSize(size); |
857 else | 849 else |
858 NOTREACHED() << "Hint buffer size should be > 0."; | 850 NOTREACHED() << "Hint buffer size should be > 0."; |
859 } | 851 } |
860 | 852 |
861 void SyncSchedulerImpl::OnShouldStopSyncingPermanently() { | 853 void SyncSchedulerImpl::OnShouldStopSyncingPermanently() { |
862 DCHECK(CalledOnValidThread()); | 854 DCHECK(CalledOnValidThread()); |
863 SDVLOG(2) << "OnShouldStopSyncingPermanently"; | 855 SDVLOG(2) << "OnShouldStopSyncingPermanently"; |
864 syncer_->RequestEarlyExit(); // Thread-safe. | 856 Stop(); |
865 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); | 857 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); |
866 } | 858 } |
867 | 859 |
868 void SyncSchedulerImpl::OnActionableError( | 860 void SyncSchedulerImpl::OnActionableError( |
869 const sessions::SyncSessionSnapshot& snap) { | 861 const sessions::SyncSessionSnapshot& snap) { |
870 DCHECK(CalledOnValidThread()); | 862 DCHECK(CalledOnValidThread()); |
871 SDVLOG(2) << "OnActionableError"; | 863 SDVLOG(2) << "OnActionableError"; |
872 SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR); | 864 SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR); |
873 event.snapshot = snap; | 865 event.snapshot = snap; |
874 session_context_->NotifyListeners(event); | 866 session_context_->NotifyListeners(event); |
875 } | 867 } |
876 | 868 |
877 void SyncSchedulerImpl::OnSyncProtocolError( | 869 void SyncSchedulerImpl::OnSyncProtocolError( |
878 const sessions::SyncSessionSnapshot& snapshot) { | 870 const sessions::SyncSessionSnapshot& snapshot) { |
879 DCHECK(CalledOnValidThread()); | 871 DCHECK(CalledOnValidThread()); |
880 if (ShouldRequestEarlyExit( | 872 if (ShouldRequestEarlyExit( |
881 snapshot.model_neutral_state().sync_protocol_error)) { | 873 snapshot.model_neutral_state().sync_protocol_error)) { |
882 SDVLOG(2) << "Sync Scheduler requesting early exit."; | 874 SDVLOG(2) << "Sync Scheduler requesting early exit."; |
883 syncer_->RequestEarlyExit(); // Thread-safe. | 875 Stop(); |
884 } | 876 } |
885 if (IsActionableError(snapshot.model_neutral_state().sync_protocol_error)) | 877 if (IsActionableError(snapshot.model_neutral_state().sync_protocol_error)) |
886 OnActionableError(snapshot); | 878 OnActionableError(snapshot); |
887 } | 879 } |
888 | 880 |
889 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { | 881 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { |
890 DCHECK(CalledOnValidThread()); | 882 DCHECK(CalledOnValidThread()); |
891 session_context_->set_notifications_enabled(notifications_enabled); | 883 session_context_->set_notifications_enabled(notifications_enabled); |
892 if (notifications_enabled) | 884 if (notifications_enabled) |
893 nudge_tracker_.OnInvalidationsEnabled(); | 885 nudge_tracker_.OnInvalidationsEnabled(); |
894 else | 886 else |
895 nudge_tracker_.OnInvalidationsDisabled(); | 887 nudge_tracker_.OnInvalidationsDisabled(); |
896 } | 888 } |
897 | 889 |
898 base::TimeDelta SyncSchedulerImpl::GetSessionsCommitDelay() const { | 890 base::TimeDelta SyncSchedulerImpl::GetSessionsCommitDelay() const { |
899 DCHECK(CalledOnValidThread()); | 891 DCHECK(CalledOnValidThread()); |
900 return sessions_commit_delay_; | 892 return sessions_commit_delay_; |
901 } | 893 } |
902 | 894 |
903 #undef SDVLOG_LOC | 895 #undef SDVLOG_LOC |
904 | 896 |
905 #undef SDVLOG | 897 #undef SDVLOG |
906 | 898 |
907 #undef SLOG | 899 #undef SLOG |
908 | 900 |
909 #undef ENUM_CASE | 901 #undef ENUM_CASE |
910 | 902 |
911 } // namespace syncer | 903 } // namespace syncer |
OLD | NEW |