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/backoff_delay_provider.h" | 5 #include "sync/engine/backoff_delay_provider.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 // Cap the backoff interval. | 59 // Cap the backoff interval. |
60 backoff_s = std::max(static_cast<int64_t>(1), | 60 backoff_s = std::max(static_cast<int64_t>(1), |
61 std::min(backoff_s, kMaxBackoffSeconds)); | 61 std::min(backoff_s, kMaxBackoffSeconds)); |
62 | 62 |
63 return TimeDelta::FromSeconds(backoff_s); | 63 return TimeDelta::FromSeconds(backoff_s); |
64 } | 64 } |
65 | 65 |
66 TimeDelta BackoffDelayProvider::GetInitialDelay( | 66 TimeDelta BackoffDelayProvider::GetInitialDelay( |
67 const sessions::ModelNeutralState& state) const { | 67 const sessions::ModelNeutralState& state) const { |
68 // NETWORK_CONNECTION_UNAVAILABLE implies we did not even manage to hit the | 68 // NETWORK_CONNECTION_UNAVAILABLE implies we did not receive HTTP response |
69 // wire; the failure occurred locally. Note that if commit_result is *not* | 69 // from server because of some network error. If network is unavailable then |
70 // UNSET, this implies download_updates_result succeeded. Also note that | 70 // on next connection type or address change scheduler will run canary job. |
71 // last_get_key_result is coupled to last_download_updates_result in that | 71 // Otherwise we'll retry in 30 seconds. |
72 // they are part of the same GetUpdates request, so we only check if | |
73 // the download request is CONNECTION_UNAVAILABLE. | |
74 // | |
75 // TODO(tim): Should we treat NETWORK_IO_ERROR similarly? It's different | |
76 // from CONNECTION_UNAVAILABLE in that a request may well have succeeded | |
77 // in contacting the server (e.g we got a 200 back), but we failed | |
78 // trying to parse the response (actual content length != HTTP response | |
79 // header content length value). For now since we're considering | |
80 // merging this code to branches and I haven't audited all the | |
81 // NETWORK_IO_ERROR cases carefully, I'm going to target the fix | |
82 // very tightly (see bug chromium-os:35073). DIRECTORY_LOOKUP_FAILED is | |
83 // another example of something that shouldn't backoff, though the | |
84 // scheduler should probably be handling these cases differently. See | |
85 // the TODO(rlarocque) in ScheduleNextSync. | |
86 if (state.commit_result == NETWORK_CONNECTION_UNAVAILABLE || | 72 if (state.commit_result == NETWORK_CONNECTION_UNAVAILABLE || |
87 state.last_download_updates_result == NETWORK_CONNECTION_UNAVAILABLE) { | 73 state.last_download_updates_result == NETWORK_CONNECTION_UNAVAILABLE) { |
88 return short_initial_backoff_; | 74 return default_initial_backoff_; |
89 } | 75 } |
90 | 76 |
91 if (SyncerErrorIsError(state.last_get_key_result)) | 77 if (SyncerErrorIsError(state.last_get_key_result)) |
92 return default_initial_backoff_; | 78 return default_initial_backoff_; |
93 | 79 |
94 // Note: If we received a MIGRATION_DONE on download updates, then commit | 80 // Note: If we received a MIGRATION_DONE on download updates, then commit |
95 // should not have taken place. Moreover, if we receive a MIGRATION_DONE | 81 // should not have taken place. Moreover, if we receive a MIGRATION_DONE |
96 // on commit, it means that download updates succeeded. Therefore, we only | 82 // on commit, it means that download updates succeeded. Therefore, we only |
97 // need to check if either code is equal to SERVER_RETURN_MIGRATION_DONE, | 83 // need to check if either code is equal to SERVER_RETURN_MIGRATION_DONE, |
98 // and not if there were any more serious errors requiring the long retry. | 84 // and not if there were any more serious errors requiring the long retry. |
(...skipping 15 matching lines...) Expand all Loading... |
114 // TODO(sync): We shouldn't need to handle this in BackoffDelayProvider. | 100 // TODO(sync): We shouldn't need to handle this in BackoffDelayProvider. |
115 // There should be a way to deal with protocol errors before we get to this | 101 // There should be a way to deal with protocol errors before we get to this |
116 // point. | 102 // point. |
117 if (state.commit_result == SERVER_RETURN_CONFLICT) | 103 if (state.commit_result == SERVER_RETURN_CONFLICT) |
118 return short_initial_backoff_; | 104 return short_initial_backoff_; |
119 | 105 |
120 return default_initial_backoff_; | 106 return default_initial_backoff_; |
121 } | 107 } |
122 | 108 |
123 } // namespace syncer | 109 } // namespace syncer |
OLD | NEW |