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/sessions/sync_session.h" | 5 #include "chrome/browser/sync/sessions/sync_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/sync/syncable/directory_manager.h" | 10 #include "chrome/browser/sync/syncable/directory_manager.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 if (update_progress && | 226 if (update_progress && |
227 (update_progress->VerifiedUpdatesBegin() != | 227 (update_progress->VerifiedUpdatesBegin() != |
228 update_progress->VerifiedUpdatesEnd())) { | 228 update_progress->VerifiedUpdatesEnd())) { |
229 enabled_groups_with_verified_updates.insert(*it); | 229 enabled_groups_with_verified_updates.insert(*it); |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 return enabled_groups_with_verified_updates; | 233 return enabled_groups_with_verified_updates; |
234 } | 234 } |
235 | 235 |
| 236 namespace { |
| 237 // Returns true if the result indicates an error that might go away on its own. |
| 238 // In other words, it wouldn't be a bad idea to retry with exponential backoff |
| 239 // if we detect one of these errors. |
| 240 bool IsTransientError(SyncerError error) { |
| 241 switch (error) { |
| 242 // No operation was not attempted. |
| 243 case UNINITIALIZED: |
| 244 return false; |
| 245 |
| 246 // Client-side error. |
| 247 case DIRECTORY_LOOKUP_FAILED: |
| 248 return false; |
| 249 |
| 250 // Probably temporary network issues. |
| 251 case NETWORK_CONNECTION_UNAVAILABLE: |
| 252 case NETWORK_IO_ERROR: |
| 253 return true; |
| 254 |
| 255 // Error cause is ambiguous. It's best not to retry in these cases. |
| 256 case SYNC_SERVER_ERROR: |
| 257 case SERVER_RETURN_UNKNOWN_ERROR: |
| 258 return false; |
| 259 |
| 260 // These require user intervention |
| 261 case SYNC_AUTH_ERROR: |
| 262 case SERVER_RETURN_INVALID_CREDENTIAL: |
| 263 return false; |
| 264 |
| 265 // We have special logic to handle backoff in this case. |
| 266 case SERVER_RETURN_THROTTLED: |
| 267 return false; |
| 268 |
| 269 // The server wants us to retry. |
| 270 case SERVER_RETURN_TRANSIENT_ERROR: |
| 271 return true; |
| 272 |
| 273 // Handled separately. |
| 274 case SERVER_RETURN_MIGRATION_DONE: |
| 275 case SERVER_RETURN_CLEAR_PENDING: |
| 276 case SERVER_RETURN_NOT_MY_BIRTHDAY: |
| 277 case SERVER_RESPONSE_VALIDATION_FAILED: |
| 278 return false; |
| 279 |
| 280 case NO_ERROR: |
| 281 return false; |
| 282 } |
| 283 } |
| 284 } // namespace |
| 285 |
| 286 bool SyncSession::ExperiencedTransientError() const { |
| 287 return IsTransientError(status_controller_->error().download_updates_result) |
| 288 || IsTransientError(status_controller_->error().post_commit_result) |
| 289 || IsTransientError( |
| 290 status_controller_->error().process_commit_response_result); |
| 291 } |
| 292 |
| 293 namespace { |
| 294 // Return true if the command in question was attempted and did not complete |
| 295 // successfully. |
| 296 // |
| 297 bool IsError(SyncerError error) { |
| 298 return error != UNINITIALIZED && error != NO_ERROR; |
| 299 } |
| 300 } // namespace |
| 301 |
| 302 bool SyncSession::Succeeded() const { |
| 303 bool download_updates_error = |
| 304 IsError(status_controller_->error().download_updates_result); |
| 305 bool post_commit_error = |
| 306 IsError(status_controller_->error().post_commit_result); |
| 307 bool process_commit_response_error = |
| 308 IsError(status_controller_->error().process_commit_response_result); |
| 309 return !download_updates_error |
| 310 && !post_commit_error |
| 311 && !process_commit_response_error; |
| 312 } |
236 | 313 |
237 } // namespace sessions | 314 } // namespace sessions |
238 } // namespace browser_sync | 315 } // namespace browser_sync |
OLD | NEW |