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/sessions/sync_session.h" | 5 #include "sync/sessions/sync_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 (update_progress->VerifiedUpdatesBegin() != | 232 (update_progress->VerifiedUpdatesBegin() != |
233 update_progress->VerifiedUpdatesEnd())) { | 233 update_progress->VerifiedUpdatesEnd())) { |
234 enabled_groups_with_verified_updates.insert(*it); | 234 enabled_groups_with_verified_updates.insert(*it); |
235 } | 235 } |
236 } | 236 } |
237 | 237 |
238 return enabled_groups_with_verified_updates; | 238 return enabled_groups_with_verified_updates; |
239 } | 239 } |
240 | 240 |
241 namespace { | 241 namespace { |
242 // Return true if the command in question was attempted and did not complete | |
243 // successfully. | |
244 bool IsError(SyncerError error) { | |
245 return error != UNSET && error != SYNCER_OK; | |
246 } | |
247 | 242 |
248 // Returns false iff one of the command results had an error. | 243 // Returns false iff one of the command results had an error. |
249 bool HadErrors(const ModelNeutralState& state) { | 244 bool HadErrors(const ModelNeutralState& state) { |
250 const bool get_key_error = IsError(state.last_get_key_result); | 245 const bool get_key_error = SyncerErrorIsError(state.last_get_key_result); |
251 const bool download_updates_error = | 246 const bool download_updates_error = |
252 IsError(state.last_download_updates_result); | 247 SyncerErrorIsError(state.last_download_updates_result); |
253 const bool commit_error = IsError(state.commit_result); | 248 const bool commit_error = SyncerErrorIsError(state.commit_result); |
254 return get_key_error || download_updates_error || commit_error; | 249 return get_key_error || download_updates_error || commit_error; |
255 } | 250 } |
256 } // namespace | 251 } // namespace |
257 | 252 |
258 bool SyncSession::Succeeded() const { | 253 bool SyncSession::Succeeded() const { |
259 return finished_ && !HadErrors(status_controller_->model_neutral_state()); | 254 return finished_ && !HadErrors(status_controller_->model_neutral_state()); |
260 } | 255 } |
261 | 256 |
262 bool SyncSession::SuccessfullyReachedServer() const { | 257 bool SyncSession::SuccessfullyReachedServer() const { |
263 const ModelNeutralState& state = status_controller_->model_neutral_state(); | 258 const ModelNeutralState& state = status_controller_->model_neutral_state(); |
264 bool reached_server = state.last_get_key_result == SYNCER_OK || | 259 bool reached_server = state.last_get_key_result == SYNCER_OK || |
265 state.last_download_updates_result == SYNCER_OK; | 260 state.last_download_updates_result == SYNCER_OK; |
266 // It's possible that we reached the server on one attempt, then had an error | 261 // It's possible that we reached the server on one attempt, then had an error |
267 // on the next (or didn't perform some of the server-communicating commands). | 262 // on the next (or didn't perform some of the server-communicating commands). |
268 // We want to verify that, for all commands attempted, we successfully spoke | 263 // We want to verify that, for all commands attempted, we successfully spoke |
269 // with the server. Therefore, we verify no errors and at least one SYNCER_OK. | 264 // with the server. Therefore, we verify no errors and at least one SYNCER_OK. |
270 return reached_server && !HadErrors(state); | 265 return reached_server && !HadErrors(state); |
271 } | 266 } |
272 | 267 |
273 void SyncSession::SetFinished() { | 268 void SyncSession::SetFinished() { |
274 finished_ = true; | 269 finished_ = true; |
275 } | 270 } |
276 | 271 |
277 } // namespace sessions | 272 } // namespace sessions |
278 } // namespace syncer | 273 } // namespace syncer |
OLD | NEW |