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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 std::set_intersection(workers_.begin(), workers_.end(), | 121 std::set_intersection(workers_.begin(), workers_.end(), |
121 session.workers_.begin(), session.workers_.end(), | 122 session.workers_.begin(), session.workers_.end(), |
122 std::back_inserter(temp)); | 123 std::back_inserter(temp)); |
123 workers_.swap(temp); | 124 workers_.swap(temp); |
124 | 125 |
125 // Now update enabled groups. | 126 // Now update enabled groups. |
126 enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_); | 127 enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_); |
127 } | 128 } |
128 | 129 |
129 void SyncSession::PrepareForAnotherSyncCycle() { | 130 void SyncSession::PrepareForAnotherSyncCycle() { |
| 131 finished_ = false; |
130 source_.updates_source = | 132 source_.updates_source = |
131 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; | 133 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; |
132 status_controller_.reset(new StatusController(routing_info_)); | 134 status_controller_.reset(new StatusController(routing_info_)); |
133 } | 135 } |
134 | 136 |
135 SyncSessionSnapshot SyncSession::TakeSnapshot() const { | 137 SyncSessionSnapshot SyncSession::TakeSnapshot() const { |
136 syncable::Directory* dir = context_->directory(); | 138 syncable::Directory* dir = context_->directory(); |
137 | 139 |
138 bool is_share_useable = true; | 140 bool is_share_useable = true; |
139 syncable::ModelTypeSet initial_sync_ended; | 141 syncable::ModelTypeSet initial_sync_ended; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } | 221 } |
220 | 222 |
221 return enabled_groups_with_verified_updates; | 223 return enabled_groups_with_verified_updates; |
222 } | 224 } |
223 | 225 |
224 namespace { | 226 namespace { |
225 // Return true if the command in question was attempted and did not complete | 227 // Return true if the command in question was attempted and did not complete |
226 // successfully. | 228 // successfully. |
227 // | 229 // |
228 bool IsError(SyncerError error) { | 230 bool IsError(SyncerError error) { |
229 return error != UNSET | 231 return error != UNSET && error != SYNCER_OK; |
230 && error != SYNCER_OK; | 232 } |
| 233 |
| 234 // Returns false iff one of the command results had an error. |
| 235 bool HadErrors(const ErrorCounters& error) { |
| 236 const bool download_updates_error = |
| 237 IsError(error.last_download_updates_result); |
| 238 const bool post_commit_error = IsError(error.last_post_commit_result); |
| 239 const bool process_commit_response_error = |
| 240 IsError(error.last_process_commit_response_result); |
| 241 return download_updates_error || |
| 242 post_commit_error || |
| 243 process_commit_response_error; |
231 } | 244 } |
232 } // namespace | 245 } // namespace |
233 | 246 |
234 bool SyncSession::Succeeded() const { | 247 bool SyncSession::Succeeded() const { |
235 const bool download_updates_error = | 248 const ErrorCounters& error = status_controller_->error(); |
236 IsError(status_controller_->error().last_download_updates_result); | 249 return finished_ && !HadErrors(error); |
237 const bool post_commit_error = | 250 } |
238 IsError(status_controller_->error().last_post_commit_result); | 251 |
239 const bool process_commit_response_error = | 252 bool SyncSession::SuccessfullyReachedServer() const { |
240 IsError(status_controller_->error().last_process_commit_response_result); | 253 const ErrorCounters& error = status_controller_->error(); |
241 return !download_updates_error | 254 bool reached_server = error.last_download_updates_result == SYNCER_OK || |
242 && !post_commit_error | 255 error.last_post_commit_result == SYNCER_OK || |
243 && !process_commit_response_error; | 256 error.last_process_commit_response_result == SYNCER_OK; |
| 257 // It's possible that we reached the server on one attempt, then had an error |
| 258 // on the next (or didn't perform some of the server-communicating commands). |
| 259 // We want to verify that, for all commands attempted, we successfully spoke |
| 260 // with the server. Therefore, we verify no errors and at least one SYNCER_OK. |
| 261 return reached_server && !HadErrors(error); |
| 262 } |
| 263 |
| 264 void SyncSession::SetFinished() { |
| 265 finished_ = true; |
244 } | 266 } |
245 | 267 |
246 } // namespace sessions | 268 } // namespace sessions |
247 } // namespace browser_sync | 269 } // namespace browser_sync |
OLD | NEW |