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

Side by Side Diff: components/sync/engine_impl/get_updates_processor.cc

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. Created 4 years, 2 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
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 "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>
10
9 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
10 #include "components/sync/engine/events/get_updates_response_event.h" 12 #include "components/sync/engine/events/get_updates_response_event.h"
11 #include "components/sync/engine_impl/cycle/status_controller.h" 13 #include "components/sync/engine_impl/cycle/status_controller.h"
12 #include "components/sync/engine_impl/cycle/sync_cycle.h" 14 #include "components/sync/engine_impl/cycle/sync_cycle.h"
13 #include "components/sync/engine_impl/get_updates_delegate.h" 15 #include "components/sync/engine_impl/get_updates_delegate.h"
14 #include "components/sync/engine_impl/syncer_proto_util.h" 16 #include "components/sync/engine_impl/syncer_proto_util.h"
15 #include "components/sync/engine_impl/update_handler.h" 17 #include "components/sync/engine_impl/update_handler.h"
16 #include "components/sync/syncable/directory.h" 18 #include "components/sync/syncable/directory.h"
17 #include "components/sync/syncable/nigori_handler.h" 19 #include "components/sync/syncable/nigori_handler.h"
18 #include "components/sync/syncable/syncable_read_transaction.h" 20 #include "components/sync/syncable/syncable_read_transaction.h"
19 21
20 typedef std::vector<const sync_pb::SyncEntity*> SyncEntityList;
21 typedef std::map<syncer::ModelType, SyncEntityList> TypeSyncEntityMap;
22
23 namespace syncer { 22 namespace syncer {
24 23
24 namespace {
25
26 typedef std::vector<const sync_pb::SyncEntity*> SyncEntityList;
27 typedef std::map<ModelType, SyncEntityList> TypeSyncEntityMap;
25 typedef std::map<ModelType, size_t> TypeToIndexMap; 28 typedef std::map<ModelType, size_t> TypeToIndexMap;
26 29
27 namespace {
28
29 bool ShouldRequestEncryptionKey(SyncCycleContext* context) { 30 bool ShouldRequestEncryptionKey(SyncCycleContext* context) {
30 syncable::Directory* dir = context->directory(); 31 syncable::Directory* dir = context->directory();
31 syncable::ReadTransaction trans(FROM_HERE, dir); 32 syncable::ReadTransaction trans(FROM_HERE, dir);
32 syncable::NigoriHandler* nigori_handler = dir->GetNigoriHandler(); 33 syncable::NigoriHandler* nigori_handler = dir->GetNigoriHandler();
33 return nigori_handler->NeedKeystoreKey(&trans); 34 return nigori_handler->NeedKeystoreKey(&trans);
34 } 35 }
35 36
36 SyncerError HandleGetEncryptionKeyResponse( 37 SyncerError HandleGetEncryptionKeyResponse(
37 const sync_pb::ClientToServerResponse& update_response, 38 const sync_pb::ClientToServerResponse& update_response,
38 syncable::Directory* dir) { 39 syncable::Directory* dir) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 ModelTypeSet request_types, 278 ModelTypeSet request_types,
278 StatusController* status) { 279 StatusController* status) {
279 status->increment_num_updates_downloaded_by(gu_response.entries_size()); 280 status->increment_num_updates_downloaded_by(gu_response.entries_size());
280 281
281 // The changes remaining field is used to prevent the client from looping. If 282 // The changes remaining field is used to prevent the client from looping. If
282 // that field is being set incorrectly, we're in big trouble. 283 // that field is being set incorrectly, we're in big trouble.
283 if (!gu_response.has_changes_remaining()) { 284 if (!gu_response.has_changes_remaining()) {
284 return SERVER_RESPONSE_VALIDATION_FAILED; 285 return SERVER_RESPONSE_VALIDATION_FAILED;
285 } 286 }
286 287
287 syncer::SyncerError result = 288 SyncerError result =
288 ProcessGetUpdatesResponse(request_types, gu_response, status); 289 ProcessGetUpdatesResponse(request_types, gu_response, status);
289 if (result != syncer::SYNCER_OK) 290 if (result != SYNCER_OK)
290 return result; 291 return result;
291 292
292 if (gu_response.changes_remaining() == 0) { 293 if (gu_response.changes_remaining() == 0) {
293 return SYNCER_OK; 294 return SYNCER_OK;
294 } else { 295 } else {
295 return SERVER_MORE_TO_DOWNLOAD; 296 return SERVER_MORE_TO_DOWNLOAD;
296 } 297 }
297 } 298 }
298 299
299 syncer::SyncerError GetUpdatesProcessor::ProcessGetUpdatesResponse( 300 SyncerError GetUpdatesProcessor::ProcessGetUpdatesResponse(
300 ModelTypeSet gu_types, 301 ModelTypeSet gu_types,
301 const sync_pb::GetUpdatesResponse& gu_response, 302 const sync_pb::GetUpdatesResponse& gu_response,
302 StatusController* status_controller) { 303 StatusController* status_controller) {
303 TypeSyncEntityMap updates_by_type; 304 TypeSyncEntityMap updates_by_type;
304 PartitionUpdatesByType(gu_response, gu_types, &updates_by_type); 305 PartitionUpdatesByType(gu_response, gu_types, &updates_by_type);
305 DCHECK_EQ(gu_types.Size(), updates_by_type.size()); 306 DCHECK_EQ(gu_types.Size(), updates_by_type.size());
306 307
307 TypeToIndexMap progress_index_by_type; 308 TypeToIndexMap progress_index_by_type;
308 PartitionProgressMarkersByType(gu_response, gu_types, 309 PartitionProgressMarkersByType(gu_response, 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 syncer::SERVER_RESPONSE_VALIDATION_FAILED; 313 return 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 syncer::SyncerError result = 338 SyncerError result =
338 update_handler_iter->second->ProcessGetUpdatesResponse( 339 update_handler_iter->second->ProcessGetUpdatesResponse(
339 gu_response.new_progress_marker(progress_marker_iter->second), 340 gu_response.new_progress_marker(progress_marker_iter->second),
340 context, updates_iter->second, status_controller); 341 context, updates_iter->second, status_controller);
341 if (result != syncer::SYNCER_OK) 342 if (result != SYNCER_OK)
342 return result; 343 return result;
343 } else { 344 } else {
344 DLOG(WARNING) << "Ignoring received updates of a type we can't handle. " 345 DLOG(WARNING) << "Ignoring received updates of a type we can't handle. "
345 << "Type is: " << ModelTypeToString(type); 346 << "Type is: " << ModelTypeToString(type);
346 continue; 347 continue;
347 } 348 }
348 } 349 }
349 DCHECK(progress_marker_iter == progress_index_by_type.end() && 350 DCHECK(progress_marker_iter == progress_index_by_type.end() &&
350 updates_iter == updates_by_type.end()); 351 updates_iter == updates_by_type.end());
351 352
352 return syncer::SYNCER_OK; 353 return SYNCER_OK;
353 } 354 }
354 355
355 void GetUpdatesProcessor::ApplyUpdates(ModelTypeSet gu_types, 356 void GetUpdatesProcessor::ApplyUpdates(ModelTypeSet gu_types,
356 StatusController* status_controller) { 357 StatusController* status_controller) {
357 status_controller->set_get_updates_request_types(gu_types); 358 status_controller->set_get_updates_request_types(gu_types);
358 delegate_.ApplyUpdates(gu_types, status_controller, update_handler_map_); 359 delegate_.ApplyUpdates(gu_types, status_controller, update_handler_map_);
359 } 360 }
360 361
361 void GetUpdatesProcessor::CopyClientDebugInfo( 362 void GetUpdatesProcessor::CopyClientDebugInfo(
362 DebugInfoGetter* debug_info_getter, 363 DebugInfoGetter* debug_info_getter,
363 sync_pb::DebugInfo* debug_info) { 364 sync_pb::DebugInfo* debug_info) {
364 DVLOG(1) << "Copying client debug info to send."; 365 DVLOG(1) << "Copying client debug info to send.";
365 debug_info_getter->GetDebugInfo(debug_info); 366 debug_info_getter->GetDebugInfo(debug_info);
366 } 367 }
367 368
368 } // namespace syncer 369 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/get_updates_processor.h ('k') | components/sync/engine_impl/get_updates_processor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698