Chromium Code Reviews| Index: sync/engine/download.cc |
| diff --git a/sync/engine/download.cc b/sync/engine/download.cc |
| index 2bc7f7a0a9d35be4e85e68ce60420826057f5458..ad547912e516db8bef82a867a4cb1dca787d7e0c 100644 |
| --- a/sync/engine/download.cc |
| +++ b/sync/engine/download.cc |
| @@ -8,7 +8,6 @@ |
| #include "base/command_line.h" |
| #include "sync/engine/process_updates_util.h" |
|
tim (not reviewing)
2014/01/16 18:28:22
I don't think we need this here now.
rlarocque
2014/01/16 20:28:42
Removed.
|
| -#include "sync/engine/sync_directory_update_handler.h" |
| #include "sync/engine/syncer.h" |
| #include "sync/engine/syncer_proto_util.h" |
| #include "sync/sessions/nudge_tracker.h" |
| @@ -104,97 +103,11 @@ void InitDownloadUpdatesContext( |
| session->context()->notifications_enabled()); |
| } |
| -void InitDownloadUpdatesProgress( |
| - ModelTypeSet proto_request_types, |
| - UpdateHandlerMap* handler_map, |
| - sync_pb::GetUpdatesMessage* get_updates) { |
| - for (ModelTypeSet::Iterator it = proto_request_types.First(); |
| - it.Good(); it.Inc()) { |
| - UpdateHandlerMap::iterator handler_it = handler_map->find(it.Get()); |
| - DCHECK(handler_it != handler_map->end()); |
| - sync_pb::DataTypeProgressMarker* progress_marker = |
| - get_updates->add_from_progress_marker(); |
| - handler_it->second->GetDownloadProgress(progress_marker); |
| - } |
| -} |
| - |
| -// Builds a map of ModelTypes to indices to progress markers in the given |
| -// |gu_response| message. The map is returned in the |index_map| parameter. |
| -void PartitionProgressMarkersByType( |
| - const sync_pb::GetUpdatesResponse& gu_response, |
| - ModelTypeSet request_types, |
| - TypeToIndexMap* index_map) { |
| - for (int i = 0; i < gu_response.new_progress_marker_size(); ++i) { |
| - int field_number = gu_response.new_progress_marker(i).data_type_id(); |
| - ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); |
| - if (!IsRealDataType(model_type)) { |
| - DLOG(WARNING) << "Unknown field number " << field_number; |
| - continue; |
| - } |
| - if (!request_types.Has(model_type)) { |
| - DLOG(WARNING) |
| - << "Skipping unexpected progress marker for non-enabled type " |
| - << ModelTypeToString(model_type); |
| - continue; |
| - } |
| - index_map->insert(std::make_pair(model_type, i)); |
| - } |
| -} |
| - |
| -// Examines the contents of the GetUpdates response message and forwards |
| -// relevant data to the UpdateHandlers for processing and persisting. |
| -bool ProcessUpdateResponseContents( |
| - const sync_pb::GetUpdatesResponse& gu_response, |
| - ModelTypeSet proto_request_types, |
| - UpdateHandlerMap* handler_map, |
| - StatusController* status) { |
| - TypeSyncEntityMap updates_by_type; |
| - PartitionUpdatesByType(gu_response, proto_request_types, &updates_by_type); |
| - DCHECK_EQ(proto_request_types.Size(), updates_by_type.size()); |
| - |
| - TypeToIndexMap progress_index_by_type; |
| - PartitionProgressMarkersByType(gu_response, |
| - proto_request_types, |
| - &progress_index_by_type); |
| - if (proto_request_types.Size() != progress_index_by_type.size()) { |
| - NOTREACHED() << "Missing progress markers in GetUpdates response."; |
| - return false; |
| - } |
| - |
| - // Iterate over these maps in parallel, processing updates for each type. |
| - TypeToIndexMap::iterator progress_marker_iter = |
| - progress_index_by_type.begin(); |
| - TypeSyncEntityMap::iterator updates_iter = updates_by_type.begin(); |
| - for ( ; (progress_marker_iter != progress_index_by_type.end() |
| - && updates_iter != updates_by_type.end()); |
| - ++progress_marker_iter, ++updates_iter) { |
| - DCHECK_EQ(progress_marker_iter->first, updates_iter->first); |
| - ModelType type = progress_marker_iter->first; |
| - |
| - UpdateHandlerMap::iterator update_handler_iter = handler_map->find(type); |
| - |
| - if (update_handler_iter != handler_map->end()) { |
| - update_handler_iter->second->ProcessGetUpdatesResponse( |
| - gu_response.new_progress_marker(progress_marker_iter->second), |
| - updates_iter->second, |
| - status); |
| - } else { |
| - DLOG(WARNING) |
| - << "Ignoring received updates of a type we can't handle. " |
| - << "Type is: " << ModelTypeToString(type); |
| - continue; |
| - } |
| - } |
| - DCHECK(progress_marker_iter == progress_index_by_type.end() |
| - && updates_iter == updates_by_type.end()); |
| - |
| - return true; |
| -} |
| - |
| } // namespace |
| void BuildNormalDownloadUpdates( |
| SyncSession* session, |
| + GetUpdatesProcessor* get_updates_processor, |
| bool create_mobile_bookmarks_folder, |
| ModelTypeSet request_types, |
| const sessions::NudgeTracker& nudge_tracker, |
| @@ -211,22 +124,20 @@ void BuildNormalDownloadUpdates( |
| BuildNormalDownloadUpdatesImpl( |
| Intersection(request_types, ProtocolTypes()), |
| - session->context()->update_handler_map(), |
| + get_updates_processor, |
| nudge_tracker, |
| client_to_server_message->mutable_get_updates()); |
| } |
| void BuildNormalDownloadUpdatesImpl( |
| ModelTypeSet proto_request_types, |
| - UpdateHandlerMap* update_handler_map, |
| + GetUpdatesProcessor* get_updates_processor, |
| const sessions::NudgeTracker& nudge_tracker, |
| sync_pb::GetUpdatesMessage* get_updates) { |
| DCHECK(!proto_request_types.Empty()); |
| - InitDownloadUpdatesProgress( |
| - proto_request_types, |
| - update_handler_map, |
| - get_updates); |
| + // Get progress markers and other data for requested types. |
| + get_updates_processor->PrepareGetUpdates(proto_request_types, get_updates); |
| // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information. |
| get_updates->mutable_caller_info()->set_source( |
| @@ -254,6 +165,7 @@ void BuildNormalDownloadUpdatesImpl( |
| void BuildDownloadUpdatesForConfigure( |
| SyncSession* session, |
| + GetUpdatesProcessor* get_updates_processor, |
| bool create_mobile_bookmarks_folder, |
| sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
| ModelTypeSet request_types, |
| @@ -268,22 +180,20 @@ void BuildDownloadUpdatesForConfigure( |
| client_to_server_message); |
| BuildDownloadUpdatesForConfigureImpl( |
| Intersection(request_types, ProtocolTypes()), |
| - session->context()->update_handler_map(), |
| + get_updates_processor, |
| source, |
| client_to_server_message->mutable_get_updates()); |
| } |
| void BuildDownloadUpdatesForConfigureImpl( |
| ModelTypeSet proto_request_types, |
| - UpdateHandlerMap* update_handler_map, |
| + GetUpdatesProcessor* get_updates_processor, |
| sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
| sync_pb::GetUpdatesMessage* get_updates) { |
| DCHECK(!proto_request_types.Empty()); |
| - InitDownloadUpdatesProgress( |
| - proto_request_types, |
| - update_handler_map, |
| - get_updates); |
| + // Get progress markers and other data for requested types. |
| + get_updates_processor->PrepareGetUpdates(proto_request_types, get_updates); |
| // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information. |
| get_updates->mutable_caller_info()->set_source(source); |
| @@ -296,6 +206,7 @@ void BuildDownloadUpdatesForConfigureImpl( |
| void BuildDownloadUpdatesForPoll( |
| SyncSession* session, |
| + GetUpdatesProcessor* get_updates_processor, |
| bool create_mobile_bookmarks_folder, |
| ModelTypeSet request_types, |
| sync_pb::ClientToServerMessage* client_to_server_message) { |
| @@ -308,20 +219,18 @@ void BuildDownloadUpdatesForPoll( |
| client_to_server_message); |
| BuildDownloadUpdatesForPollImpl( |
| Intersection(request_types, ProtocolTypes()), |
| - session->context()->update_handler_map(), |
| + get_updates_processor, |
| client_to_server_message->mutable_get_updates()); |
| } |
| void BuildDownloadUpdatesForPollImpl( |
| ModelTypeSet proto_request_types, |
| - UpdateHandlerMap* update_handler_map, |
| + GetUpdatesProcessor* get_updates_processor, |
| sync_pb::GetUpdatesMessage* get_updates) { |
| DCHECK(!proto_request_types.Empty()); |
| - InitDownloadUpdatesProgress( |
| - proto_request_types, |
| - update_handler_map, |
| - get_updates); |
| + // Get progress markers and other data for requested types. |
| + get_updates_processor->PrepareGetUpdates(proto_request_types, get_updates); |
| // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information. |
| get_updates->mutable_caller_info()->set_source( |
| @@ -334,6 +243,7 @@ void BuildDownloadUpdatesForPollImpl( |
| SyncerError ExecuteDownloadUpdates( |
| ModelTypeSet request_types, |
| SyncSession* session, |
| + GetUpdatesProcessor* get_updates_processor, |
| sync_pb::ClientToServerMessage* msg) { |
| sync_pb::ClientToServerResponse update_response; |
| StatusController* status = session->mutable_status_controller(); |
| @@ -381,14 +291,14 @@ SyncerError ExecuteDownloadUpdates( |
| return ProcessResponse(update_response.get_updates(), |
| proto_request_types, |
| - session->context()->update_handler_map(), |
| + get_updates_processor, |
| status); |
| } |
| SyncerError ProcessResponse( |
| const sync_pb::GetUpdatesResponse& gu_response, |
| ModelTypeSet proto_request_types, |
| - UpdateHandlerMap* handler_map, |
| + GetUpdatesProcessor* get_updates_processor, |
| StatusController* status) { |
| status->increment_num_updates_downloaded_by(gu_response.entries_size()); |
| @@ -400,10 +310,9 @@ SyncerError ProcessResponse( |
| status->set_num_server_changes_remaining(gu_response.changes_remaining()); |
| - if (!ProcessUpdateResponseContents(gu_response, |
| - proto_request_types, |
| - handler_map, |
| - status)) { |
| + if (!get_updates_processor->ProcessGetUpdatesResponse(proto_request_types, |
| + gu_response, |
| + status)) { |
| return SERVER_RESPONSE_VALIDATION_FAILED; |
| } |