| 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 30 matching lines...) Expand all  Loading... | 
| 41       } | 41       } | 
| 42       // All enabled groups should have a corresponding worker. | 42       // All enabled groups should have a corresponding worker. | 
| 43       DCHECK(std::includes( | 43       DCHECK(std::includes( | 
| 44           groups_with_workers.begin(), groups_with_workers.end(), | 44           groups_with_workers.begin(), groups_with_workers.end(), | 
| 45           enabled_groups.begin(), enabled_groups.end())); | 45           enabled_groups.begin(), enabled_groups.end())); | 
| 46     } | 46     } | 
| 47   } | 47   } | 
| 48   return enabled_groups; | 48   return enabled_groups; | 
| 49 } | 49 } | 
| 50 | 50 | 
| 51 void PurgeStalePayload(ModelTypePayloadMap* original, | 51 void PurgeStaleStates(ModelTypeStateMap* original, | 
| 52                        const ModelSafeRoutingInfo& routing_info) { | 52                       const ModelSafeRoutingInfo& routing_info) { | 
| 53   std::vector<ModelTypePayloadMap::iterator> iterators_to_delete; | 53   std::vector<ModelTypeStateMap::iterator> iterators_to_delete; | 
| 54   for (ModelTypePayloadMap::iterator i = original->begin(); | 54   for (ModelTypeStateMap::iterator i = original->begin(); | 
| 55        i != original->end(); ++i) { | 55        i != original->end(); ++i) { | 
| 56     if (routing_info.end() == routing_info.find(i->first)) { | 56     if (routing_info.end() == routing_info.find(i->first)) { | 
| 57       iterators_to_delete.push_back(i); | 57       iterators_to_delete.push_back(i); | 
| 58     } | 58     } | 
| 59   } | 59   } | 
| 60 | 60 | 
| 61   for (std::vector<ModelTypePayloadMap::iterator>::iterator | 61   for (std::vector<ModelTypeStateMap::iterator>::iterator | 
| 62        it = iterators_to_delete.begin(); it != iterators_to_delete.end(); | 62        it = iterators_to_delete.begin(); it != iterators_to_delete.end(); | 
| 63        ++it) { | 63        ++it) { | 
| 64     original->erase(*it); | 64     original->erase(*it); | 
| 65   } | 65   } | 
| 66 } | 66 } | 
| 67 | 67 | 
| 68 }  // namesepace | 68 }  // namesepace | 
| 69 | 69 | 
| 70 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, | 70 SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, | 
| 71     const SyncSourceInfo& source, | 71     const SyncSourceInfo& source, | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 85 | 85 | 
| 86 SyncSession::~SyncSession() {} | 86 SyncSession::~SyncSession() {} | 
| 87 | 87 | 
| 88 void SyncSession::Coalesce(const SyncSession& session) { | 88 void SyncSession::Coalesce(const SyncSession& session) { | 
| 89   if (context_ != session.context() || delegate_ != session.delegate_) { | 89   if (context_ != session.context() || delegate_ != session.delegate_) { | 
| 90     NOTREACHED(); | 90     NOTREACHED(); | 
| 91     return; | 91     return; | 
| 92   } | 92   } | 
| 93 | 93 | 
| 94   // When we coalesce sessions, the sync update source gets overwritten with the | 94   // When we coalesce sessions, the sync update source gets overwritten with the | 
| 95   // most recent, while the type/payload map gets merged. | 95   // most recent, while the type/state map gets merged. | 
| 96   CoalescePayloads(&source_.types, session.source_.types); | 96   CoalesceStates(&source_.types, session.source_.types); | 
| 97   source_.updates_source = session.source_.updates_source; | 97   source_.updates_source = session.source_.updates_source; | 
| 98 | 98 | 
| 99   std::vector<ModelSafeWorker*> temp; | 99   std::vector<ModelSafeWorker*> temp; | 
| 100   std::set_union(workers_.begin(), workers_.end(), | 100   std::set_union(workers_.begin(), workers_.end(), | 
| 101                  session.workers_.begin(), session.workers_.end(), | 101                  session.workers_.begin(), session.workers_.end(), | 
| 102                  std::back_inserter(temp)); | 102                  std::back_inserter(temp)); | 
| 103   workers_.swap(temp); | 103   workers_.swap(temp); | 
| 104 | 104 | 
| 105   // We have to update the model safe routing info to the union. In case the | 105   // We have to update the model safe routing info to the union. In case the | 
| 106   // same key is present in both pick the one from session. | 106   // same key is present in both pick the one from session. | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 125        ++it) { | 125        ++it) { | 
| 126     if (routing_info_.find(it->first) != routing_info_.end()) { | 126     if (routing_info_.find(it->first) != routing_info_.end()) { | 
| 127       temp_routing_info[it->first] = it->second; | 127       temp_routing_info[it->first] = it->second; | 
| 128     } | 128     } | 
| 129   } | 129   } | 
| 130 | 130 | 
| 131   // Now swap it. | 131   // Now swap it. | 
| 132   routing_info_.swap(temp_routing_info); | 132   routing_info_.swap(temp_routing_info); | 
| 133 | 133 | 
| 134   // Now update the payload map. | 134   // Now update the payload map. | 
| 135   PurgeStalePayload(&source_.types, session.routing_info_); | 135   PurgeStaleStates(&source_.types, session.routing_info_); | 
| 136 | 136 | 
| 137   // Now update the workers. | 137   // Now update the workers. | 
| 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() { | 148 void SyncSession::PrepareForAnotherSyncCycle() { | 
| 149   finished_ = false; | 149   finished_ = false; | 
| 150   source_.updates_source = | 150   source_.updates_source = | 
| 151       sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; | 151       sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; | 
| 152   status_controller_.reset(new StatusController(routing_info_)); | 152   status_controller_.reset(new StatusController(routing_info_)); | 
| 153 } | 153 } | 
| 154 | 154 | 
| 155 SyncSessionSnapshot SyncSession::TakeSnapshot() const { | 155 SyncSessionSnapshot SyncSession::TakeSnapshot() const { | 
| 156   syncable::Directory* dir = context_->directory(); | 156   syncable::Directory* dir = context_->directory(); | 
| 157 | 157 | 
| 158   bool is_share_useable = true; | 158   bool is_share_useable = true; | 
| 159   ModelTypeSet initial_sync_ended; | 159   ModelTypeSet initial_sync_ended; | 
| 160   ModelTypePayloadMap download_progress_markers; | 160   ModelTypeStateMap download_progress_markers; | 
| 161   for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 161   for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 
| 162     ModelType type(ModelTypeFromInt(i)); | 162     ModelType type(ModelTypeFromInt(i)); | 
| 163     if (routing_info_.count(type) != 0) { | 163     if (routing_info_.count(type) != 0) { | 
| 164       if (dir->initial_sync_ended_for_type(type)) | 164       if (dir->initial_sync_ended_for_type(type)) | 
| 165         initial_sync_ended.Put(type); | 165         initial_sync_ended.Put(type); | 
| 166       else | 166       else | 
| 167         is_share_useable = false; | 167         is_share_useable = false; | 
| 168     } | 168     } | 
| 169     dir->GetDownloadProgressAsString(type, &download_progress_markers[type]); | 169     // TODO(dcheng): Is this correct? I'm guessing GetDownloadProgressAsString() | 
|  | 170     // shouldn't care about the ack handle... | 
|  | 171     dir->GetDownloadProgressAsString(type, | 
|  | 172                                      &download_progress_markers[type].payload); | 
| 170   } | 173   } | 
| 171 | 174 | 
| 172   return SyncSessionSnapshot( | 175   return SyncSessionSnapshot( | 
| 173       status_controller_->model_neutral_state(), | 176       status_controller_->model_neutral_state(), | 
| 174       is_share_useable, | 177       is_share_useable, | 
| 175       initial_sync_ended, | 178       initial_sync_ended, | 
| 176       download_progress_markers, | 179       download_progress_markers, | 
| 177       HasMoreToSync(), | 180       HasMoreToSync(), | 
| 178       delegate_->IsSyncingCurrentlySilenced(), | 181       delegate_->IsSyncingCurrentlySilenced(), | 
| 179       status_controller_->TotalNumEncryptionConflictingItems(), | 182       status_controller_->TotalNumEncryptionConflictingItems(), | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 264   // with the server. Therefore, we verify no errors and at least one SYNCER_OK. | 267   // with the server. Therefore, we verify no errors and at least one SYNCER_OK. | 
| 265   return reached_server && !HadErrors(state); | 268   return reached_server && !HadErrors(state); | 
| 266 } | 269 } | 
| 267 | 270 | 
| 268 void SyncSession::SetFinished() { | 271 void SyncSession::SetFinished() { | 
| 269   finished_ = true; | 272   finished_ = true; | 
| 270 } | 273 } | 
| 271 | 274 | 
| 272 }  // namespace sessions | 275 }  // namespace sessions | 
| 273 }  // namespace syncer | 276 }  // namespace syncer | 
| OLD | NEW | 
|---|