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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, | 52 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, |
53 const SyncSourceInfo& source, | 53 const SyncSourceInfo& source, |
54 const ModelSafeRoutingInfo& routing_info, | 54 const ModelSafeRoutingInfo& routing_info, |
55 const std::vector<ModelSafeWorker*>& workers) | 55 const std::vector<ModelSafeWorker*>& workers) |
56 : context_(context), | 56 : context_(context), |
57 source_(source), | 57 source_(source), |
58 write_transaction_(NULL), | 58 write_transaction_(NULL), |
59 delegate_(delegate), | 59 delegate_(delegate), |
60 workers_(workers), | 60 workers_(workers), |
61 routing_info_(routing_info), | 61 routing_info_(routing_info), |
62 enabled_groups_(ComputeEnabledGroups(routing_info_, workers_)) { | 62 enabled_groups_(ComputeEnabledGroups(routing_info_, workers_)), |
| 63 finished_(false) { |
63 status_controller_.reset(new StatusController(routing_info_)); | 64 status_controller_.reset(new StatusController(routing_info_)); |
64 std::sort(workers_.begin(), workers_.end()); | 65 std::sort(workers_.begin(), workers_.end()); |
65 } | 66 } |
66 | 67 |
67 SyncSession::~SyncSession() {} | 68 SyncSession::~SyncSession() {} |
68 | 69 |
69 void SyncSession::Coalesce(const SyncSession& session) { | 70 void SyncSession::Coalesce(const SyncSession& session) { |
70 if (context_ != session.context() || delegate_ != session.delegate_) { | 71 if (context_ != session.context() || delegate_ != session.delegate_) { |
71 NOTREACHED(); | 72 NOTREACHED(); |
72 return; | 73 return; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } | 220 } |
220 | 221 |
221 return enabled_groups_with_verified_updates; | 222 return enabled_groups_with_verified_updates; |
222 } | 223 } |
223 | 224 |
224 namespace { | 225 namespace { |
225 // Return true if the command in question was attempted and did not complete | 226 // Return true if the command in question was attempted and did not complete |
226 // successfully. | 227 // successfully. |
227 // | 228 // |
228 bool IsError(SyncerError error) { | 229 bool IsError(SyncerError error) { |
229 return error != UNSET | 230 return error != UNSET && error != SYNCER_OK; |
230 && error != SYNCER_OK; | 231 } |
| 232 |
| 233 // Returns false iff one of the command results had an error. |
| 234 bool HadErrors(const ErrorCounters& error) { |
| 235 const bool download_updates_error = |
| 236 IsError(error.last_download_updates_result); |
| 237 const bool post_commit_error = IsError(error.last_post_commit_result); |
| 238 const bool process_commit_response_error = |
| 239 IsError(error.last_process_commit_response_result); |
| 240 return download_updates_error || |
| 241 post_commit_error || |
| 242 process_commit_response_error; |
231 } | 243 } |
232 } // namespace | 244 } // namespace |
233 | 245 |
234 bool SyncSession::Succeeded() const { | 246 bool SyncSession::Succeeded() const { |
235 const bool download_updates_error = | 247 const ErrorCounters& error = status_controller_->error(); |
236 IsError(status_controller_->error().last_download_updates_result); | 248 return finished_ && !HadErrors(error); |
237 const bool post_commit_error = | 249 } |
238 IsError(status_controller_->error().last_post_commit_result); | 250 |
239 const bool process_commit_response_error = | 251 bool SyncSession::SuccessfullyReachServer() const { |
240 IsError(status_controller_->error().last_process_commit_response_result); | 252 const ErrorCounters& error = status_controller_->error(); |
241 return !download_updates_error | 253 bool reach_server = false; |
242 && !post_commit_error | 254 if (error.last_download_updates_result == SYNCER_OK || |
243 && !process_commit_response_error; | 255 error.last_post_commit_result == SYNCER_OK || |
| 256 error.last_process_commit_response_result == SYNCER_OK) |
| 257 reach_server = true; |
| 258 return reach_server && !HadErrors(error); |
| 259 } |
| 260 |
| 261 void SyncSession::SetFinished() { |
| 262 finished_ = true; |
244 } | 263 } |
245 | 264 |
246 } // namespace sessions | 265 } // namespace sessions |
247 } // namespace browser_sync | 266 } // namespace browser_sync |
OLD | NEW |