| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 std::vector<ModelSafeWorker*> temp; | 138 std::vector<ModelSafeWorker*> temp; |
| 139 std::set_intersection(workers_.begin(), workers_.end(), | 139 std::set_intersection(workers_.begin(), workers_.end(), |
| 140 session.workers_.begin(), session.workers_.end(), | 140 session.workers_.begin(), session.workers_.end(), |
| 141 std::back_inserter(temp)); | 141 std::back_inserter(temp)); |
| 142 workers_.swap(temp); | 142 workers_.swap(temp); |
| 143 | 143 |
| 144 // Now update enabled groups. | 144 // Now update enabled groups. |
| 145 enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_); | 145 enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void SyncSession::PrepareForAnotherSyncCycle() { | |
| 149 finished_ = false; | |
| 150 source_.updates_source = | |
| 151 sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; | |
| 152 status_controller_.reset(new StatusController(routing_info_)); | |
| 153 } | |
| 154 | |
| 155 SyncSessionSnapshot SyncSession::TakeSnapshot() const { | 148 SyncSessionSnapshot SyncSession::TakeSnapshot() const { |
| 156 syncable::Directory* dir = context_->directory(); | 149 syncable::Directory* dir = context_->directory(); |
| 157 | 150 |
| 158 bool is_share_useable = true; | 151 bool is_share_useable = true; |
| 159 ModelTypeSet initial_sync_ended; | 152 ModelTypeSet initial_sync_ended; |
| 160 ProgressMarkerMap download_progress_markers; | 153 ProgressMarkerMap download_progress_markers; |
| 161 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 154 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 162 ModelType type(ModelTypeFromInt(i)); | 155 ModelType type(ModelTypeFromInt(i)); |
| 163 if (routing_info_.count(type) != 0) { | 156 if (routing_info_.count(type) != 0) { |
| 164 if (dir->initial_sync_ended_for_type(type)) | 157 if (dir->initial_sync_ended_for_type(type)) |
| 165 initial_sync_ended.Put(type); | 158 initial_sync_ended.Put(type); |
| 166 else | 159 else |
| 167 is_share_useable = false; | 160 is_share_useable = false; |
| 168 } | 161 } |
| 169 dir->GetDownloadProgressAsString(type, &download_progress_markers[type]); | 162 dir->GetDownloadProgressAsString(type, &download_progress_markers[type]); |
| 170 } | 163 } |
| 171 | 164 |
| 172 return SyncSessionSnapshot( | 165 return SyncSessionSnapshot( |
| 173 status_controller_->model_neutral_state(), | 166 status_controller_->model_neutral_state(), |
| 174 is_share_useable, | 167 is_share_useable, |
| 175 initial_sync_ended, | 168 initial_sync_ended, |
| 176 download_progress_markers, | 169 download_progress_markers, |
| 177 HasMoreToSync(), | |
| 178 delegate_->IsSyncingCurrentlySilenced(), | 170 delegate_->IsSyncingCurrentlySilenced(), |
| 179 status_controller_->num_encryption_conflicts(), | 171 status_controller_->num_encryption_conflicts(), |
| 180 status_controller_->num_hierarchy_conflicts(), | 172 status_controller_->num_hierarchy_conflicts(), |
| 181 status_controller_->num_simple_conflicts(), | |
| 182 status_controller_->num_server_conflicts(), | 173 status_controller_->num_server_conflicts(), |
| 183 source_, | 174 source_, |
| 184 context_->notifications_enabled(), | 175 context_->notifications_enabled(), |
| 185 dir->GetEntriesCount(), | 176 dir->GetEntriesCount(), |
| 186 status_controller_->sync_start_time(), | 177 status_controller_->sync_start_time(), |
| 187 !Succeeded()); | 178 !Succeeded()); |
| 188 } | 179 } |
| 189 | 180 |
| 190 void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) { | 181 void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) { |
| 191 SyncEngineEvent event(cause); | 182 SyncEngineEvent event(cause); |
| 192 event.snapshot = TakeSnapshot(); | 183 event.snapshot = TakeSnapshot(); |
| 193 | 184 |
| 194 DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString(); | 185 DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString(); |
| 195 context()->NotifyListeners(event); | 186 context()->NotifyListeners(event); |
| 196 } | 187 } |
| 197 | 188 |
| 198 bool SyncSession::HasMoreToSync() const { | |
| 199 const StatusController* status = status_controller_.get(); | |
| 200 return status->conflicts_resolved(); | |
| 201 } | |
| 202 | |
| 203 const std::set<ModelSafeGroup>& SyncSession::GetEnabledGroups() const { | 189 const std::set<ModelSafeGroup>& SyncSession::GetEnabledGroups() const { |
| 204 return enabled_groups_; | 190 return enabled_groups_; |
| 205 } | 191 } |
| 206 | 192 |
| 207 // TODO(rlarocque): Delete this function after refactoring conflict resolution. | |
| 208 std::set<ModelSafeGroup> SyncSession::GetEnabledGroupsWithConflicts() const { | |
| 209 const std::set<ModelSafeGroup>& enabled_groups = GetEnabledGroups(); | |
| 210 std::set<ModelSafeGroup> enabled_groups_with_conflicts; | |
| 211 for (std::set<ModelSafeGroup>::const_iterator it = | |
| 212 enabled_groups.begin(); it != enabled_groups.end(); ++it) { | |
| 213 const std::set<syncable::Id>* ids = | |
| 214 status_controller_->GetUnrestrictedSimpleConflictIds(*it); | |
| 215 if (ids && ids->size() > 0) { | |
| 216 enabled_groups_with_conflicts.insert(*it); | |
| 217 } | |
| 218 } | |
| 219 return enabled_groups_with_conflicts; | |
| 220 } | |
| 221 | |
| 222 namespace { | 193 namespace { |
| 223 | 194 |
| 224 // Returns false iff one of the command results had an error. | 195 // Returns false iff one of the command results had an error. |
| 225 bool HadErrors(const ModelNeutralState& state) { | 196 bool HadErrors(const ModelNeutralState& state) { |
| 226 const bool get_key_error = SyncerErrorIsError(state.last_get_key_result); | 197 const bool get_key_error = SyncerErrorIsError(state.last_get_key_result); |
| 227 const bool download_updates_error = | 198 const bool download_updates_error = |
| 228 SyncerErrorIsError(state.last_download_updates_result); | 199 SyncerErrorIsError(state.last_download_updates_result); |
| 229 const bool commit_error = SyncerErrorIsError(state.commit_result); | 200 const bool commit_error = SyncerErrorIsError(state.commit_result); |
| 230 return get_key_error || download_updates_error || commit_error; | 201 return get_key_error || download_updates_error || commit_error; |
| 231 } | 202 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 245 // with the server. Therefore, we verify no errors and at least one SYNCER_OK. | 216 // with the server. Therefore, we verify no errors and at least one SYNCER_OK. |
| 246 return reached_server && !HadErrors(state); | 217 return reached_server && !HadErrors(state); |
| 247 } | 218 } |
| 248 | 219 |
| 249 void SyncSession::SetFinished() { | 220 void SyncSession::SetFinished() { |
| 250 finished_ = true; | 221 finished_ = true; |
| 251 } | 222 } |
| 252 | 223 |
| 253 } // namespace sessions | 224 } // namespace sessions |
| 254 } // namespace syncer | 225 } // namespace syncer |
| OLD | NEW |