Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: sync/engine/get_updates_processor.cc

Issue 232003005: [Sync] Add support for retrying a getupdates due to a context change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/get_updates_processor.h ('k') | sync/engine/non_blocking_type_processor_core.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "sync/engine/get_updates_processor.h" 5 #include "sync/engine/get_updates_processor.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "sync/engine/get_updates_delegate.h" 10 #include "sync/engine/get_updates_delegate.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 sessions::StatusController* status) { 277 sessions::StatusController* status) {
278 status->increment_num_updates_downloaded_by(gu_response.entries_size()); 278 status->increment_num_updates_downloaded_by(gu_response.entries_size());
279 279
280 // The changes remaining field is used to prevent the client from looping. If 280 // The changes remaining field is used to prevent the client from looping. If
281 // that field is being set incorrectly, we're in big trouble. 281 // that field is being set incorrectly, we're in big trouble.
282 if (!gu_response.has_changes_remaining()) { 282 if (!gu_response.has_changes_remaining()) {
283 return SERVER_RESPONSE_VALIDATION_FAILED; 283 return SERVER_RESPONSE_VALIDATION_FAILED;
284 } 284 }
285 status->set_num_server_changes_remaining(gu_response.changes_remaining()); 285 status->set_num_server_changes_remaining(gu_response.changes_remaining());
286 286
287 if (!ProcessGetUpdatesResponse(request_types, gu_response, status)) { 287 syncer::SyncerError result =
288 return SERVER_RESPONSE_VALIDATION_FAILED; 288 ProcessGetUpdatesResponse(request_types, gu_response, status);
289 } 289 if (result != syncer::SYNCER_OK)
290 return result;
290 291
291 if (gu_response.changes_remaining() == 0) { 292 if (gu_response.changes_remaining() == 0) {
292 return SYNCER_OK; 293 return SYNCER_OK;
293 } else { 294 } else {
294 return SERVER_MORE_TO_DOWNLOAD; 295 return SERVER_MORE_TO_DOWNLOAD;
295 } 296 }
296 } 297 }
297 298
298 bool GetUpdatesProcessor::ProcessGetUpdatesResponse( 299 syncer::SyncerError GetUpdatesProcessor::ProcessGetUpdatesResponse(
299 ModelTypeSet gu_types, 300 ModelTypeSet gu_types,
300 const sync_pb::GetUpdatesResponse& gu_response, 301 const sync_pb::GetUpdatesResponse& gu_response,
301 sessions::StatusController* status_controller) { 302 sessions::StatusController* status_controller) {
302 TypeSyncEntityMap updates_by_type; 303 TypeSyncEntityMap updates_by_type;
303 PartitionUpdatesByType(gu_response, gu_types, &updates_by_type); 304 PartitionUpdatesByType(gu_response, gu_types, &updates_by_type);
304 DCHECK_EQ(gu_types.Size(), updates_by_type.size()); 305 DCHECK_EQ(gu_types.Size(), updates_by_type.size());
305 306
306 TypeToIndexMap progress_index_by_type; 307 TypeToIndexMap progress_index_by_type;
307 PartitionProgressMarkersByType(gu_response, 308 PartitionProgressMarkersByType(gu_response,
308 gu_types, 309 gu_types,
309 &progress_index_by_type); 310 &progress_index_by_type);
310 if (gu_types.Size() != progress_index_by_type.size()) { 311 if (gu_types.Size() != progress_index_by_type.size()) {
311 NOTREACHED() << "Missing progress markers in GetUpdates response."; 312 NOTREACHED() << "Missing progress markers in GetUpdates response.";
312 return false; 313 return syncer::SERVER_RESPONSE_VALIDATION_FAILED;
313 } 314 }
314 315
315 TypeToIndexMap context_by_type; 316 TypeToIndexMap context_by_type;
316 PartitionContextMutationsByType(gu_response, gu_types, &context_by_type); 317 PartitionContextMutationsByType(gu_response, gu_types, &context_by_type);
317 318
318 // Iterate over these maps in parallel, processing updates for each type. 319 // Iterate over these maps in parallel, processing updates for each type.
319 TypeToIndexMap::iterator progress_marker_iter = 320 TypeToIndexMap::iterator progress_marker_iter =
320 progress_index_by_type.begin(); 321 progress_index_by_type.begin();
321 TypeSyncEntityMap::iterator updates_iter = updates_by_type.begin(); 322 TypeSyncEntityMap::iterator updates_iter = updates_by_type.begin();
322 for (; (progress_marker_iter != progress_index_by_type.end() 323 for (; (progress_marker_iter != progress_index_by_type.end()
323 && updates_iter != updates_by_type.end()); 324 && updates_iter != updates_by_type.end());
324 ++progress_marker_iter, ++updates_iter) { 325 ++progress_marker_iter, ++updates_iter) {
325 DCHECK_EQ(progress_marker_iter->first, updates_iter->first); 326 DCHECK_EQ(progress_marker_iter->first, updates_iter->first);
326 ModelType type = progress_marker_iter->first; 327 ModelType type = progress_marker_iter->first;
327 328
328 UpdateHandlerMap::iterator update_handler_iter = 329 UpdateHandlerMap::iterator update_handler_iter =
329 update_handler_map_->find(type); 330 update_handler_map_->find(type);
330 331
331 sync_pb::DataTypeContext context; 332 sync_pb::DataTypeContext context;
332 TypeToIndexMap::iterator context_iter = context_by_type.find(type); 333 TypeToIndexMap::iterator context_iter = context_by_type.find(type);
333 if (context_iter != context_by_type.end()) 334 if (context_iter != context_by_type.end())
334 context.CopyFrom(gu_response.context_mutations(context_iter->second)); 335 context.CopyFrom(gu_response.context_mutations(context_iter->second));
335 336
336 if (update_handler_iter != update_handler_map_->end()) { 337 if (update_handler_iter != update_handler_map_->end()) {
337 update_handler_iter->second->ProcessGetUpdatesResponse( 338 if (!update_handler_iter->second->ProcessGetUpdatesResponse(
rlarocque 2014/04/10 01:15:29 Could we have ProcessGetUpdatesResponse return an
Nicolas Zea 2014/04/10 19:06:26 Done.
338 gu_response.new_progress_marker(progress_marker_iter->second), 339 gu_response.new_progress_marker(progress_marker_iter->second),
339 context, 340 context,
340 updates_iter->second, 341 updates_iter->second,
341 status_controller); 342 status_controller)) {
343 return syncer::DATATYPE_TRIGGERED_RETRY;
344 }
342 } else { 345 } else {
343 DLOG(WARNING) 346 DLOG(WARNING)
344 << "Ignoring received updates of a type we can't handle. " 347 << "Ignoring received updates of a type we can't handle. "
345 << "Type is: " << ModelTypeToString(type); 348 << "Type is: " << ModelTypeToString(type);
346 continue; 349 continue;
347 } 350 }
348 } 351 }
349 DCHECK(progress_marker_iter == progress_index_by_type.end() && 352 DCHECK(progress_marker_iter == progress_index_by_type.end() &&
350 updates_iter == updates_by_type.end()); 353 updates_iter == updates_by_type.end());
351 354
352 return true; 355 return syncer::SYNCER_OK;
353 } 356 }
354 357
355 void GetUpdatesProcessor::ApplyUpdates( 358 void GetUpdatesProcessor::ApplyUpdates(
356 ModelTypeSet gu_types, 359 ModelTypeSet gu_types,
357 sessions::StatusController* status_controller) { 360 sessions::StatusController* status_controller) {
358 delegate_.ApplyUpdates(gu_types, status_controller, update_handler_map_); 361 delegate_.ApplyUpdates(gu_types, status_controller, update_handler_map_);
359 } 362 }
360 363
361 void GetUpdatesProcessor::CopyClientDebugInfo( 364 void GetUpdatesProcessor::CopyClientDebugInfo(
362 sessions::DebugInfoGetter* debug_info_getter, 365 sessions::DebugInfoGetter* debug_info_getter,
363 sync_pb::DebugInfo* debug_info) { 366 sync_pb::DebugInfo* debug_info) {
364 DVLOG(1) << "Copying client debug info to send."; 367 DVLOG(1) << "Copying client debug info to send.";
365 debug_info_getter->GetDebugInfo(debug_info); 368 debug_info_getter->GetDebugInfo(debug_info);
366 } 369 }
367 370
368 } // namespace syncer 371 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/get_updates_processor.h ('k') | sync/engine/non_blocking_type_processor_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698