| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/sync/engine_impl/get_updates_processor.h" | 5 #include "components/sync/engine_impl/get_updates_processor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 83 } |
| 84 | 84 |
| 85 it->second.push_back(&update); | 85 it->second.push_back(&update); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Builds a map of ModelTypes to indices to progress markers in the given | 89 // Builds a map of ModelTypes to indices to progress markers in the given |
| 90 // |gu_response| message. The map is returned in the |index_map| parameter. | 90 // |gu_response| message. The map is returned in the |index_map| parameter. |
| 91 void PartitionProgressMarkersByType( | 91 void PartitionProgressMarkersByType( |
| 92 const sync_pb::GetUpdatesResponse& gu_response, | 92 const sync_pb::GetUpdatesResponse& gu_response, |
| 93 ModelTypeSet request_types, | 93 const ModelTypeSet& request_types, |
| 94 TypeToIndexMap* index_map) { | 94 TypeToIndexMap* index_map) { |
| 95 for (int i = 0; i < gu_response.new_progress_marker_size(); ++i) { | 95 for (int i = 0; i < gu_response.new_progress_marker_size(); ++i) { |
| 96 int field_number = gu_response.new_progress_marker(i).data_type_id(); | 96 int field_number = gu_response.new_progress_marker(i).data_type_id(); |
| 97 ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); | 97 ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); |
| 98 if (!IsRealDataType(model_type)) { | 98 if (!IsRealDataType(model_type)) { |
| 99 DLOG(WARNING) << "Unknown field number " << field_number; | 99 DLOG(WARNING) << "Unknown field number " << field_number; |
| 100 continue; | 100 continue; |
| 101 } | 101 } |
| 102 if (!request_types.Has(model_type)) { | 102 if (!request_types.Has(model_type)) { |
| 103 DLOG(WARNING) | 103 DLOG(WARNING) |
| 104 << "Skipping unexpected progress marker for non-enabled type " | 104 << "Skipping unexpected progress marker for non-enabled type " |
| 105 << ModelTypeToString(model_type); | 105 << ModelTypeToString(model_type); |
| 106 continue; | 106 continue; |
| 107 } | 107 } |
| 108 index_map->insert(std::make_pair(model_type, i)); | 108 index_map->insert(std::make_pair(model_type, i)); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 void PartitionContextMutationsByType( | 112 void PartitionContextMutationsByType( |
| 113 const sync_pb::GetUpdatesResponse& gu_response, | 113 const sync_pb::GetUpdatesResponse& gu_response, |
| 114 ModelTypeSet request_types, | 114 const ModelTypeSet& request_types, |
| 115 TypeToIndexMap* index_map) { | 115 TypeToIndexMap* index_map) { |
| 116 for (int i = 0; i < gu_response.context_mutations_size(); ++i) { | 116 for (int i = 0; i < gu_response.context_mutations_size(); ++i) { |
| 117 int field_number = gu_response.context_mutations(i).data_type_id(); | 117 int field_number = gu_response.context_mutations(i).data_type_id(); |
| 118 ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); | 118 ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); |
| 119 if (!IsRealDataType(model_type)) { | 119 if (!IsRealDataType(model_type)) { |
| 120 DLOG(WARNING) << "Unknown field number " << field_number; | 120 DLOG(WARNING) << "Unknown field number " << field_number; |
| 121 continue; | 121 continue; |
| 122 } | 122 } |
| 123 if (!request_types.Has(model_type)) { | 123 if (!request_types.Has(model_type)) { |
| 124 DLOG(WARNING) | 124 DLOG(WARNING) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 sync_pb::ClientToServerMessage message; | 174 sync_pb::ClientToServerMessage message; |
| 175 InitDownloadUpdatesContext(cycle, create_mobile_bookmarks_folder, &message); | 175 InitDownloadUpdatesContext(cycle, create_mobile_bookmarks_folder, &message); |
| 176 PrepareGetUpdates(*request_types, &message); | 176 PrepareGetUpdates(*request_types, &message); |
| 177 | 177 |
| 178 SyncerError result = ExecuteDownloadUpdates(request_types, cycle, &message); | 178 SyncerError result = ExecuteDownloadUpdates(request_types, cycle, &message); |
| 179 cycle->mutable_status_controller()->set_last_download_updates_result(result); | 179 cycle->mutable_status_controller()->set_last_download_updates_result(result); |
| 180 return result; | 180 return result; |
| 181 } | 181 } |
| 182 | 182 |
| 183 void GetUpdatesProcessor::PrepareGetUpdates( | 183 void GetUpdatesProcessor::PrepareGetUpdates( |
| 184 ModelTypeSet gu_types, | 184 const ModelTypeSet& gu_types, |
| 185 sync_pb::ClientToServerMessage* message) { | 185 sync_pb::ClientToServerMessage* message) { |
| 186 sync_pb::GetUpdatesMessage* get_updates = message->mutable_get_updates(); | 186 sync_pb::GetUpdatesMessage* get_updates = message->mutable_get_updates(); |
| 187 | 187 |
| 188 for (ModelTypeSet::Iterator it = gu_types.First(); it.Good(); it.Inc()) { | 188 for (ModelTypeSet::Iterator it = gu_types.First(); it.Good(); it.Inc()) { |
| 189 UpdateHandlerMap::iterator handler_it = update_handler_map_->find(it.Get()); | 189 UpdateHandlerMap::iterator handler_it = update_handler_map_->find(it.Get()); |
| 190 DCHECK(handler_it != update_handler_map_->end()) | 190 DCHECK(handler_it != update_handler_map_->end()) |
| 191 << "Failed to look up handler for " << ModelTypeToString(it.Get()); | 191 << "Failed to look up handler for " << ModelTypeToString(it.Get()); |
| 192 sync_pb::DataTypeProgressMarker* progress_marker = | 192 sync_pb::DataTypeProgressMarker* progress_marker = |
| 193 get_updates->add_from_progress_marker(); | 193 get_updates->add_from_progress_marker(); |
| 194 handler_it->second->GetDownloadProgress(progress_marker); | 194 handler_it->second->GetDownloadProgress(progress_marker); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 process_result); | 270 process_result); |
| 271 cycle->SendProtocolEvent(response_event); | 271 cycle->SendProtocolEvent(response_event); |
| 272 | 272 |
| 273 DVLOG(1) << "GetUpdates result: " << process_result; | 273 DVLOG(1) << "GetUpdates result: " << process_result; |
| 274 | 274 |
| 275 return process_result; | 275 return process_result; |
| 276 } | 276 } |
| 277 | 277 |
| 278 SyncerError GetUpdatesProcessor::ProcessResponse( | 278 SyncerError GetUpdatesProcessor::ProcessResponse( |
| 279 const sync_pb::GetUpdatesResponse& gu_response, | 279 const sync_pb::GetUpdatesResponse& gu_response, |
| 280 ModelTypeSet request_types, | 280 const ModelTypeSet& request_types, |
| 281 StatusController* status) { | 281 StatusController* status) { |
| 282 status->increment_num_updates_downloaded_by(gu_response.entries_size()); | 282 status->increment_num_updates_downloaded_by(gu_response.entries_size()); |
| 283 | 283 |
| 284 // The changes remaining field is used to prevent the client from looping. If | 284 // The changes remaining field is used to prevent the client from looping. If |
| 285 // that field is being set incorrectly, we're in big trouble. | 285 // that field is being set incorrectly, we're in big trouble. |
| 286 if (!gu_response.has_changes_remaining()) { | 286 if (!gu_response.has_changes_remaining()) { |
| 287 return SERVER_RESPONSE_VALIDATION_FAILED; | 287 return SERVER_RESPONSE_VALIDATION_FAILED; |
| 288 } | 288 } |
| 289 | 289 |
| 290 SyncerError result = | 290 SyncerError result = |
| 291 ProcessGetUpdatesResponse(request_types, gu_response, status); | 291 ProcessGetUpdatesResponse(request_types, gu_response, status); |
| 292 if (result != SYNCER_OK) | 292 if (result != SYNCER_OK) |
| 293 return result; | 293 return result; |
| 294 | 294 |
| 295 if (gu_response.changes_remaining() == 0) { | 295 if (gu_response.changes_remaining() == 0) { |
| 296 return SYNCER_OK; | 296 return SYNCER_OK; |
| 297 } else { | 297 } else { |
| 298 return SERVER_MORE_TO_DOWNLOAD; | 298 return SERVER_MORE_TO_DOWNLOAD; |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 | 301 |
| 302 SyncerError GetUpdatesProcessor::ProcessGetUpdatesResponse( | 302 SyncerError GetUpdatesProcessor::ProcessGetUpdatesResponse( |
| 303 ModelTypeSet gu_types, | 303 const ModelTypeSet& gu_types, |
| 304 const sync_pb::GetUpdatesResponse& gu_response, | 304 const sync_pb::GetUpdatesResponse& gu_response, |
| 305 StatusController* status_controller) { | 305 StatusController* status_controller) { |
| 306 TypeSyncEntityMap updates_by_type; | 306 TypeSyncEntityMap updates_by_type; |
| 307 PartitionUpdatesByType(gu_response, gu_types, &updates_by_type); | 307 PartitionUpdatesByType(gu_response, gu_types, &updates_by_type); |
| 308 DCHECK_EQ(gu_types.Size(), updates_by_type.size()); | 308 DCHECK_EQ(gu_types.Size(), updates_by_type.size()); |
| 309 | 309 |
| 310 TypeToIndexMap progress_index_by_type; | 310 TypeToIndexMap progress_index_by_type; |
| 311 PartitionProgressMarkersByType(gu_response, gu_types, | 311 PartitionProgressMarkersByType(gu_response, gu_types, |
| 312 &progress_index_by_type); | 312 &progress_index_by_type); |
| 313 if (gu_types.Size() != progress_index_by_type.size()) { | 313 if (gu_types.Size() != progress_index_by_type.size()) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 << "Type is: " << ModelTypeToString(type); | 348 << "Type is: " << ModelTypeToString(type); |
| 349 continue; | 349 continue; |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 DCHECK(progress_marker_iter == progress_index_by_type.end() && | 352 DCHECK(progress_marker_iter == progress_index_by_type.end() && |
| 353 updates_iter == updates_by_type.end()); | 353 updates_iter == updates_by_type.end()); |
| 354 | 354 |
| 355 return SYNCER_OK; | 355 return SYNCER_OK; |
| 356 } | 356 } |
| 357 | 357 |
| 358 void GetUpdatesProcessor::ApplyUpdates(ModelTypeSet gu_types, | 358 void GetUpdatesProcessor::ApplyUpdates(const ModelTypeSet& gu_types, |
| 359 StatusController* status_controller) { | 359 StatusController* status_controller) { |
| 360 status_controller->set_get_updates_request_types(gu_types); | 360 status_controller->set_get_updates_request_types(gu_types); |
| 361 delegate_.ApplyUpdates(gu_types, status_controller, update_handler_map_); | 361 delegate_.ApplyUpdates(gu_types, status_controller, update_handler_map_); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void GetUpdatesProcessor::CopyClientDebugInfo( | 364 void GetUpdatesProcessor::CopyClientDebugInfo( |
| 365 DebugInfoGetter* debug_info_getter, | 365 DebugInfoGetter* debug_info_getter, |
| 366 sync_pb::DebugInfo* debug_info) { | 366 sync_pb::DebugInfo* debug_info) { |
| 367 DVLOG(1) << "Copying client debug info to send."; | 367 DVLOG(1) << "Copying client debug info to send."; |
| 368 debug_info_getter->GetDebugInfo(debug_info); | 368 debug_info_getter->GetDebugInfo(debug_info); |
| 369 } | 369 } |
| 370 | 370 |
| 371 } // namespace syncer | 371 } // namespace syncer |
| OLD | NEW |