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

Unified Diff: sync/engine/download.cc

Issue 93433006: sync: Introduce ModelTypeRegistry and helpers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split the type manager Created 7 years 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 side-by-side diff with in-line comments
Download patch
Index: sync/engine/download.cc
diff --git a/sync/engine/download.cc b/sync/engine/download.cc
index 2bc7f7a0a9d35be4e85e68ce60420826057f5458..dda052c0a247b10d1367d6ce3b34e1c2b077fa8e 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"
-#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,93 +103,6 @@ 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(
@@ -211,22 +123,20 @@ void BuildNormalDownloadUpdates(
BuildNormalDownloadUpdatesImpl(
Intersection(request_types, ProtocolTypes()),
- session->context()->update_handler_map(),
+ session->context()->updater_list(),
nudge_tracker,
client_to_server_message->mutable_get_updates());
}
void BuildNormalDownloadUpdatesImpl(
ModelTypeSet proto_request_types,
- UpdateHandlerMap* update_handler_map,
+ UpdaterList* updater_list,
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.
+ updater_list->PrepareGetUpdates(proto_request_types, get_updates);
Nicolas Zea 2013/12/18 22:36:10 remind me why this is named proto_request_types, a
rlarocque 2014/01/03 01:46:41 "request": Because not all enabled types are asked
// Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information.
get_updates->mutable_caller_info()->set_source(
@@ -268,22 +178,20 @@ void BuildDownloadUpdatesForConfigure(
client_to_server_message);
BuildDownloadUpdatesForConfigureImpl(
Intersection(request_types, ProtocolTypes()),
- session->context()->update_handler_map(),
+ session->context()->updater_list(),
source,
client_to_server_message->mutable_get_updates());
}
void BuildDownloadUpdatesForConfigureImpl(
ModelTypeSet proto_request_types,
- UpdateHandlerMap* update_handler_map,
+ UpdaterList* updater_list,
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.
+ updater_list->PrepareGetUpdates(proto_request_types, get_updates);
// Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information.
get_updates->mutable_caller_info()->set_source(source);
@@ -308,20 +216,18 @@ void BuildDownloadUpdatesForPoll(
client_to_server_message);
BuildDownloadUpdatesForPollImpl(
Intersection(request_types, ProtocolTypes()),
- session->context()->update_handler_map(),
+ session->context()->updater_list(),
client_to_server_message->mutable_get_updates());
}
void BuildDownloadUpdatesForPollImpl(
ModelTypeSet proto_request_types,
- UpdateHandlerMap* update_handler_map,
+ UpdaterList* updater_list,
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.
+ updater_list->PrepareGetUpdates(proto_request_types, get_updates);
// Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information.
get_updates->mutable_caller_info()->set_source(
@@ -381,14 +287,14 @@ SyncerError ExecuteDownloadUpdates(
return ProcessResponse(update_response.get_updates(),
proto_request_types,
- session->context()->update_handler_map(),
+ session->context()->updater_list(),
status);
}
SyncerError ProcessResponse(
const sync_pb::GetUpdatesResponse& gu_response,
ModelTypeSet proto_request_types,
- UpdateHandlerMap* handler_map,
+ UpdaterList* updater_list,
StatusController* status) {
status->increment_num_updates_downloaded_by(gu_response.entries_size());
@@ -400,10 +306,9 @@ SyncerError ProcessResponse(
status->set_num_server_changes_remaining(gu_response.changes_remaining());
- if (!ProcessUpdateResponseContents(gu_response,
- proto_request_types,
- handler_map,
- status)) {
+ if (!updater_list->ProcessGetUpdatesResponse(proto_request_types,
+ gu_response,
+ status)) {
return SERVER_RESPONSE_VALIDATION_FAILED;
}

Powered by Google App Engine
This is Rietveld 408576698