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

Unified Diff: sync/engine/syncer.cc

Issue 93433006: sync: Introduce ModelTypeRegistry and helpers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leak in tests Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/engine/syncer.h ('k') | sync/engine/syncer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/engine/syncer.cc
diff --git a/sync/engine/syncer.cc b/sync/engine/syncer.cc
index e75c1c691c3a0c2a18bf54787901e46117cfd581..339948d1ff95eb3d7c45bcfd50d2b33e17455000 100644
--- a/sync/engine/syncer.cc
+++ b/sync/engine/syncer.cc
@@ -12,8 +12,10 @@
#include "build/build_config.h"
#include "sync/engine/apply_control_data_updates.h"
#include "sync/engine/commit.h"
+#include "sync/engine/commit_processor.h"
#include "sync/engine/conflict_resolver.h"
#include "sync/engine/download.h"
+#include "sync/engine/get_updates_processor.h"
#include "sync/engine/net/server_connection_manager.h"
#include "sync/engine/syncer_types.h"
#include "sync/internal_api/public/base/cancelation_signal.h"
@@ -56,14 +58,18 @@ bool Syncer::NormalSyncShare(ModelTypeSet request_types,
const NudgeTracker& nudge_tracker,
SyncSession* session) {
HandleCycleBegin(session);
+ GetUpdatesProcessor get_updates_processor(
+ session->context()->model_type_registry()->update_handler_map());
VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types);
if (nudge_tracker.IsGetUpdatesRequired(base::TimeTicks::Now()) ||
session->context()->ShouldFetchUpdatesBeforeCommit()) {
if (!DownloadAndApplyUpdates(
request_types,
session,
+ &get_updates_processor,
base::Bind(&download::BuildNormalDownloadUpdates,
session,
+ &get_updates_processor,
kCreateMobileBookmarksFolder,
request_types,
base::ConstRef(nudge_tracker)))) {
@@ -72,7 +78,10 @@ bool Syncer::NormalSyncShare(ModelTypeSet request_types,
}
VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types);
- SyncerError commit_result = BuildAndPostCommits(request_types, session);
+ CommitProcessor commit_processor(
+ session->context()->model_type_registry()->commit_contributor_map());
+ SyncerError commit_result =
+ BuildAndPostCommits(request_types, session, &commit_processor);
session->mutable_status_controller()->set_commit_result(commit_result);
return HandleCycleEnd(session, nudge_tracker.updates_source());
@@ -83,12 +92,16 @@ bool Syncer::ConfigureSyncShare(
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
SyncSession* session) {
HandleCycleBegin(session);
+ GetUpdatesProcessor get_updates_processor(
+ session->context()->model_type_registry()->update_handler_map());
VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types);
DownloadAndApplyUpdates(
request_types,
session,
+ &get_updates_processor,
base::Bind(&download::BuildDownloadUpdatesForConfigure,
session,
+ &get_updates_processor,
kCreateMobileBookmarksFolder,
source,
request_types));
@@ -98,12 +111,16 @@ bool Syncer::ConfigureSyncShare(
bool Syncer::PollSyncShare(ModelTypeSet request_types,
SyncSession* session) {
HandleCycleBegin(session);
+ GetUpdatesProcessor get_updates_processor(
+ session->context()->model_type_registry()->update_handler_map());
VLOG(1) << "Polling types " << ModelTypeSetToString(request_types);
DownloadAndApplyUpdates(
request_types,
session,
+ &get_updates_processor,
base::Bind(&download::BuildDownloadUpdatesForPoll,
session,
+ &get_updates_processor,
kCreateMobileBookmarksFolder,
request_types));
return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::PERIODIC);
@@ -112,27 +129,29 @@ bool Syncer::PollSyncShare(ModelTypeSet request_types,
bool Syncer::RetrySyncShare(ModelTypeSet request_types,
SyncSession* session) {
HandleCycleBegin(session);
+ GetUpdatesProcessor get_updates_processor(
+ session->context()->model_type_registry()->update_handler_map());
VLOG(1) << "Retrying types " << ModelTypeSetToString(request_types);
DownloadAndApplyUpdates(
request_types,
session,
+ &get_updates_processor,
base::Bind(&download::BuildDownloadUpdatesForRetry,
session,
+ &get_updates_processor,
kCreateMobileBookmarksFolder,
request_types));
return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::RETRY);
}
-void Syncer::ApplyUpdates(SyncSession* session) {
+void Syncer::ApplyUpdates(SyncSession* session,
+ GetUpdatesProcessor* get_updates_processor) {
TRACE_EVENT0("sync", "ApplyUpdates");
ApplyControlDataUpdates(session->context()->directory());
- UpdateHandlerMap* handler_map = session->context()->update_handler_map();
- for (UpdateHandlerMap::iterator it = handler_map->begin();
- it != handler_map->end(); ++it) {
- it->second->ApplyUpdates(session->mutable_status_controller());
- }
+ get_updates_processor->ApplyUpdatesForAllTypes(
+ session->mutable_status_controller());
session->context()->set_hierarchy_conflict_detected(
session->status_controller().num_hierarchy_conflicts() > 0);
@@ -143,14 +162,17 @@ void Syncer::ApplyUpdates(SyncSession* session) {
bool Syncer::DownloadAndApplyUpdates(
ModelTypeSet request_types,
SyncSession* session,
+ GetUpdatesProcessor* get_updates_processor,
base::Callback<void(sync_pb::ClientToServerMessage*)> build_fn) {
SyncerError download_result = UNSET;
do {
TRACE_EVENT0("sync", "DownloadUpdates");
sync_pb::ClientToServerMessage msg;
build_fn.Run(&msg);
- download_result =
- download::ExecuteDownloadUpdates(request_types, session, &msg);
+ download_result = download::ExecuteDownloadUpdates(request_types,
+ session,
+ get_updates_processor,
+ &msg);
session->mutable_status_controller()->set_last_download_updates_result(
download_result);
} while (download_result == SERVER_MORE_TO_DOWNLOAD);
@@ -161,14 +183,15 @@ bool Syncer::DownloadAndApplyUpdates(
if (ExitRequested())
return false;
- ApplyUpdates(session);
+ ApplyUpdates(session, get_updates_processor);
if (ExitRequested())
return false;
return true;
}
SyncerError Syncer::BuildAndPostCommits(ModelTypeSet requested_types,
- sessions::SyncSession* session) {
+ sessions::SyncSession* session,
+ CommitProcessor* commit_processor) {
// The ExitRequested() check is unnecessary, since we should start getting
// errors from the ServerConnectionManager if an exist has been requested.
// However, it doesn't hurt to check it anyway.
@@ -176,10 +199,11 @@ SyncerError Syncer::BuildAndPostCommits(ModelTypeSet requested_types,
scoped_ptr<Commit> commit(
Commit::Init(
requested_types,
+ session->context()->enabled_types(),
session->context()->max_commit_batch_size(),
session->context()->account_name(),
session->context()->directory()->cache_guid(),
- session->context()->commit_contributor_map(),
+ commit_processor,
session->context()->extensions_activity()));
if (!commit) {
break;
« no previous file with comments | « sync/engine/syncer.h ('k') | sync/engine/syncer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698