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

Unified Diff: sync/sessions/data_type_tracker.cc

Issue 322333004: sync: Inject sync/'s dependency on invalidations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 5 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/sessions/data_type_tracker.h ('k') | sync/sessions/nudge_tracker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/sessions/data_type_tracker.cc
diff --git a/sync/sessions/data_type_tracker.cc b/sync/sessions/data_type_tracker.cc
index 5e0ee90171e6c2b21ae4356380c4d63faa5d7ac6..ed7f07f45a1467eef9a82827d4a0e58456d422f2 100644
--- a/sync/sessions/data_type_tracker.cc
+++ b/sync/sessions/data_type_tracker.cc
@@ -5,19 +5,17 @@
#include "sync/sessions/data_type_tracker.h"
#include "base/logging.h"
-#include "sync/internal_api/public/base/invalidation.h"
-#include "sync/notifier/invalidation_util.h"
-#include "sync/notifier/single_object_invalidation_set.h"
+#include "sync/internal_api/public/base/invalidation_interface.h"
#include "sync/sessions/nudge_tracker.h"
namespace syncer {
namespace sessions {
-DataTypeTracker::DataTypeTracker(const invalidation::ObjectId& object_id)
- : local_nudge_count_(0),
- local_refresh_request_count_(0),
- payload_buffer_size_(NudgeTracker::kDefaultMaxPayloadsPerType),
- drop_tracker_(object_id) { }
+DataTypeTracker::DataTypeTracker()
+ : local_nudge_count_(0),
+ local_refresh_request_count_(0),
+ payload_buffer_size_(NudgeTracker::kDefaultMaxPayloadsPerType) {
+}
DataTypeTracker::~DataTypeTracker() { }
@@ -29,20 +27,11 @@ void DataTypeTracker::RecordLocalRefreshRequest() {
local_refresh_request_count_++;
}
-namespace {
-
-bool IsInvalidationVersionLessThan(
- const Invalidation& a,
- const Invalidation& b) {
- InvalidationVersionLessThan comparator;
- return comparator(a, b);
-}
-
-} // namespace
+void DataTypeTracker::RecordRemoteInvalidation(
+ scoped_ptr<InvalidationInterface> incoming) {
+ DCHECK(incoming);
-void DataTypeTracker::RecordRemoteInvalidations(
- const SingleObjectInvalidationSet& invalidations) {
- // Merge the incoming invalidations into our list of pending invalidations.
+ // Merge the incoming invalidation into our list of pending invalidations.
//
// We won't use STL algorithms here because our concept of equality doesn't
// quite fit the expectations of set_intersection. In particular, two
@@ -50,52 +39,50 @@ void DataTypeTracker::RecordRemoteInvalidations(
// rules (ie. have equal versions), but still have different AckHandle values
// and need to be acknowledged separately.
//
- // The invalidaitons service can only track one outsanding invalidation per
+ // The invalidations service can only track one outsanding invalidation per
// type and version, so the acknowledgement here should be redundant. We'll
// acknowledge them anyway since it should do no harm, and makes this code a
// bit easier to test.
//
// Overlaps should be extremely rare for most invalidations. They can happen
// for unknown version invalidations, though.
- SingleObjectInvalidationSet::const_iterator incoming_it =
- invalidations.begin();
- SingleObjectInvalidationSet::const_iterator existing_it =
+
+ ScopedVector<InvalidationInterface>::iterator it =
pending_invalidations_.begin();
- while (incoming_it != invalidations.end()) {
- // Keep existing_it ahead of incoming_it.
- while (existing_it != pending_invalidations_.end()
- && IsInvalidationVersionLessThan(*existing_it, *incoming_it)) {
- existing_it++;
- }
+ // Find the lower bound.
+ while (it != pending_invalidations_.end() &&
+ InvalidationInterface::LessThanByVersion(**it, *incoming)) {
+ it++;
+ }
- if (existing_it != pending_invalidations_.end()
- && !IsInvalidationVersionLessThan(*incoming_it, *existing_it)
- && !IsInvalidationVersionLessThan(*existing_it, *incoming_it)) {
- // Incoming overlaps with existing. Either both are unknown versions
- // (likely) or these two have the same version number (very unlikely).
- // Acknowledge and overwrite existing.
- SingleObjectInvalidationSet::const_iterator old_inv = existing_it;
- existing_it++;
- old_inv->Acknowledge();
- pending_invalidations_.Erase(old_inv);
- pending_invalidations_.Insert(*incoming_it);
- incoming_it++;
- } else {
- DCHECK(existing_it == pending_invalidations_.end()
- || IsInvalidationVersionLessThan(*incoming_it, *existing_it));
- // The incoming_it points at a version not in the pending_invalidations_
- // list. Add it to the list then increment past it.
- pending_invalidations_.Insert(*incoming_it);
- incoming_it++;
- }
+ if (it != pending_invalidations_.end() &&
+ !InvalidationInterface::LessThanByVersion(*incoming, **it) &&
+ !InvalidationInterface::LessThanByVersion(**it, *incoming)) {
+ // Incoming overlaps with existing. Either both are unknown versions
+ // (likely) or these two have the same version number (very unlikely).
+ // Acknowledge and overwrite existing.
+
+ // Insert before the existing and get iterator to inserted.
+ ScopedVector<InvalidationInterface>::iterator it2 =
+ pending_invalidations_.insert(it, incoming.release());
+
+ // Increment that iterator to the old one, then acknowledge and remove it.
+ ++it2;
+ (*it2)->Acknowledge();
+ pending_invalidations_.erase(it2);
+ } else {
+ // The incoming has a version not in the pending_invalidations_ list.
+ // Add it to the list at the proper position.
+ pending_invalidations_.insert(it, incoming.release());
}
- // Those incoming invalidations may have caused us to exceed our buffer size.
+ // The incoming invalidation may have caused us to exceed our buffer size.
// Trim some items from our list, if necessary.
- while (pending_invalidations_.GetSize() > payload_buffer_size_) {
- pending_invalidations_.begin()->Drop(&drop_tracker_);
- pending_invalidations_.Erase(pending_invalidations_.begin());
+ while (pending_invalidations_.size() > payload_buffer_size_) {
+ last_dropped_invalidation_.reset(pending_invalidations_.front());
+ last_dropped_invalidation_->Drop();
+ pending_invalidations_.weak_erase(pending_invalidations_.begin());
}
}
@@ -112,15 +99,17 @@ void DataTypeTracker::RecordSuccessfulSyncCycle() {
// crash before writing all our state, we should wait until the results of
// this sync cycle have been written to disk before updating the invalidations
// state. See crbug.com/324996.
- for (SingleObjectInvalidationSet::const_iterator it =
- pending_invalidations_.begin();
- it != pending_invalidations_.end(); ++it) {
- it->Acknowledge();
+ for (ScopedVector<InvalidationInterface>::const_iterator it =
+ pending_invalidations_.begin();
+ it != pending_invalidations_.end();
+ ++it) {
+ (*it)->Acknowledge();
}
- pending_invalidations_.Clear();
+ pending_invalidations_.clear();
- if (drop_tracker_.IsRecoveringFromDropEvent()) {
- drop_tracker_.RecordRecoveryFromDropEvent();
+ if (last_dropped_invalidation_) {
+ last_dropped_invalidation_->Acknowledge();
+ last_dropped_invalidation_.reset();
}
}
@@ -147,8 +136,7 @@ bool DataTypeTracker::HasRefreshRequestPending() const {
}
bool DataTypeTracker::HasPendingInvalidation() const {
- return !pending_invalidations_.IsEmpty()
- || drop_tracker_.IsRecoveringFromDropEvent();
+ return !pending_invalidations_.empty() || last_dropped_invalidation_;
}
void DataTypeTracker::SetLegacyNotificationHint(
@@ -156,16 +144,17 @@ void DataTypeTracker::SetLegacyNotificationHint(
DCHECK(!IsThrottled())
<< "We should not make requests if the type is throttled.";
- if (!pending_invalidations_.IsEmpty() &&
- !pending_invalidations_.back().is_unknown_version()) {
+ if (!pending_invalidations_.empty() &&
+ !pending_invalidations_.back()->IsUnknownVersion()) {
// The old-style source info can contain only one hint per type. We grab
// the most recent, to mimic the old coalescing behaviour.
- progress->set_notification_hint(pending_invalidations_.back().payload());
+ progress->set_notification_hint(
+ pending_invalidations_.back()->GetPayload());
} else if (HasLocalChangePending()) {
// The old-style source info sent up an empty string (as opposed to
// nothing at all) when the type was locally nudged, but had not received
// any invalidations.
- progress->set_notification_hint("");
+ progress->set_notification_hint(std::string());
}
}
@@ -174,17 +163,19 @@ void DataTypeTracker::FillGetUpdatesTriggersMessage(
// Fill the list of payloads, if applicable. The payloads must be ordered
// oldest to newest, so we insert them in the same order as we've been storing
// them internally.
- for (SingleObjectInvalidationSet::const_iterator it =
- pending_invalidations_.begin();
- it != pending_invalidations_.end(); ++it) {
- if (!it->is_unknown_version()) {
- msg->add_notification_hint(it->payload());
+ for (ScopedVector<InvalidationInterface>::const_iterator it =
+ pending_invalidations_.begin();
+ it != pending_invalidations_.end();
+ ++it) {
+ if (!(*it)->IsUnknownVersion()) {
+ msg->add_notification_hint((*it)->GetPayload());
}
}
msg->set_server_dropped_hints(
- pending_invalidations_.StartsWithUnknownVersion());
- msg->set_client_dropped_hints(drop_tracker_.IsRecoveringFromDropEvent());
+ !pending_invalidations_.empty() &&
+ (*pending_invalidations_.begin())->IsUnknownVersion());
+ 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_);
}
« no previous file with comments | « sync/sessions/data_type_tracker.h ('k') | sync/sessions/nudge_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698