| 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   ModelTypeStateMap download_progress_markers; |  153   ModelTypeStateMap 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     // TODO(dcheng): Is this correct? I'm guessing GetDownloadProgressAsString() |  162     // TODO(dcheng): Is this correct? I'm guessing GetDownloadProgressAsString() | 
|  170     // shouldn't care about the ack handle... |  163     // shouldn't care about the ack handle... | 
|  171     dir->GetDownloadProgressAsString(type, |  164     dir->GetDownloadProgressAsString(type, | 
|  172                                      &download_progress_markers[type].payload); |  165                                      &download_progress_markers[type].payload); | 
|  173   } |  166   } | 
|  174  |  167  | 
|  175   return SyncSessionSnapshot( |  168   return SyncSessionSnapshot( | 
|  176       status_controller_->model_neutral_state(), |  169       status_controller_->model_neutral_state(), | 
|  177       is_share_useable, |  170       is_share_useable, | 
|  178       initial_sync_ended, |  171       initial_sync_ended, | 
|  179       download_progress_markers, |  172       download_progress_markers, | 
|  180       HasMoreToSync(), |  173       false, // FIXME: clean up. | 
|  181       delegate_->IsSyncingCurrentlySilenced(), |  174       delegate_->IsSyncingCurrentlySilenced(), | 
|  182       status_controller_->TotalNumEncryptionConflictingItems(), |  175       status_controller_->num_encryption_conflicts(), | 
|  183       status_controller_->TotalNumHierarchyConflictingItems(), |  176       status_controller_->num_hierarchy_conflicts(), | 
|  184       status_controller_->TotalNumSimpleConflictingItems(), |  177       0, // FIXME: clean up. | 
|  185       status_controller_->TotalNumServerConflictingItems(), |  178       status_controller_->num_server_conflicts(), | 
|  186       source_, |  179       source_, | 
|  187       context_->notifications_enabled(), |  180       context_->notifications_enabled(), | 
|  188       dir->GetEntriesCount(), |  181       dir->GetEntriesCount(), | 
|  189       status_controller_->sync_start_time(), |  182       status_controller_->sync_start_time(), | 
|  190       !Succeeded()); |  183       !Succeeded()); | 
|  191 } |  184 } | 
|  192  |  185  | 
|  193 void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) { |  186 void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) { | 
|  194   SyncEngineEvent event(cause); |  187   SyncEngineEvent event(cause); | 
|  195   event.snapshot = TakeSnapshot(); |  188   event.snapshot = TakeSnapshot(); | 
|  196  |  189  | 
|  197   DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString(); |  190   DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString(); | 
|  198   context()->NotifyListeners(event); |  191   context()->NotifyListeners(event); | 
|  199 } |  192 } | 
|  200  |  193  | 
|  201 bool SyncSession::HasMoreToSync() const { |  | 
|  202   const StatusController* status = status_controller_.get(); |  | 
|  203   return status->conflicts_resolved(); |  | 
|  204 } |  | 
|  205  |  | 
|  206 const std::set<ModelSafeGroup>& SyncSession::GetEnabledGroups() const { |  194 const std::set<ModelSafeGroup>& SyncSession::GetEnabledGroups() const { | 
|  207   return enabled_groups_; |  195   return enabled_groups_; | 
|  208 } |  196 } | 
|  209  |  197  | 
|  210 std::set<ModelSafeGroup> SyncSession::GetEnabledGroupsWithConflicts() const { |  | 
|  211   const std::set<ModelSafeGroup>& enabled_groups = GetEnabledGroups(); |  | 
|  212   std::set<ModelSafeGroup> enabled_groups_with_conflicts; |  | 
|  213   for (std::set<ModelSafeGroup>::const_iterator it = |  | 
|  214            enabled_groups.begin(); it != enabled_groups.end(); ++it) { |  | 
|  215     const sessions::ConflictProgress* conflict_progress = |  | 
|  216         status_controller_->GetUnrestrictedConflictProgress(*it); |  | 
|  217     if (conflict_progress && |  | 
|  218         (conflict_progress->SimpleConflictingItemsBegin() != |  | 
|  219          conflict_progress->SimpleConflictingItemsEnd())) { |  | 
|  220       enabled_groups_with_conflicts.insert(*it); |  | 
|  221     } |  | 
|  222   } |  | 
|  223   return enabled_groups_with_conflicts; |  | 
|  224 } |  | 
|  225  |  | 
|  226 std::set<ModelSafeGroup> |  | 
|  227     SyncSession::GetEnabledGroupsWithVerifiedUpdates() const { |  | 
|  228   const std::set<ModelSafeGroup>& enabled_groups = GetEnabledGroups(); |  | 
|  229   std::set<ModelSafeGroup> enabled_groups_with_verified_updates; |  | 
|  230   for (std::set<ModelSafeGroup>::const_iterator it = |  | 
|  231            enabled_groups.begin(); it != enabled_groups.end(); ++it) { |  | 
|  232     const UpdateProgress* update_progress = |  | 
|  233         status_controller_->GetUnrestrictedUpdateProgress(*it); |  | 
|  234     if (update_progress && |  | 
|  235         (update_progress->VerifiedUpdatesBegin() != |  | 
|  236          update_progress->VerifiedUpdatesEnd())) { |  | 
|  237       enabled_groups_with_verified_updates.insert(*it); |  | 
|  238     } |  | 
|  239   } |  | 
|  240  |  | 
|  241   return enabled_groups_with_verified_updates; |  | 
|  242 } |  | 
|  243  |  | 
|  244 namespace { |  198 namespace { | 
|  245  |  199  | 
|  246 // Returns false iff one of the command results had an error. |  200 // Returns false iff one of the command results had an error. | 
|  247 bool HadErrors(const ModelNeutralState& state) { |  201 bool HadErrors(const ModelNeutralState& state) { | 
|  248   const bool get_key_error = SyncerErrorIsError(state.last_get_key_result); |  202   const bool get_key_error = SyncerErrorIsError(state.last_get_key_result); | 
|  249   const bool download_updates_error = |  203   const bool download_updates_error = | 
|  250       SyncerErrorIsError(state.last_download_updates_result); |  204       SyncerErrorIsError(state.last_download_updates_result); | 
|  251   const bool commit_error = SyncerErrorIsError(state.commit_result); |  205   const bool commit_error = SyncerErrorIsError(state.commit_result); | 
|  252   return get_key_error || download_updates_error || commit_error; |  206   return get_key_error || download_updates_error || commit_error; | 
|  253 } |  207 } | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|  267   // with the server. Therefore, we verify no errors and at least one SYNCER_OK. |  221   // with the server. Therefore, we verify no errors and at least one SYNCER_OK. | 
|  268   return reached_server && !HadErrors(state); |  222   return reached_server && !HadErrors(state); | 
|  269 } |  223 } | 
|  270  |  224  | 
|  271 void SyncSession::SetFinished() { |  225 void SyncSession::SetFinished() { | 
|  272   finished_ = true; |  226   finished_ = true; | 
|  273 } |  227 } | 
|  274  |  228  | 
|  275 }  // namespace sessions |  229 }  // namespace sessions | 
|  276 }  // namespace syncer |  230 }  // namespace syncer | 
| OLD | NEW |