summaryrefslogtreecommitdiffstats
path: root/sync/engine
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-12 08:45:16 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-12 08:45:16 +0000
commitc9daa4305bf8b1cc578ce8017518c474fa38afe9 (patch)
tree8c9851cee0c9d2244d3aee1b2ac42a3338e4c290 /sync/engine
parentb9ec2e016bb556029d10c45a15a864948370f62d (diff)
downloadchromium_src-c9daa4305bf8b1cc578ce8017518c474fa38afe9.zip
chromium_src-c9daa4305bf8b1cc578ce8017518c474fa38afe9.tar.gz
chromium_src-c9daa4305bf8b1cc578ce8017518c474fa38afe9.tar.bz2
This is the clean-up following r249138.
Introduce a GetUpdatesDelegate class to contain request behavior that is specific to a GU type. There are implementations for Normal, Retry, Poll and Configure GUs. These implementations may have different members. For example, only the 'Normal' GU requires a NudgeTracker. They also implement different functionality for building the request message and for applying the received updates. The latter is to allow the configure GetUpdates to apply updates directly on the sync thread. The GU types can still vary in other ways that are not encapsulated in the GU delegate. For example, the Poll GU is not retried on failure, though this is not expressed in its GU delegate in any way. BUG=278484 Review URL: https://codereview.chromium.org/137753010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/engine')
-rw-r--r--sync/engine/download.cc214
-rw-r--r--sync/engine/download.h69
-rw-r--r--sync/engine/download_unittest.cc136
-rw-r--r--sync/engine/get_updates_delegate.cc155
-rw-r--r--sync/engine/get_updates_delegate.h124
-rw-r--r--sync/engine/get_updates_processor.cc22
-rw-r--r--sync/engine/get_updates_processor.h15
-rw-r--r--sync/engine/sync_scheduler_impl.cc4
-rw-r--r--sync/engine/syncer.cc136
-rw-r--r--sync/engine/syncer.h6
10 files changed, 446 insertions, 435 deletions
diff --git a/sync/engine/download.cc b/sync/engine/download.cc
index 16e6de3..def78dd 100644
--- a/sync/engine/download.cc
+++ b/sync/engine/download.cc
@@ -6,10 +6,9 @@
#include <string>
-#include "base/command_line.h"
-#include "sync/engine/syncer.h"
#include "sync/engine/syncer_proto_util.h"
-#include "sync/sessions/nudge_tracker.h"
+#include "sync/sessions/sync_session.h"
+#include "sync/sessions/sync_session_context.h"
#include "sync/syncable/directory.h"
#include "sync/syncable/nigori_handler.h"
#include "sync/syncable/syncable_read_transaction.h"
@@ -21,12 +20,8 @@ using sessions::SyncSession;
using sessions::SyncSessionContext;
using std::string;
-namespace download {
-
namespace {
-typedef std::map<ModelType, size_t> TypeToIndexMap;
-
SyncerError HandleGetEncryptionKeyResponse(
const sync_pb::ClientToServerResponse& update_response,
syncable::Directory* dir) {
@@ -48,24 +43,6 @@ SyncerError HandleGetEncryptionKeyResponse(
return (success ? SYNCER_OK : SERVER_RESPONSE_VALIDATION_FAILED);
}
-sync_pb::SyncEnums::GetUpdatesOrigin ConvertConfigureSourceToOrigin(
- sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
- switch (source) {
- // Configurations:
- case sync_pb::GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE:
- return sync_pb::SyncEnums::NEWLY_SUPPORTED_DATATYPE;
- case sync_pb::GetUpdatesCallerInfo::MIGRATION:
- return sync_pb::SyncEnums::MIGRATION;
- case sync_pb::GetUpdatesCallerInfo::RECONFIGURATION:
- return sync_pb::SyncEnums::RECONFIGURATION;
- case sync_pb::GetUpdatesCallerInfo::NEW_CLIENT:
- return sync_pb::SyncEnums::NEW_CLIENT;
- default:
- NOTREACHED();
- return sync_pb::SyncEnums::UNKNOWN_ORIGIN;
- }
-}
-
bool ShouldRequestEncryptionKey(
SyncSessionContext* context) {
bool need_encryption_key = false;
@@ -78,6 +55,10 @@ bool ShouldRequestEncryptionKey(
return need_encryption_key;
}
+} // namespace
+
+namespace download {
+
void InitDownloadUpdatesContext(
SyncSession* session,
bool create_mobile_bookmarks_folder,
@@ -102,180 +83,6 @@ void InitDownloadUpdatesContext(
session->context()->notifications_enabled());
}
-} // namespace
-
-void BuildNormalDownloadUpdates(
- SyncSession* session,
- GetUpdatesProcessor* get_updates_processor,
- bool create_mobile_bookmarks_folder,
- ModelTypeSet request_types,
- const sessions::NudgeTracker& nudge_tracker,
- sync_pb::ClientToServerMessage* client_to_server_message) {
- // Request updates for all requested types.
- DVLOG(1) << "Getting updates for types "
- << ModelTypeSetToString(request_types);
- DCHECK(!request_types.Empty());
-
- InitDownloadUpdatesContext(
- session,
- create_mobile_bookmarks_folder,
- client_to_server_message);
-
- BuildNormalDownloadUpdatesImpl(
- Intersection(request_types, ProtocolTypes()),
- get_updates_processor,
- nudge_tracker,
- client_to_server_message->mutable_get_updates());
-}
-
-void BuildNormalDownloadUpdatesImpl(
- ModelTypeSet proto_request_types,
- GetUpdatesProcessor* get_updates_processor,
- const sessions::NudgeTracker& nudge_tracker,
- sync_pb::GetUpdatesMessage* get_updates) {
- DCHECK(!proto_request_types.Empty());
-
- // 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(
- nudge_tracker.updates_source());
-
- // Set the new and improved version of source, too.
- get_updates->set_get_updates_origin(sync_pb::SyncEnums::GU_TRIGGER);
- get_updates->set_is_retry(nudge_tracker.IsRetryRequired());
-
- // Fill in the notification hints.
- for (int i = 0; i < get_updates->from_progress_marker_size(); ++i) {
- sync_pb::DataTypeProgressMarker* progress_marker =
- get_updates->mutable_from_progress_marker(i);
- ModelType type = GetModelTypeFromSpecificsFieldNumber(
- progress_marker->data_type_id());
-
- DCHECK(!nudge_tracker.IsTypeThrottled(type))
- << "Throttled types should have been removed from the request_types.";
-
- nudge_tracker.SetLegacyNotificationHint(type, progress_marker);
- nudge_tracker.FillProtoMessage(
- type,
- progress_marker->mutable_get_update_triggers());
- }
-}
-
-void BuildDownloadUpdatesForConfigure(
- SyncSession* session,
- GetUpdatesProcessor* get_updates_processor,
- bool create_mobile_bookmarks_folder,
- sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
- ModelTypeSet request_types,
- sync_pb::ClientToServerMessage* client_to_server_message) {
- // Request updates for all enabled types.
- DVLOG(1) << "Initial download for types "
- << ModelTypeSetToString(request_types);
-
- InitDownloadUpdatesContext(
- session,
- create_mobile_bookmarks_folder,
- client_to_server_message);
- BuildDownloadUpdatesForConfigureImpl(
- Intersection(request_types, ProtocolTypes()),
- get_updates_processor,
- source,
- client_to_server_message->mutable_get_updates());
-}
-
-void BuildDownloadUpdatesForConfigureImpl(
- ModelTypeSet proto_request_types,
- GetUpdatesProcessor* get_updates_processor,
- sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
- sync_pb::GetUpdatesMessage* get_updates) {
- DCHECK(!proto_request_types.Empty());
-
- // 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);
-
- // Set the new and improved version of source, too.
- sync_pb::SyncEnums::GetUpdatesOrigin origin =
- ConvertConfigureSourceToOrigin(source);
- get_updates->set_get_updates_origin(origin);
-}
-
-void BuildDownloadUpdatesForPoll(
- SyncSession* session,
- GetUpdatesProcessor* get_updates_processor,
- bool create_mobile_bookmarks_folder,
- ModelTypeSet request_types,
- sync_pb::ClientToServerMessage* client_to_server_message) {
- DVLOG(1) << "Polling for types "
- << ModelTypeSetToString(request_types);
-
- InitDownloadUpdatesContext(
- session,
- create_mobile_bookmarks_folder,
- client_to_server_message);
- BuildDownloadUpdatesForPollImpl(
- Intersection(request_types, ProtocolTypes()),
- get_updates_processor,
- client_to_server_message->mutable_get_updates());
-}
-
-void BuildDownloadUpdatesForPollImpl(
- ModelTypeSet proto_request_types,
- GetUpdatesProcessor* get_updates_processor,
- sync_pb::GetUpdatesMessage* get_updates) {
- DCHECK(!proto_request_types.Empty());
-
- // 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(
- sync_pb::GetUpdatesCallerInfo::PERIODIC);
-
- // Set the new and improved version of source, too.
- get_updates->set_get_updates_origin(sync_pb::SyncEnums::PERIODIC);
-}
-
-void BuildDownloadUpdatesForRetry(
- SyncSession* session,
- GetUpdatesProcessor* get_updates_processor,
- bool create_mobile_bookmarks_folder,
- ModelTypeSet request_types,
- sync_pb::ClientToServerMessage* client_to_server_message) {
- DVLOG(1) << "Retrying for types "
- << ModelTypeSetToString(request_types);
-
- InitDownloadUpdatesContext(
- session,
- create_mobile_bookmarks_folder,
- client_to_server_message);
- BuildDownloadUpdatesForRetryImpl(
- Intersection(request_types, ProtocolTypes()),
- get_updates_processor,
- client_to_server_message->mutable_get_updates());
-}
-
-void BuildDownloadUpdatesForRetryImpl(
- ModelTypeSet proto_request_types,
- GetUpdatesProcessor* get_updates_processor,
- sync_pb::GetUpdatesMessage* get_updates) {
- DCHECK(!proto_request_types.Empty());
-
- get_updates_processor->PrepareGetUpdates(proto_request_types, get_updates);
-
- // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information.
- get_updates->mutable_caller_info()->set_source(
- sync_pb::GetUpdatesCallerInfo::RETRY);
-
- // Set the new and improved version of source, too.
- get_updates->set_get_updates_origin(sync_pb::SyncEnums::RETRY);
- get_updates->set_is_retry(true);
-}
-
SyncerError ExecuteDownloadUpdates(
ModelTypeSet request_types,
SyncSession* session,
@@ -322,18 +129,15 @@ SyncerError ExecuteDownloadUpdates(
HandleGetEncryptionKeyResponse(update_response, dir));
}
- const ModelTypeSet proto_request_types =
- Intersection(request_types, ProtocolTypes());
-
return ProcessResponse(update_response.get_updates(),
- proto_request_types,
+ request_types,
get_updates_processor,
status);
}
SyncerError ProcessResponse(
const sync_pb::GetUpdatesResponse& gu_response,
- ModelTypeSet proto_request_types,
+ ModelTypeSet request_types,
GetUpdatesProcessor* get_updates_processor,
StatusController* status) {
status->increment_num_updates_downloaded_by(gu_response.entries_size());
@@ -346,7 +150,7 @@ SyncerError ProcessResponse(
status->set_num_server_changes_remaining(gu_response.changes_remaining());
- if (!get_updates_processor->ProcessGetUpdatesResponse(proto_request_types,
+ if (!get_updates_processor->ProcessGetUpdatesResponse(request_types,
gu_response,
status)) {
return SERVER_RESPONSE_VALIDATION_FAILED;
diff --git a/sync/engine/download.h b/sync/engine/download.h
index 22a3a42..0eeca97 100644
--- a/sync/engine/download.h
+++ b/sync/engine/download.h
@@ -19,80 +19,17 @@ namespace syncer {
namespace sessions {
class DebugInfoGetter;
-class NudgeTracker;
class StatusController;
class SyncSession;
} // namespace sessions
namespace download {
-// This function executes a single GetUpdate request and stores the response in
-// the session's StatusController. It constructs the type of request used to
-// keep types in sync when in normal mode.
-SYNC_EXPORT_PRIVATE void BuildNormalDownloadUpdates(
+// Generic initialization of a GetUpdates message.
+SYNC_EXPORT_PRIVATE void InitDownloadUpdatesContext(
sessions::SyncSession* session,
- GetUpdatesProcessor* get_updates_processor,
bool create_mobile_bookmarks_folder,
- ModelTypeSet request_types,
- const sessions::NudgeTracker& nudge_tracker,
- sync_pb::ClientToServerMessage* client_to_server_message);
-
-// Helper function. Defined here for testing.
-SYNC_EXPORT_PRIVATE void BuildNormalDownloadUpdatesImpl(
- ModelTypeSet proto_request_types,
- GetUpdatesProcessor* get_updates_processor,
- const sessions::NudgeTracker& nudge_tracker,
- sync_pb::GetUpdatesMessage* get_updates);
-
-// This function executes a single GetUpdate request and stores the response in
-// the session's StatusController. It constructs the type of request used to
-// initialize a type for the first time.
-SYNC_EXPORT_PRIVATE void BuildDownloadUpdatesForConfigure(
- sessions::SyncSession* session,
- GetUpdatesProcessor* get_updates_processor,
- bool create_mobile_bookmarks_folder,
- sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
- ModelTypeSet request_types,
- sync_pb::ClientToServerMessage* client_to_server_message);
-
-// Helper function. Defined here for testing.
-SYNC_EXPORT_PRIVATE void BuildDownloadUpdatesForConfigureImpl(
- ModelTypeSet proto_request_types,
- GetUpdatesProcessor* get_updates_processor,
- sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
- sync_pb::GetUpdatesMessage* get_updates);
-
-// This function executes a single GetUpdate request and stores the response in
-// the session's status controller. It constructs the type of request used for
-// periodic polling.
-SYNC_EXPORT_PRIVATE void BuildDownloadUpdatesForPoll(
- sessions::SyncSession* session,
- GetUpdatesProcessor* get_updates_processor,
- bool create_mobile_bookmarks_folder,
- ModelTypeSet request_types,
- sync_pb::ClientToServerMessage* client_to_server_message);
-
-// Helper function. Defined here for testing.
-SYNC_EXPORT_PRIVATE void BuildDownloadUpdatesForPollImpl(
- ModelTypeSet proto_request_types,
- GetUpdatesProcessor* get_updates_processor,
- sync_pb::GetUpdatesMessage* get_updates);
-
-// Same as BuildDownloadUpdatesForPoll() except the update origin/source is
-// RETRY.
-SYNC_EXPORT_PRIVATE void BuildDownloadUpdatesForRetry(
- sessions::SyncSession* session,
- GetUpdatesProcessor* get_updates_processor,
- bool create_mobile_bookmarks_folder,
- ModelTypeSet request_types,
- sync_pb::ClientToServerMessage* client_to_server_message);
-
-// Same as BuildDownloadUpdatesForPollImpl() except the update origin/source is
-// RETRY.
-SYNC_EXPORT_PRIVATE void BuildDownloadUpdatesForRetryImpl(
- ModelTypeSet proto_request_types,
- GetUpdatesProcessor* get_updates_processor,
- sync_pb::GetUpdatesMessage* get_updates);
+ sync_pb::ClientToServerMessage* message);
// Sends the specified message to the server and stores the response in a member
// of the |session|'s StatusController.
diff --git a/sync/engine/download_unittest.cc b/sync/engine/download_unittest.cc
index c0462bc..1a0c5b9 100644
--- a/sync/engine/download_unittest.cc
+++ b/sync/engine/download_unittest.cc
@@ -6,6 +6,7 @@
#include "base/message_loop/message_loop.h"
#include "base/stl_util.h"
+#include "sync/engine/get_updates_delegate.h"
#include "sync/engine/sync_directory_update_handler.h"
#include "sync/internal_api/public/base/model_type_test_util.h"
#include "sync/protocol/sync.pb.h"
@@ -41,20 +42,22 @@ class DownloadUpdatesTest : public ::testing::Test {
dir_maker_.TearDown();
}
- ModelTypeSet proto_request_types() {
- return proto_request_types_;
+ ModelTypeSet request_types() {
+ return request_types_;
}
syncable::Directory* directory() {
return dir_maker_.directory();
}
- GetUpdatesProcessor* get_updates_processor() {
- return get_updates_processor_.get();
+ scoped_ptr<GetUpdatesProcessor> BuildGetUpdatesProcessor(
+ const GetUpdatesDelegate& delegate) {
+ return scoped_ptr<GetUpdatesProcessor>(
+ new GetUpdatesProcessor(&update_handler_map_, delegate));
}
void InitFakeUpdateResponse(sync_pb::GetUpdatesResponse* response) {
- ModelTypeSet types = proto_request_types();
+ ModelTypeSet types = request_types();
for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) {
sync_pb::DataTypeProgressMarker* marker =
@@ -72,19 +75,18 @@ class DownloadUpdatesTest : public ::testing::Test {
void AddUpdateHandler(ModelType type, ModelSafeGroup group) {
DCHECK(directory());
- proto_request_types_.Put(type);
+ request_types_.Put(type);
scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(group);
SyncDirectoryUpdateHandler* handler =
new SyncDirectoryUpdateHandler(directory(), type, worker);
update_handler_map_.insert(std::make_pair(type, handler));
- get_updates_processor_.reset(new GetUpdatesProcessor(&update_handler_map_));
}
base::MessageLoop loop_; // Needed for directory init.
TestDirectorySetterUpper dir_maker_;
- ModelTypeSet proto_request_types_;
+ ModelTypeSet request_types_;
UpdateHandlerMap update_handler_map_;
STLValueDeleter<UpdateHandlerMap> update_handler_deleter_;
scoped_ptr<GetUpdatesProcessor> get_updates_processor_;
@@ -97,13 +99,12 @@ TEST_F(DownloadUpdatesTest, BookmarkNudge) {
sessions::NudgeTracker nudge_tracker;
nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS));
- sync_pb::ClientToServerMessage msg;
- download::BuildNormalDownloadUpdatesImpl(proto_request_types(),
- get_updates_processor(),
- nudge_tracker,
- msg.mutable_get_updates());
+ sync_pb::GetUpdatesMessage gu_msg;
+ NormalGetUpdatesDelegate normal_delegate(nudge_tracker);
+ scoped_ptr<GetUpdatesProcessor> processor(
+ BuildGetUpdatesProcessor(normal_delegate));
+ processor->PrepareGetUpdates(request_types(), &gu_msg);
- const sync_pb::GetUpdatesMessage& gu_msg = msg.get_updates();
EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL,
gu_msg.caller_info().source());
EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin());
@@ -145,13 +146,12 @@ TEST_F(DownloadUpdatesTest, NotifyMany) {
notified_types.Put(BOOKMARKS);
notified_types.Put(PREFERENCES);
- sync_pb::ClientToServerMessage msg;
- download::BuildNormalDownloadUpdatesImpl(proto_request_types(),
- get_updates_processor(),
- nudge_tracker,
- msg.mutable_get_updates());
+ sync_pb::GetUpdatesMessage gu_msg;
+ NormalGetUpdatesDelegate normal_delegate(nudge_tracker);
+ scoped_ptr<GetUpdatesProcessor> processor(
+ BuildGetUpdatesProcessor(normal_delegate));
+ processor->PrepareGetUpdates(request_types(), &gu_msg);
- const sync_pb::GetUpdatesMessage& gu_msg = msg.get_updates();
EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION,
gu_msg.caller_info().source());
EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin());
@@ -178,14 +178,12 @@ TEST_F(DownloadUpdatesTest, NotifyMany) {
}
TEST_F(DownloadUpdatesTest, ConfigureTest) {
- sync_pb::ClientToServerMessage msg;
- download::BuildDownloadUpdatesForConfigureImpl(
- proto_request_types(),
- get_updates_processor(),
- sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
- msg.mutable_get_updates());
-
- const sync_pb::GetUpdatesMessage& gu_msg = msg.get_updates();
+ sync_pb::GetUpdatesMessage gu_msg;
+ ConfigureGetUpdatesDelegate configure_delegate(
+ sync_pb::GetUpdatesCallerInfo::RECONFIGURATION);
+ scoped_ptr<GetUpdatesProcessor> processor(
+ BuildGetUpdatesProcessor(configure_delegate));
+ processor->PrepareGetUpdates(request_types(), &gu_msg);
EXPECT_EQ(sync_pb::SyncEnums::RECONFIGURATION, gu_msg.get_updates_origin());
EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
@@ -197,17 +195,15 @@ TEST_F(DownloadUpdatesTest, ConfigureTest) {
gu_msg.from_progress_marker(i).data_type_id());
progress_types.Put(type);
}
- EXPECT_TRUE(proto_request_types().Equals(progress_types));
+ EXPECT_TRUE(request_types().Equals(progress_types));
}
TEST_F(DownloadUpdatesTest, PollTest) {
- sync_pb::ClientToServerMessage msg;
- download::BuildDownloadUpdatesForPollImpl(
- proto_request_types(),
- get_updates_processor(),
- msg.mutable_get_updates());
-
- const sync_pb::GetUpdatesMessage& gu_msg = msg.get_updates();
+ sync_pb::GetUpdatesMessage gu_msg;
+ PollGetUpdatesDelegate poll_delegate;
+ scoped_ptr<GetUpdatesProcessor> processor(
+ BuildGetUpdatesProcessor(poll_delegate));
+ processor->PrepareGetUpdates(request_types(), &gu_msg);
EXPECT_EQ(sync_pb::SyncEnums::PERIODIC, gu_msg.get_updates_origin());
EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC,
@@ -219,17 +215,24 @@ TEST_F(DownloadUpdatesTest, PollTest) {
gu_msg.from_progress_marker(i).data_type_id());
progress_types.Put(type);
}
- EXPECT_TRUE(proto_request_types().Equals(progress_types));
+ EXPECT_TRUE(request_types().Equals(progress_types));
}
TEST_F(DownloadUpdatesTest, RetryTest) {
- sync_pb::ClientToServerMessage msg;
- download::BuildDownloadUpdatesForRetryImpl(
- proto_request_types(),
- get_updates_processor(),
- msg.mutable_get_updates());
+ sessions::NudgeTracker nudge_tracker;
+
+ // Schedule a retry.
+ base::TimeTicks t1 = kTestStartTime;
+ nudge_tracker.SetNextRetryTime(t1);
+
+ // Get the nudge tracker to think the retry is due.
+ nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1));
- const sync_pb::GetUpdatesMessage& gu_msg = msg.get_updates();
+ sync_pb::GetUpdatesMessage gu_msg;
+ RetryGetUpdatesDelegate retry_delegate;
+ scoped_ptr<GetUpdatesProcessor> processor(
+ BuildGetUpdatesProcessor(retry_delegate));
+ processor->PrepareGetUpdates(request_types(), &gu_msg);
EXPECT_EQ(sync_pb::SyncEnums::RETRY, gu_msg.get_updates_origin());
EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RETRY,
@@ -242,12 +245,11 @@ TEST_F(DownloadUpdatesTest, RetryTest) {
gu_msg.from_progress_marker(i).data_type_id());
progress_types.Put(type);
}
- EXPECT_TRUE(proto_request_types().Equals(progress_types));
+ EXPECT_TRUE(request_types().Equals(progress_types));
}
TEST_F(DownloadUpdatesTest, NudgeWithRetryTest) {
sessions::NudgeTracker nudge_tracker;
- nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS));
// Schedule a retry.
base::TimeTicks t1 = kTestStartTime;
@@ -256,12 +258,20 @@ TEST_F(DownloadUpdatesTest, NudgeWithRetryTest) {
// Get the nudge tracker to think the retry is due.
nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1));
- sync_pb::ClientToServerMessage msg;
- download::BuildNormalDownloadUpdatesImpl(proto_request_types(),
- get_updates_processor(),
- nudge_tracker,
- msg.mutable_get_updates());
- EXPECT_TRUE(msg.get_updates().is_retry());
+ // Record a local change, too.
+ nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS));
+
+ sync_pb::GetUpdatesMessage gu_msg;
+ NormalGetUpdatesDelegate normal_delegate(nudge_tracker);
+ scoped_ptr<GetUpdatesProcessor> processor(
+ BuildGetUpdatesProcessor(normal_delegate));
+ processor->PrepareGetUpdates(request_types(), &gu_msg);
+
+ EXPECT_NE(sync_pb::SyncEnums::RETRY, gu_msg.get_updates_origin());
+ EXPECT_NE(sync_pb::GetUpdatesCallerInfo::RETRY,
+ gu_msg.caller_info().source());
+
+ EXPECT_TRUE(gu_msg.is_retry());
}
// Verify that a bogus response message is detected.
@@ -273,10 +283,14 @@ TEST_F(DownloadUpdatesTest, InvalidResponse) {
// then something is very wrong. The client should detect this.
gu_response.clear_changes_remaining();
+ sessions::NudgeTracker nudge_tracker;
+ NormalGetUpdatesDelegate normal_delegate(nudge_tracker);
sessions::StatusController status;
+ scoped_ptr<GetUpdatesProcessor> processor(
+ BuildGetUpdatesProcessor(normal_delegate));
SyncerError error = download::ProcessResponse(gu_response,
- proto_request_types(),
- get_updates_processor(),
+ request_types(),
+ processor.get(),
&status);
EXPECT_EQ(error, SERVER_RESPONSE_VALIDATION_FAILED);
}
@@ -287,10 +301,14 @@ TEST_F(DownloadUpdatesTest, MoreToDownloadResponse) {
InitFakeUpdateResponse(&gu_response);
gu_response.set_changes_remaining(1);
+ sessions::NudgeTracker nudge_tracker;
+ NormalGetUpdatesDelegate normal_delegate(nudge_tracker);
sessions::StatusController status;
+ scoped_ptr<GetUpdatesProcessor> processor(
+ BuildGetUpdatesProcessor(normal_delegate));
SyncerError error = download::ProcessResponse(gu_response,
- proto_request_types(),
- get_updates_processor(),
+ request_types(),
+ processor.get(),
&status);
EXPECT_EQ(error, SERVER_MORE_TO_DOWNLOAD);
}
@@ -301,10 +319,14 @@ TEST_F(DownloadUpdatesTest, NormalResponseTest) {
InitFakeUpdateResponse(&gu_response);
gu_response.set_changes_remaining(0);
+ sessions::NudgeTracker nudge_tracker;
+ NormalGetUpdatesDelegate normal_delegate(nudge_tracker);
sessions::StatusController status;
+ scoped_ptr<GetUpdatesProcessor> processor(
+ BuildGetUpdatesProcessor(normal_delegate));
SyncerError error = download::ProcessResponse(gu_response,
- proto_request_types(),
- get_updates_processor(),
+ request_types(),
+ processor.get(),
&status);
EXPECT_EQ(error, SYNCER_OK);
}
diff --git a/sync/engine/get_updates_delegate.cc b/sync/engine/get_updates_delegate.cc
new file mode 100644
index 0000000..32cc0f1
--- /dev/null
+++ b/sync/engine/get_updates_delegate.cc
@@ -0,0 +1,155 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/engine/get_updates_delegate.h"
+
+#include "sync/engine/get_updates_processor.h"
+#include "sync/engine/sync_directory_update_handler.h"
+
+namespace syncer {
+
+namespace {
+
+void NonPassiveApplyUpdates(
+ sessions::StatusController* status_controller,
+ UpdateHandlerMap* update_handler_map) {
+ for (UpdateHandlerMap::iterator it = update_handler_map->begin();
+ it != update_handler_map->end(); ++it) {
+ it->second->ApplyUpdates(status_controller);
+ }
+}
+
+void PassiveApplyUpdates(
+ sessions::StatusController* status_controller,
+ UpdateHandlerMap* update_handler_map) {
+ for (UpdateHandlerMap::iterator it = update_handler_map->begin();
+ it != update_handler_map->end(); ++it) {
+ it->second->PassiveApplyUpdates(status_controller);
+ }
+}
+
+} // namespace
+
+GetUpdatesDelegate::GetUpdatesDelegate() {}
+
+GetUpdatesDelegate::~GetUpdatesDelegate() {}
+
+NormalGetUpdatesDelegate::NormalGetUpdatesDelegate(
+ const sessions::NudgeTracker& nudge_tracker)
+ : nudge_tracker_(nudge_tracker) {}
+
+NormalGetUpdatesDelegate::~NormalGetUpdatesDelegate() {}
+
+// This function assumes the progress markers have already been populated.
+void NormalGetUpdatesDelegate::HelpPopulateGuMessage(
+ sync_pb::GetUpdatesMessage* get_updates) const {
+ // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information.
+ get_updates->mutable_caller_info()->set_source(
+ nudge_tracker_.updates_source());
+
+ // Set the new and improved version of source, too.
+ get_updates->set_get_updates_origin(sync_pb::SyncEnums::GU_TRIGGER);
+ get_updates->set_is_retry(nudge_tracker_.IsRetryRequired());
+
+ // Fill in the notification hints.
+ for (int i = 0; i < get_updates->from_progress_marker_size(); ++i) {
+ sync_pb::DataTypeProgressMarker* progress_marker =
+ get_updates->mutable_from_progress_marker(i);
+ ModelType type = GetModelTypeFromSpecificsFieldNumber(
+ progress_marker->data_type_id());
+
+ DCHECK(!nudge_tracker_.IsTypeThrottled(type))
+ << "Throttled types should have been removed from the request_types.";
+
+ nudge_tracker_.SetLegacyNotificationHint(type, progress_marker);
+ nudge_tracker_.FillProtoMessage(
+ type,
+ progress_marker->mutable_get_update_triggers());
+ }
+}
+
+void NormalGetUpdatesDelegate::ApplyUpdates(
+ sessions::StatusController* status_controller,
+ UpdateHandlerMap* update_handler_map) const {
+ NonPassiveApplyUpdates(status_controller, update_handler_map);
+}
+
+RetryGetUpdatesDelegate::RetryGetUpdatesDelegate() {}
+
+RetryGetUpdatesDelegate::~RetryGetUpdatesDelegate() {}
+
+void RetryGetUpdatesDelegate::HelpPopulateGuMessage(
+ sync_pb::GetUpdatesMessage* get_updates) const {
+ // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information.
+ get_updates->mutable_caller_info()->set_source(
+ sync_pb::GetUpdatesCallerInfo::RETRY);
+
+ // Set the new and improved version of source, too.
+ get_updates->set_get_updates_origin(sync_pb::SyncEnums::RETRY);
+ get_updates->set_is_retry(true);
+}
+
+void RetryGetUpdatesDelegate::ApplyUpdates(
+ sessions::StatusController* status_controller,
+ UpdateHandlerMap* update_handler_map) const {
+ NonPassiveApplyUpdates(status_controller, update_handler_map);
+}
+
+ConfigureGetUpdatesDelegate::ConfigureGetUpdatesDelegate(
+ sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) : source_(source) {}
+
+ConfigureGetUpdatesDelegate::~ConfigureGetUpdatesDelegate() {}
+
+void ConfigureGetUpdatesDelegate::HelpPopulateGuMessage(
+ sync_pb::GetUpdatesMessage* get_updates) const {
+ get_updates->mutable_caller_info()->set_source(source_);
+ get_updates->set_get_updates_origin(ConvertConfigureSourceToOrigin(source_));
+}
+
+void ConfigureGetUpdatesDelegate::ApplyUpdates(
+ sessions::StatusController* status_controller,
+ UpdateHandlerMap* update_handler_map) const {
+ PassiveApplyUpdates(status_controller, update_handler_map);
+}
+
+sync_pb::SyncEnums::GetUpdatesOrigin
+ConfigureGetUpdatesDelegate::ConvertConfigureSourceToOrigin(
+ sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
+ switch (source) {
+ // Configurations:
+ case sync_pb::GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE:
+ return sync_pb::SyncEnums::NEWLY_SUPPORTED_DATATYPE;
+ case sync_pb::GetUpdatesCallerInfo::MIGRATION:
+ return sync_pb::SyncEnums::MIGRATION;
+ case sync_pb::GetUpdatesCallerInfo::RECONFIGURATION:
+ return sync_pb::SyncEnums::RECONFIGURATION;
+ case sync_pb::GetUpdatesCallerInfo::NEW_CLIENT:
+ return sync_pb::SyncEnums::NEW_CLIENT;
+ default:
+ NOTREACHED();
+ return sync_pb::SyncEnums::UNKNOWN_ORIGIN;
+ }
+}
+
+PollGetUpdatesDelegate::PollGetUpdatesDelegate() {}
+
+PollGetUpdatesDelegate::~PollGetUpdatesDelegate() {}
+
+void PollGetUpdatesDelegate::HelpPopulateGuMessage(
+ sync_pb::GetUpdatesMessage* get_updates) const {
+ // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information.
+ get_updates->mutable_caller_info()->set_source(
+ sync_pb::GetUpdatesCallerInfo::PERIODIC);
+
+ // Set the new and improved version of source, too.
+ get_updates->set_get_updates_origin(sync_pb::SyncEnums::PERIODIC);
+}
+
+void PollGetUpdatesDelegate::ApplyUpdates(
+ sessions::StatusController* status_controller,
+ UpdateHandlerMap* update_handler_map) const {
+ NonPassiveApplyUpdates(status_controller, update_handler_map);
+}
+
+} // namespace syncer
diff --git a/sync/engine/get_updates_delegate.h b/sync/engine/get_updates_delegate.h
new file mode 100644
index 0000000..825c061
--- /dev/null
+++ b/sync/engine/get_updates_delegate.h
@@ -0,0 +1,124 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYNC_ENGINE_GET_UPDATES_DELEGATE_H_
+#define SYNC_ENGINE_GET_UPDATES_DELEGATE_H_
+
+#include "sync/protocol/sync.pb.h"
+#include "sync/sessions/model_type_registry.h"
+#include "sync/sessions/nudge_tracker.h"
+#include "sync/sessions/status_controller.h"
+
+namespace syncer {
+
+class GetUpdatesProcessor;
+
+// Interface for GetUpdates functionality that dependends on the requested
+// GetUpdate type (normal, configuration, poll). The GetUpdatesProcessor is
+// given an appropriate GetUpdatesDelegate to handle type specific functionality
+// on construction.
+class SYNC_EXPORT_PRIVATE GetUpdatesDelegate {
+ public:
+ GetUpdatesDelegate();
+ virtual ~GetUpdatesDelegate() = 0;
+
+ // Populates GetUpdate message fields that depende on GetUpdates request type.
+ virtual void HelpPopulateGuMessage(
+ sync_pb::GetUpdatesMessage* get_updates) const = 0;
+
+ // Applies pending updates to non-control types.
+ virtual void ApplyUpdates(
+ sessions::StatusController* session,
+ UpdateHandlerMap* update_handler_map) const = 0;
+};
+
+// Functionality specific to the normal GetUpdate request.
+class SYNC_EXPORT_PRIVATE NormalGetUpdatesDelegate : public GetUpdatesDelegate {
+ public:
+ NormalGetUpdatesDelegate(const sessions::NudgeTracker& nudge_tracker);
+ virtual ~NormalGetUpdatesDelegate();
+
+ // Uses the member NudgeTracker to populate some fields of this GU message.
+ virtual void HelpPopulateGuMessage(
+ sync_pb::GetUpdatesMessage* get_updates) const OVERRIDE;
+
+ // Applies pending updates on the appropriate data type threads.
+ virtual void ApplyUpdates(
+ sessions::StatusController* status,
+ UpdateHandlerMap* update_handler_map) const OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NormalGetUpdatesDelegate);
+
+ const sessions::NudgeTracker& nudge_tracker_;
+};
+
+// Functionality specific to the retry GetUpdate request.
+class SYNC_EXPORT_PRIVATE RetryGetUpdatesDelegate : public GetUpdatesDelegate {
+ public:
+ RetryGetUpdatesDelegate();
+ virtual ~RetryGetUpdatesDelegate();
+
+ virtual void HelpPopulateGuMessage(
+ sync_pb::GetUpdatesMessage* get_updates) const OVERRIDE;
+
+ virtual void ApplyUpdates(
+ sessions::StatusController* status,
+ UpdateHandlerMap* update_handler_map) const OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RetryGetUpdatesDelegate);
+};
+
+// Functionality specific to the configure GetUpdate request.
+class SYNC_EXPORT_PRIVATE ConfigureGetUpdatesDelegate
+ : public GetUpdatesDelegate {
+ public:
+ ConfigureGetUpdatesDelegate(
+ sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
+ virtual ~ConfigureGetUpdatesDelegate();
+
+ // Sets the 'source' and 'origin' fields for this request.
+ virtual void HelpPopulateGuMessage(
+ sync_pb::GetUpdatesMessage* get_updates) const OVERRIDE;
+
+ // Applies updates passively (ie. on the sync thread).
+ //
+ // This is safe only if the ChangeProcessor is not listening to changes at
+ // this time.
+ virtual void ApplyUpdates(
+ sessions::StatusController* status,
+ UpdateHandlerMap* update_handler_map) const OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ConfigureGetUpdatesDelegate);
+
+ static sync_pb::SyncEnums::GetUpdatesOrigin ConvertConfigureSourceToOrigin(
+ sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
+
+ const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source_;
+};
+
+// Functionality specific to the poll GetUpdate request.
+class SYNC_EXPORT_PRIVATE PollGetUpdatesDelegate : public GetUpdatesDelegate {
+ public:
+ PollGetUpdatesDelegate();
+ virtual ~PollGetUpdatesDelegate();
+
+ // Sets the 'source' and 'origin' to indicate this is a poll request.
+ virtual void HelpPopulateGuMessage(
+ sync_pb::GetUpdatesMessage* get_updates) const OVERRIDE;
+
+ // Applies updates on the appropriate data type thread.
+ virtual void ApplyUpdates(
+ sessions::StatusController* status,
+ UpdateHandlerMap* update_handler_map) const OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PollGetUpdatesDelegate);
+};
+
+} // namespace syncer
+
+#endif // SYNC_ENGINE_GET_UPDATES_DELEGATE_H_
diff --git a/sync/engine/get_updates_processor.cc b/sync/engine/get_updates_processor.cc
index 64dc347..16207b8 100644
--- a/sync/engine/get_updates_processor.cc
+++ b/sync/engine/get_updates_processor.cc
@@ -6,6 +6,7 @@
#include <map>
+#include "sync/engine/get_updates_delegate.h"
#include "sync/engine/sync_directory_update_handler.h"
#include "sync/protocol/sync.pb.h"
@@ -72,8 +73,9 @@ void PartitionProgressMarkersByType(
} // namespace
-GetUpdatesProcessor::GetUpdatesProcessor(UpdateHandlerMap* update_handler_map)
- : update_handler_map_(update_handler_map) {}
+GetUpdatesProcessor::GetUpdatesProcessor(UpdateHandlerMap* update_handler_map,
+ const GetUpdatesDelegate& delegate)
+ : update_handler_map_(update_handler_map), delegate_(delegate) {}
GetUpdatesProcessor::~GetUpdatesProcessor() {}
@@ -87,6 +89,7 @@ void GetUpdatesProcessor::PrepareGetUpdates(
get_updates->add_from_progress_marker();
handler_it->second->GetDownloadProgress(progress_marker);
}
+ delegate_.HelpPopulateGuMessage(get_updates);
}
bool GetUpdatesProcessor::ProcessGetUpdatesResponse(
@@ -137,20 +140,9 @@ bool GetUpdatesProcessor::ProcessGetUpdatesResponse(
return true;
}
-void GetUpdatesProcessor::ApplyUpdatesForAllTypes(
+void GetUpdatesProcessor::ApplyUpdates(
sessions::StatusController* status_controller) {
- for (UpdateHandlerMap::iterator it = update_handler_map_->begin();
- it != update_handler_map_->end(); ++it) {
- it->second->ApplyUpdates(status_controller);
- }
-}
-
-void GetUpdatesProcessor::PassiveApplyUpdatesForAllTypes(
- sessions::StatusController* status_controller) {
- for (UpdateHandlerMap::iterator it = update_handler_map_->begin();
- it != update_handler_map_->end(); ++it) {
- it->second->PassiveApplyUpdates(status_controller);
- }
+ delegate_.ApplyUpdates(status_controller, update_handler_map_);
}
} // namespace syncer
diff --git a/sync/engine/get_updates_processor.h b/sync/engine/get_updates_processor.h
index 4032ce6..4058091 100644
--- a/sync/engine/get_updates_processor.h
+++ b/sync/engine/get_updates_processor.h
@@ -29,6 +29,7 @@ namespace syncable {
class Directory;
} // namespace syncable
+class GetUpdatesDelegate;
class SyncDirectoryUpdateHandler;
typedef std::vector<const sync_pb::SyncEntity*> SyncEntityList;
@@ -42,7 +43,8 @@ typedef std::map<ModelType, SyncEntityList> TypeSyncEntityMap;
// contains a type which was not previously registered with the manager.
class SYNC_EXPORT_PRIVATE GetUpdatesProcessor {
public:
- explicit GetUpdatesProcessor(UpdateHandlerMap* update_handler_map);
+ explicit GetUpdatesProcessor(UpdateHandlerMap* update_handler_map,
+ const GetUpdatesDelegate& delegate);
~GetUpdatesProcessor();
// Populates a GetUpdates request message with per-type information.
@@ -55,13 +57,8 @@ class SYNC_EXPORT_PRIVATE GetUpdatesProcessor {
const sync_pb::GetUpdatesResponse& gu_response,
sessions::StatusController* status_controller);
- // Applies pending updates for all sync types known to the manager. Work is
- // delegated to their model threads.
- void ApplyUpdatesForAllTypes(sessions::StatusController* status_controller);
-
- // Applies updates on the sync thread. Safe only in configure cycles.
- void PassiveApplyUpdatesForAllTypes(
- sessions::StatusController* status_controller);
+ // Hands off control to the delegate so it can apply updates.
+ void ApplyUpdates(sessions::StatusController* status_controller);
private:
// A map of 'update handlers', one for each enabled type.
@@ -69,6 +66,8 @@ class SYNC_EXPORT_PRIVATE GetUpdatesProcessor {
// that problem is to initialize this map in set_routing_info().
UpdateHandlerMap* update_handler_map_;
+ const GetUpdatesDelegate& delegate_;
+
DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessor);
};
diff --git a/sync/engine/sync_scheduler_impl.cc b/sync/engine/sync_scheduler_impl.cc
index 1399331..928dff4 100644
--- a/sync/engine/sync_scheduler_impl.cc
+++ b/sync/engine/sync_scheduler_impl.cc
@@ -247,8 +247,10 @@ void SyncSchedulerImpl::Start(Mode mode) {
ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() {
ModelTypeSet enabled_types = session_context_->enabled_types();
+ ModelTypeSet enabled_protocol_types =
+ Intersection(ProtocolTypes(), enabled_types);
ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes();
- return Difference(enabled_types, throttled_types);
+ return Difference(enabled_protocol_types, throttled_types);
}
void SyncSchedulerImpl::SendInitialSnapshot() {
diff --git a/sync/engine/syncer.cc b/sync/engine/syncer.cc
index 629635d..21282de 100644
--- a/sync/engine/syncer.cc
+++ b/sync/engine/syncer.cc
@@ -15,6 +15,7 @@
#include "sync/engine/commit_processor.h"
#include "sync/engine/conflict_resolver.h"
#include "sync/engine/download.h"
+#include "sync/engine/get_updates_delegate.h"
#include "sync/engine/get_updates_processor.h"
#include "sync/engine/net/server_connection_manager.h"
#include "sync/engine/syncer_types.h"
@@ -58,26 +59,20 @@ 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() ||
session->context()->ShouldFetchUpdatesBeforeCommit()) {
- if (!DownloadUpdates(
+ VLOG(1) << "Downloading types " << ModelTypeSetToString(request_types);
+ NormalGetUpdatesDelegate normal_delegate(nudge_tracker);
+ GetUpdatesProcessor get_updates_processor(
+ session->context()->model_type_registry()->update_handler_map(),
+ normal_delegate);
+ if (!DownloadAndApplyUpdates(
request_types,
session,
&get_updates_processor,
- base::Bind(&download::BuildNormalDownloadUpdates,
- session,
- &get_updates_processor,
- kCreateMobileBookmarksFolder,
- request_types,
- base::ConstRef(nudge_tracker)))) {
+ kCreateMobileBookmarksFolder)) {
return HandleCycleEnd(session, nudge_tracker.updates_source());
}
- ApplyUpdates(session, &get_updates_processor);
- if (ExitRequested())
- return HandleCycleEnd(session, nudge_tracker.updates_source());
}
VLOG(1) << "Committing from types " << ModelTypeSetToString(request_types);
@@ -94,104 +89,67 @@ bool Syncer::ConfigureSyncShare(
ModelTypeSet request_types,
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
SyncSession* session) {
+ VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types);
HandleCycleBegin(session);
+ ConfigureGetUpdatesDelegate configure_delegate(source);
GetUpdatesProcessor get_updates_processor(
- session->context()->model_type_registry()->update_handler_map());
- VLOG(1) << "Configuring types " << ModelTypeSetToString(request_types);
- if (!DownloadUpdates(
+ session->context()->model_type_registry()->update_handler_map(),
+ configure_delegate);
+ DownloadAndApplyUpdates(
request_types,
session,
&get_updates_processor,
- base::Bind(&download::BuildDownloadUpdatesForConfigure,
- session,
- &get_updates_processor,
- kCreateMobileBookmarksFolder,
- source,
- request_types))) {
- return HandleCycleEnd(session, source);
- }
-
- {
- TRACE_EVENT0("sync", "ApplyUpdatesPassively");
-
- ApplyControlDataUpdates(session->context()->directory());
-
- get_updates_processor.PassiveApplyUpdatesForAllTypes(
- session->mutable_status_controller());
- session->context()->set_hierarchy_conflict_detected(
- session->status_controller().num_hierarchy_conflicts() > 0);
- }
-
+ kCreateMobileBookmarksFolder);
return HandleCycleEnd(session, source);
}
bool Syncer::PollSyncShare(ModelTypeSet request_types,
SyncSession* session) {
+ VLOG(1) << "Polling types " << ModelTypeSetToString(request_types);
HandleCycleBegin(session);
+ PollGetUpdatesDelegate poll_delegate;
GetUpdatesProcessor get_updates_processor(
- session->context()->model_type_registry()->update_handler_map());
- VLOG(1) << "Polling types " << ModelTypeSetToString(request_types);
- if (!DownloadUpdates(
+ session->context()->model_type_registry()->update_handler_map(),
+ poll_delegate);
+ 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);
- }
- ApplyUpdates(session, &get_updates_processor);
+ kCreateMobileBookmarksFolder);
return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::PERIODIC);
}
bool Syncer::RetrySyncShare(ModelTypeSet request_types,
SyncSession* session) {
+ VLOG(1) << "Retrying types " << ModelTypeSetToString(request_types);
HandleCycleBegin(session);
+ RetryGetUpdatesDelegate retry_delegate;
GetUpdatesProcessor get_updates_processor(
- session->context()->model_type_registry()->update_handler_map());
- VLOG(1) << "Retrying types " << ModelTypeSetToString(request_types);
- if (!DownloadUpdates(
+ session->context()->model_type_registry()->update_handler_map(),
+ retry_delegate);
+ 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);
- }
- ApplyUpdates(session, &get_updates_processor);
- return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::PERIODIC);
-}
-
-void Syncer::ApplyUpdates(SyncSession* session,
- GetUpdatesProcessor* get_updates_processor) {
- TRACE_EVENT0("sync", "ApplyUpdates");
-
- ApplyControlDataUpdates(session->context()->directory());
-
- get_updates_processor->ApplyUpdatesForAllTypes(
- session->mutable_status_controller());
-
- session->context()->set_hierarchy_conflict_detected(
- session->status_controller().num_hierarchy_conflicts() > 0);
-
- session->SendEventNotification(SyncCycleEvent::STATUS_CHANGED);
+ kCreateMobileBookmarksFolder);
+ return HandleCycleEnd(session, sync_pb::GetUpdatesCallerInfo::RETRY);
}
-bool Syncer::DownloadUpdates(
+bool Syncer::DownloadAndApplyUpdates(
ModelTypeSet request_types,
SyncSession* session,
GetUpdatesProcessor* get_updates_processor,
- base::Callback<void(sync_pb::ClientToServerMessage*)> build_fn) {
+ bool create_mobile_bookmarks_folder) {
SyncerError download_result = UNSET;
do {
TRACE_EVENT0("sync", "DownloadUpdates");
sync_pb::ClientToServerMessage msg;
- build_fn.Run(&msg);
+ sync_pb::GetUpdatesMessage* gu_msg = msg.mutable_get_updates();
+
+ download::InitDownloadUpdatesContext(
+ session, create_mobile_bookmarks_folder, &msg);
+ get_updates_processor->PrepareGetUpdates(request_types, gu_msg);
+
download_result = download::ExecuteDownloadUpdates(request_types,
session,
get_updates_processor,
@@ -200,10 +158,30 @@ bool Syncer::DownloadUpdates(
download_result);
} while (download_result == SERVER_MORE_TO_DOWNLOAD);
- // Report failure if something unusual happened.
- if (download_result != SYNCER_OK || ExitRequested())
+ // Exit without applying if we're shutting down or an error was detected.
+ if (download_result != SYNCER_OK)
+ return false;
+ if (ExitRequested())
return false;
+ {
+ TRACE_EVENT0("sync", "ApplyUpdates");
+
+ // Control type updates always get applied first.
+ ApplyControlDataUpdates(session->context()->directory());
+
+ // Apply upates to the other types. May or may not involve cross-thread
+ // traffic, depending on the underlying update handlers and the GU type's
+ // delegate.
+ get_updates_processor->ApplyUpdates(session->mutable_status_controller());
+
+ session->context()->set_hierarchy_conflict_detected(
+ session->status_controller().num_hierarchy_conflicts() > 0);
+ session->SendEventNotification(SyncCycleEvent::STATUS_CHANGED);
+ }
+
+ if (ExitRequested())
+ return false;
return true;
}
diff --git a/sync/engine/syncer.h b/sync/engine/syncer.h
index 006ca3b..a1aeff8 100644
--- a/sync/engine/syncer.h
+++ b/sync/engine/syncer.h
@@ -71,13 +71,11 @@ class SYNC_EXPORT_PRIVATE Syncer {
sessions::SyncSession* session);
private:
- void ApplyUpdates(sessions::SyncSession* session,
- GetUpdatesProcessor* get_updates_processor);
- bool DownloadUpdates(
+ bool DownloadAndApplyUpdates(
ModelTypeSet request_types,
sessions::SyncSession* session,
GetUpdatesProcessor* get_updates_processor,
- base::Callback<void(sync_pb::ClientToServerMessage*)> build_fn);
+ bool create_mobile_bookmarks_folder);
// This function will commit batches of unsynced items to the server until the
// number of unsynced and ready to commit items reaches zero or an error is