Index: sync/sessions/sync_session.cc |
diff --git a/sync/sessions/sync_session.cc b/sync/sessions/sync_session.cc |
index 5a2b572d8a1b5a9092ef0c8a3e15a4799df805db..9be78d89f4cef2277e3ae0fc27da81ae8fd1c56f 100644 |
--- a/sync/sessions/sync_session.cc |
+++ b/sync/sessions/sync_session.cc |
@@ -77,8 +77,7 @@ SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, |
delegate_(delegate), |
workers_(workers), |
routing_info_(routing_info), |
- enabled_groups_(ComputeEnabledGroups(routing_info_, workers_)), |
- finished_(false) { |
+ enabled_groups_(ComputeEnabledGroups(routing_info_, workers_)) { |
status_controller_.reset(new StatusController(routing_info_)); |
std::sort(workers_.begin(), workers_.end()); |
} |
@@ -115,30 +114,31 @@ void SyncSession::Coalesce(const SyncSession& session) { |
enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_); |
} |
-void SyncSession::RebaseRoutingInfoWithLatest(const SyncSession& session) { |
+void SyncSession::RebaseRoutingInfoWithLatest( |
+ const ModelSafeRoutingInfo& routing_info, |
+ const std::vector<ModelSafeWorker*>& workers) { |
ModelSafeRoutingInfo temp_routing_info; |
- // Take the intersecion and also set the routing info(it->second) from the |
+ // Take the intersection and also set the routing info(it->second) from the |
// passed in session. |
for (ModelSafeRoutingInfo::const_iterator it = |
- session.routing_info_.begin(); it != session.routing_info_.end(); |
+ routing_info.begin(); it != routing_info.end(); |
++it) { |
if (routing_info_.find(it->first) != routing_info_.end()) { |
temp_routing_info[it->first] = it->second; |
} |
} |
- |
- // Now swap it. |
routing_info_.swap(temp_routing_info); |
- // Now update the payload map. |
- PurgeStaleStates(&source_.types, session.routing_info_); |
+ PurgeStaleStates(&source_.types, routing_info); |
// Now update the workers. |
std::vector<ModelSafeWorker*> temp; |
+ std::vector<ModelSafeWorker*> sorted_workers = workers; |
+ std::sort(sorted_workers.begin(), sorted_workers.end()); |
std::set_intersection(workers_.begin(), workers_.end(), |
- session.workers_.begin(), session.workers_.end(), |
- std::back_inserter(temp)); |
+ sorted_workers.begin(), sorted_workers.end(), |
+ std::back_inserter(temp)); |
workers_.swap(temp); |
// Now update enabled groups. |
@@ -146,7 +146,6 @@ void SyncSession::RebaseRoutingInfoWithLatest(const SyncSession& session) { |
} |
void SyncSession::PrepareForAnotherSyncCycle() { |
- finished_ = false; |
source_.updates_source = |
sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; |
status_controller_.reset(new StatusController(routing_info_)); |
@@ -183,8 +182,7 @@ SyncSessionSnapshot SyncSession::TakeSnapshot() const { |
source_, |
context_->notifications_enabled(), |
dir->GetEntriesCount(), |
- status_controller_->sync_start_time(), |
- !Succeeded()); |
+ status_controller_->sync_start_time()); |
} |
void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) { |
@@ -219,35 +217,11 @@ std::set<ModelSafeGroup> SyncSession::GetEnabledGroupsWithConflicts() const { |
return enabled_groups_with_conflicts; |
} |
-namespace { |
- |
-// Returns false iff one of the command results had an error. |
-bool HadErrors(const ModelNeutralState& state) { |
- const bool get_key_error = SyncerErrorIsError(state.last_get_key_result); |
- const bool download_updates_error = |
- SyncerErrorIsError(state.last_download_updates_result); |
- const bool commit_error = SyncerErrorIsError(state.commit_result); |
- return get_key_error || download_updates_error || commit_error; |
-} |
-} // namespace |
- |
-bool SyncSession::Succeeded() const { |
- return finished_ && !HadErrors(status_controller_->model_neutral_state()); |
-} |
- |
-bool SyncSession::SuccessfullyReachedServer() const { |
+bool SyncSession::DidReachServer() const { |
const ModelNeutralState& state = status_controller_->model_neutral_state(); |
- bool reached_server = state.last_get_key_result == SYNCER_OK || |
- state.last_download_updates_result == SYNCER_OK; |
- // It's possible that we reached the server on one attempt, then had an error |
- // on the next (or didn't perform some of the server-communicating commands). |
- // We want to verify that, for all commands attempted, we successfully spoke |
- // with the server. Therefore, we verify no errors and at least one SYNCER_OK. |
- return reached_server && !HadErrors(state); |
-} |
- |
-void SyncSession::SetFinished() { |
- finished_ = true; |
+ return state.last_get_key_result >= FIRST_SERVER_RETURN_VALUE || |
+ state.last_download_updates_result >= FIRST_SERVER_RETURN_VALUE || |
+ state.commit_result >= FIRST_SERVER_RETURN_VALUE; |
} |
} // namespace sessions |