OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/sync_scheduler.h" | 5 #include "chrome/browser/sync/engine/sync_scheduler.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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 return; // Nothing to do. | 831 return; // Nothing to do. |
832 } | 832 } |
833 | 833 |
834 SDVLOG(2) << "Updating the next polling time after SyncMain"; | 834 SDVLOG(2) << "Updating the next polling time after SyncMain"; |
835 ScheduleNextSync(job); | 835 ScheduleNextSync(job); |
836 } | 836 } |
837 | 837 |
838 void SyncScheduler::ScheduleNextSync(const SyncSessionJob& old_job) { | 838 void SyncScheduler::ScheduleNextSync(const SyncSessionJob& old_job) { |
839 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 839 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
840 DCHECK(!old_job.session->HasMoreToSync()); | 840 DCHECK(!old_job.session->HasMoreToSync()); |
841 // Note: |num_server_changes_remaining| > 0 here implies that we received a | |
842 // broken response while trying to download all updates, because the Syncer | |
843 // will loop until this value is exhausted. Also, if unsynced_handles exist | |
844 // but HasMoreToSync is false, this implies that the Syncer determined no | |
845 // forward progress was possible at this time (an error, such as an HTTP | |
846 // 500, is likely to have occurred during commit). | |
847 int num_server_changes_remaining = | |
848 old_job.session->status_controller().num_server_changes_remaining(); | |
849 size_t num_unsynced_handles = | |
850 old_job.session->status_controller().unsynced_handles().size(); | |
851 const bool work_to_do = | |
852 num_server_changes_remaining > 0 || num_unsynced_handles > 0; | |
853 SDVLOG(2) << "num server changes remaining: " << num_server_changes_remaining | |
854 << ", num unsynced handles: " << num_unsynced_handles | |
855 << ", syncer has work to do: " << work_to_do; | |
856 | 841 |
857 AdjustPolling(&old_job); | 842 AdjustPolling(&old_job); |
858 | 843 |
859 // TODO(tim): Old impl had special code if notifications disabled. Needed? | 844 if (old_job.session->Succeeded()) { |
860 if (!work_to_do) { | |
861 // Success implies backoff relief. Note that if this was a | 845 // Success implies backoff relief. Note that if this was a |
862 // "one-off" job (i.e. purpose == | 846 // "one-off" job (i.e. purpose == |
863 // SyncSessionJob::{CLEAR_USER_DATA,CLEANUP_DISABLED_TYPES}), if | 847 // SyncSessionJob::{CLEAR_USER_DATA,CLEANUP_DISABLED_TYPES}), if |
864 // there was work_to_do before it ran this wont have changed, as | 848 // there was work to do before it ran this wont have changed, as |
865 // jobs like this don't run a full sync cycle. So we don't need | 849 // jobs like this don't run a full sync cycle. So we don't need |
866 // special code here. | 850 // special code here. |
867 wait_interval_.reset(); | 851 wait_interval_.reset(); |
868 SDVLOG(2) << "Job succeeded so not scheduling more jobs"; | 852 SDVLOG(2) << "Job succeeded so not scheduling more jobs"; |
869 return; | 853 return; |
870 } | 854 } |
871 | 855 |
| 856 // TODO(rlarocque): There's no reason why we should blindly backoff and retry |
| 857 // if we don't succeed. Some types of errors are not likely to disappear on |
| 858 // their own. With the return values now available in the old_job.session, we |
| 859 // should be able to detect such errors and only retry when we detect |
| 860 // transient errors. |
| 861 |
872 // We are in backoff mode and our time did not run out. That means we had | 862 // We are in backoff mode and our time did not run out. That means we had |
873 // a local change, notification from server or a network connection change | 863 // a local change, notification from server or a network connection change |
874 // notification. In any case set had_nudge = true so we dont retry next | 864 // notification. In any case set had_nudge = true so we dont retry next |
875 // nudge. Note: we will keep retrying network connection changes though as | 865 // nudge. Note: we will keep retrying network connection changes though as |
876 // they are treated as canary jobs. Also we check the mode here because | 866 // they are treated as canary jobs. Also we check the mode here because |
877 // we want to do this only in normal mode. For config mode jobs we dont | 867 // we want to do this only in normal mode. For config mode jobs we dont |
878 // have anything similar to had_nudge. | 868 // have anything similar to had_nudge. |
879 if (IsBackingOff() && wait_interval_->timer.IsRunning() && | 869 if (IsBackingOff() && wait_interval_->timer.IsRunning() && |
880 mode_ == NORMAL_MODE) { | 870 mode_ == NORMAL_MODE) { |
881 SDVLOG(2) << "A nudge during backoff failed"; | 871 SDVLOG(2) << "A nudge during backoff failed"; |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 | 1184 |
1195 #undef SDVLOG_LOC | 1185 #undef SDVLOG_LOC |
1196 | 1186 |
1197 #undef SDVLOG | 1187 #undef SDVLOG |
1198 | 1188 |
1199 #undef SLOG | 1189 #undef SLOG |
1200 | 1190 |
1201 #undef ENUM_CASE | 1191 #undef ENUM_CASE |
1202 | 1192 |
1203 } // browser_sync | 1193 } // browser_sync |
OLD | NEW |