summaryrefslogtreecommitdiffstats
path: root/sync/sessions
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-18 18:13:46 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-18 18:13:46 +0000
commit955a206f776a025c6cf86e49cf43ea09a8bf630c (patch)
tree4cd0a3ebde3e6e2f297de5eda7465b80044b1a2e /sync/sessions
parent086028755ed14102deaf027ca274ab0a25aec65e (diff)
downloadchromium_src-955a206f776a025c6cf86e49cf43ea09a8bf630c.zip
chromium_src-955a206f776a025c6cf86e49cf43ea09a8bf630c.tar.gz
chromium_src-955a206f776a025c6cf86e49cf43ea09a8bf630c.tar.bz2
sync: Support non-blocking initial sync in proto
Adds support for non-blocking initial sync to the sync protocol. This allows some types to request an initial sync without having the scheduler enter configure mode. The protocol changes are necessary to keep the server informed that the request is due to an initial sync request. The remainder of the changes in this CL were required to plumb information about the cause of the sync cycle through the SyncScheduler. This CL also includes some new tests. At the moment, there are no types in use that support this feature. This CL will not affect behavior in any way. BUG=351005 Review URL: https://codereview.chromium.org/387983004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284159 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/sessions')
-rw-r--r--sync/sessions/data_type_tracker.cc17
-rw-r--r--sync/sessions/data_type_tracker.h10
-rw-r--r--sync/sessions/nudge_tracker.cc14
-rw-r--r--sync/sessions/nudge_tracker.h3
-rw-r--r--sync/sessions/nudge_tracker_unittest.cc33
5 files changed, 75 insertions, 2 deletions
diff --git a/sync/sessions/data_type_tracker.cc b/sync/sessions/data_type_tracker.cc
index ed7f07f..12b53e9 100644
--- a/sync/sessions/data_type_tracker.cc
+++ b/sync/sessions/data_type_tracker.cc
@@ -14,7 +14,8 @@ namespace sessions {
DataTypeTracker::DataTypeTracker()
: local_nudge_count_(0),
local_refresh_request_count_(0),
- payload_buffer_size_(NudgeTracker::kDefaultMaxPayloadsPerType) {
+ payload_buffer_size_(NudgeTracker::kDefaultMaxPayloadsPerType),
+ initial_sync_required_(false) {
}
DataTypeTracker::~DataTypeTracker() { }
@@ -86,6 +87,10 @@ void DataTypeTracker::RecordRemoteInvalidation(
}
}
+void DataTypeTracker::RecordInitialSyncRequired() {
+ initial_sync_required_ = true;
+}
+
void DataTypeTracker::RecordSuccessfulSyncCycle() {
// If we were throttled, then we would have been excluded from this cycle's
// GetUpdates and Commit actions. Our state remains unchanged.
@@ -111,6 +116,8 @@ void DataTypeTracker::RecordSuccessfulSyncCycle() {
last_dropped_invalidation_->Acknowledge();
last_dropped_invalidation_.reset();
}
+
+ initial_sync_required_ = false;
}
// This limit will take effect on all future invalidations received.
@@ -124,7 +131,8 @@ bool DataTypeTracker::IsSyncRequired() const {
bool DataTypeTracker::IsGetUpdatesRequired() const {
return !IsThrottled() &&
- (HasRefreshRequestPending() || HasPendingInvalidation());
+ (HasRefreshRequestPending() || HasPendingInvalidation() ||
+ IsInitialSyncRequired());
}
bool DataTypeTracker::HasLocalChangePending() const {
@@ -139,6 +147,10 @@ bool DataTypeTracker::HasPendingInvalidation() const {
return !pending_invalidations_.empty() || last_dropped_invalidation_;
}
+bool DataTypeTracker::IsInitialSyncRequired() const {
+ return initial_sync_required_;
+}
+
void DataTypeTracker::SetLegacyNotificationHint(
sync_pb::DataTypeProgressMarker* progress) const {
DCHECK(!IsThrottled())
@@ -178,6 +190,7 @@ void DataTypeTracker::FillGetUpdatesTriggersMessage(
msg->set_client_dropped_hints(last_dropped_invalidation_);
msg->set_local_modification_nudges(local_nudge_count_);
msg->set_datatype_refresh_nudges(local_refresh_request_count_);
+ msg->set_initial_sync_in_progress(initial_sync_required_);
}
bool DataTypeTracker::IsThrottled() const {
diff --git a/sync/sessions/data_type_tracker.h b/sync/sessions/data_type_tracker.h
index 8d78cde..7b0aba8 100644
--- a/sync/sessions/data_type_tracker.h
+++ b/sync/sessions/data_type_tracker.h
@@ -39,6 +39,9 @@ class DataTypeTracker {
// Tracks that we received invalidation notifications for this type.
void RecordRemoteInvalidation(scoped_ptr<InvalidationInterface> incoming);
+ // Takes note that initial sync is pending for this type.
+ void RecordInitialSyncRequired();
+
// Records that a sync cycle has been performed successfully.
// Generally, this means that all local changes have been committed and all
// remote changes have been downloaded, so we can clear any flags related to
@@ -67,6 +70,9 @@ class DataTypeTracker {
// Returns true if an explicit refresh request is still outstanding.
bool HasRefreshRequestPending() const;
+ // Returns true if this type is requesting an initial sync.
+ bool IsInitialSyncRequired() const;
+
// Fills in the legacy invalidaiton payload information fields.
void SetLegacyNotificationHint(
sync_pb::DataTypeProgressMarker* progress) const;
@@ -108,6 +114,10 @@ class DataTypeTracker {
size_t payload_buffer_size_;
+ // Set to true if this type is ready for, but has not yet completed initial
+ // sync.
+ bool initial_sync_required_;
+
// If !unthrottle_time_.is_null(), this type is throttled and may not download
// or commit data until the specified time.
base::TimeTicks unthrottle_time_;
diff --git a/sync/sessions/nudge_tracker.cc b/sync/sessions/nudge_tracker.cc
index e4ebc23..a0bdbda 100644
--- a/sync/sessions/nudge_tracker.cc
+++ b/sync/sessions/nudge_tracker.cc
@@ -106,6 +106,12 @@ void NudgeTracker::RecordRemoteInvalidation(
tracker_it->second->RecordRemoteInvalidation(invalidation.Pass());
}
+void NudgeTracker::RecordInitialSyncRequired(syncer::ModelType type) {
+ TypeTrackerMap::iterator tracker_it = type_trackers_.find(type);
+ DCHECK(tracker_it != type_trackers_.end());
+ tracker_it->second->RecordInitialSyncRequired();
+}
+
void NudgeTracker::OnInvalidationsEnabled() {
invalidations_enabled_ = true;
}
@@ -228,6 +234,7 @@ sync_pb::GetUpdatesCallerInfo::GetUpdatesSource NudgeTracker::GetLegacySource()
bool has_invalidation_pending = false;
bool has_refresh_request_pending = false;
bool has_commit_pending = false;
+ bool is_initial_sync_required = false;
bool has_retry = IsRetryRequired();
for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
@@ -242,12 +249,19 @@ sync_pb::GetUpdatesCallerInfo::GetUpdatesSource NudgeTracker::GetLegacySource()
if (!tracker.IsThrottled() && tracker.HasLocalChangePending()) {
has_commit_pending = true;
}
+ if (!tracker.IsThrottled() && tracker.IsInitialSyncRequired()) {
+ is_initial_sync_required = true;
+ }
}
if (has_invalidation_pending) {
return sync_pb::GetUpdatesCallerInfo::NOTIFICATION;
} else if (has_refresh_request_pending) {
return sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH;
+ } else if (is_initial_sync_required) {
+ // Not quite accurate, but good enough for our purposes. This setting of
+ // SOURCE is just a backward-compatibility hack anyway.
+ return sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH;
} else if (has_commit_pending) {
return sync_pb::GetUpdatesCallerInfo::LOCAL;
} else if (has_retry) {
diff --git a/sync/sessions/nudge_tracker.h b/sync/sessions/nudge_tracker.h
index a602537..0397c5d 100644
--- a/sync/sessions/nudge_tracker.h
+++ b/sync/sessions/nudge_tracker.h
@@ -62,6 +62,9 @@ class SYNC_EXPORT_PRIVATE NudgeTracker {
void RecordRemoteInvalidation(syncer::ModelType type,
scoped_ptr<InvalidationInterface> invalidation);
+ // Take note that an initial sync is pending for this type.
+ void RecordInitialSyncRequired(syncer::ModelType type);
+
// These functions should be called to keep this class informed of the status
// of the connection to the invalidations server.
void OnInvalidationsEnabled();
diff --git a/sync/sessions/nudge_tracker_unittest.cc b/sync/sessions/nudge_tracker_unittest.cc
index 4599e69..0b00d5e 100644
--- a/sync/sessions/nudge_tracker_unittest.cc
+++ b/sync/sessions/nudge_tracker_unittest.cc
@@ -137,6 +137,27 @@ TEST_F(NudgeTrackerTest, SourcePriorities) {
nudge_tracker_.GetLegacySource());
}
+TEST_F(NudgeTrackerTest, SourcePriority_InitialSyncRequest) {
+ nudge_tracker_.RecordInitialSyncRequired(BOOKMARKS);
+
+ // For lack of a better source, we describe an initial sync request as having
+ // source DATATYPE_REFRESH.
+ EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH,
+ nudge_tracker_.GetLegacySource());
+
+ // This should never happen in practice. But, if it did, we'd want the
+ // initial sync required to keep the source set to DATATYPE_REFRESH.
+ nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS));
+ EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH,
+ nudge_tracker_.GetLegacySource());
+
+ // It should be safe to let NOTIFICATIONs override it.
+ nudge_tracker_.RecordRemoteInvalidation(BOOKMARKS,
+ BuildInvalidation(1, "hint"));
+ EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION,
+ nudge_tracker_.GetLegacySource());
+}
+
// Verifies the management of invalidation hints and GU trigger fields.
TEST_F(NudgeTrackerTest, HintCoalescing) {
// Easy case: record one hint.
@@ -344,6 +365,12 @@ TEST_F(NudgeTrackerTest, WriteRefreshRequestedTypesToProto) {
TEST_F(NudgeTrackerTest, IsSyncRequired) {
EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
+ // Initial sync request.
+ nudge_tracker_.RecordInitialSyncRequired(BOOKMARKS);
+ EXPECT_TRUE(nudge_tracker_.IsSyncRequired());
+ nudge_tracker_.RecordSuccessfulSyncCycle();
+ EXPECT_FALSE(nudge_tracker_.IsSyncRequired());
+
// Local changes.
nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS));
EXPECT_TRUE(nudge_tracker_.IsSyncRequired());
@@ -368,6 +395,12 @@ TEST_F(NudgeTrackerTest, IsSyncRequired) {
TEST_F(NudgeTrackerTest, IsGetUpdatesRequired) {
EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
+ // Initial sync request.
+ nudge_tracker_.RecordInitialSyncRequired(BOOKMARKS);
+ EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
+ nudge_tracker_.RecordSuccessfulSyncCycle();
+ EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
+
// Local changes.
nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS));
EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());