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/bind.h" | 10 #include "base/bind.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 using base::TimeTicks; | 24 using base::TimeTicks; |
25 | 25 |
26 namespace syncer { | 26 namespace syncer { |
27 | 27 |
28 using sessions::SyncSession; | 28 using sessions::SyncSession; |
29 using sessions::SyncSessionSnapshot; | 29 using sessions::SyncSessionSnapshot; |
30 using sessions::SyncSourceInfo; | 30 using sessions::SyncSourceInfo; |
31 using sync_pb::GetUpdatesCallerInfo; | 31 using sync_pb::GetUpdatesCallerInfo; |
32 | 32 |
33 namespace { | 33 namespace { |
| 34 |
| 35 // For integration tests only. Override initial backoff value. |
| 36 // TODO(tim): Remove this egregiousness, use command line flag and plumb |
| 37 // through. Done this way to reduce diffs in hotfix. |
| 38 static bool g_force_short_retry = false; |
| 39 |
34 bool ShouldRequestEarlyExit(const SyncProtocolError& error) { | 40 bool ShouldRequestEarlyExit(const SyncProtocolError& error) { |
35 switch (error.error_type) { | 41 switch (error.error_type) { |
36 case SYNC_SUCCESS: | 42 case SYNC_SUCCESS: |
37 case MIGRATION_DONE: | 43 case MIGRATION_DONE: |
38 case THROTTLED: | 44 case THROTTLED: |
39 case TRANSIENT_ERROR: | 45 case TRANSIENT_ERROR: |
40 return false; | 46 return false; |
41 case NOT_MY_BIRTHDAY: | 47 case NOT_MY_BIRTHDAY: |
42 case CLEAR_PENDING: | 48 case CLEAR_PENDING: |
43 // If we send terminate sync early then |sync_cycle_ended| notification | 49 // If we send terminate sync early then |sync_cycle_ended| notification |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 &SyncSchedulerImpl::PollTimerCallback); | 896 &SyncSchedulerImpl::PollTimerCallback); |
891 } | 897 } |
892 | 898 |
893 void SyncSchedulerImpl::RestartWaiting() { | 899 void SyncSchedulerImpl::RestartWaiting() { |
894 CHECK(wait_interval_.get()); | 900 CHECK(wait_interval_.get()); |
895 wait_interval_->timer.Stop(); | 901 wait_interval_->timer.Stop(); |
896 wait_interval_->timer.Start(FROM_HERE, wait_interval_->length, | 902 wait_interval_->timer.Start(FROM_HERE, wait_interval_->length, |
897 this, &SyncSchedulerImpl::DoCanaryJob); | 903 this, &SyncSchedulerImpl::DoCanaryJob); |
898 } | 904 } |
899 | 905 |
| 906 namespace { |
| 907 // TODO(tim): Move this function to syncer_error.h. |
| 908 // Return true if the command in question was attempted and did not complete |
| 909 // successfully. |
| 910 bool IsError(SyncerError error) { |
| 911 return error != UNSET && error != SYNCER_OK; |
| 912 } |
| 913 } // namespace |
| 914 |
| 915 // static |
| 916 void SyncSchedulerImpl::ForceShortInitialBackoffRetry() { |
| 917 g_force_short_retry = true; |
| 918 } |
| 919 |
| 920 TimeDelta SyncSchedulerImpl::GetInitialBackoffDelay( |
| 921 const sessions::ModelNeutralState& state) const { |
| 922 // TODO(tim): Remove this, provide integration-test-only mechanism |
| 923 // for override. |
| 924 if (g_force_short_retry) { |
| 925 return TimeDelta::FromSeconds(kInitialBackoffShortRetrySeconds); |
| 926 } |
| 927 |
| 928 if (IsError(state.last_get_key_result)) |
| 929 return TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); |
| 930 // Note: If we received a MIGRATION_DONE on download updates, then commit |
| 931 // should not have taken place. Moreover, if we receive a MIGRATION_DONE |
| 932 // on commit, it means that download updates succeeded. Therefore, we only |
| 933 // need to check if either code is equal to SERVER_RETURN_MIGRATION_DONE, |
| 934 // and not if there were any more serious errors requiring the long retry. |
| 935 if (state.last_download_updates_result == SERVER_RETURN_MIGRATION_DONE || |
| 936 state.commit_result == SERVER_RETURN_MIGRATION_DONE) { |
| 937 return TimeDelta::FromSeconds(kInitialBackoffShortRetrySeconds); |
| 938 } |
| 939 |
| 940 return TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); |
| 941 } |
| 942 |
900 void SyncSchedulerImpl::HandleContinuationError( | 943 void SyncSchedulerImpl::HandleContinuationError( |
901 const SyncSessionJob& old_job) { | 944 const SyncSessionJob& old_job) { |
902 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 945 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
903 if (DCHECK_IS_ON()) { | 946 if (DCHECK_IS_ON()) { |
904 if (IsBackingOff()) { | 947 if (IsBackingOff()) { |
905 DCHECK(wait_interval_->timer.IsRunning() || old_job.is_canary_job); | 948 DCHECK(wait_interval_->timer.IsRunning() || old_job.is_canary_job); |
906 } | 949 } |
907 } | 950 } |
908 | 951 |
909 TimeDelta length = delay_provider_->GetDelay( | 952 TimeDelta length = delay_provider_->GetDelay( |
910 IsBackingOff() ? wait_interval_->length : TimeDelta::FromSeconds(1)); | 953 IsBackingOff() ? wait_interval_->length : |
| 954 GetInitialBackoffDelay( |
| 955 old_job.session->status_controller().model_neutral_state())); |
911 | 956 |
912 SDVLOG(2) << "In handle continuation error with " | 957 SDVLOG(2) << "In handle continuation error with " |
913 << SyncSessionJob::GetPurposeString(old_job.purpose) | 958 << SyncSessionJob::GetPurposeString(old_job.purpose) |
914 << " job. The time delta(ms) is " | 959 << " job. The time delta(ms) is " |
915 << length.InMilliseconds(); | 960 << length.InMilliseconds(); |
916 | 961 |
917 // This will reset the had_nudge variable as well. | 962 // This will reset the had_nudge variable as well. |
918 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, | 963 wait_interval_.reset(new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, |
919 length)); | 964 length)); |
920 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { | 965 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 | 1192 |
1148 #undef SDVLOG_LOC | 1193 #undef SDVLOG_LOC |
1149 | 1194 |
1150 #undef SDVLOG | 1195 #undef SDVLOG |
1151 | 1196 |
1152 #undef SLOG | 1197 #undef SLOG |
1153 | 1198 |
1154 #undef ENUM_CASE | 1199 #undef ENUM_CASE |
1155 | 1200 |
1156 } // namespace syncer | 1201 } // namespace syncer |
OLD | NEW |