diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-23 22:43:48 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-23 22:43:48 +0000 |
commit | bea426f7bd155d578f8cc5d2c867c254237db0ca (patch) | |
tree | 84fb3114dd5ea071b2d7c15b986ed85b5927abcc /sync/internal_api | |
parent | 74b2df888135d294389f96eea1f6251dd76fa4e4 (diff) | |
download | chromium_src-bea426f7bd155d578f8cc5d2c867c254237db0ca.zip chromium_src-bea426f7bd155d578f8cc5d2c867c254237db0ca.tar.gz chromium_src-bea426f7bd155d578f8cc5d2c867c254237db0ca.tar.bz2 |
Add UnackedInvalidationSet class
Add a class that holds all locally unacknowledged invalidations and
their state. It is not used anywhere outside of tests.
This class is part of an attempt to refactor the InvalidatorStorage
class. That class stores pieces of the invalidations component's state
in preferences. It currently has some simple getter and setter methods
for things like the client ID and bootstrat data, and some more
complicated methods that related to storing unacked invalidations.
The goal is to eventually move the complex logic related to
invalidations out of the InvalidationStorage class, and into the
UnackedInvalidationSet class. The UnackedInvalidationSet class can
be owned by the SyncInvalidationListener, and periodically passed back
to the InvalidationStorage class on a separate thread for serialization.
The motivation for this refactoring is not merely aesthetic. The
UnackedInvalidationSet handles certain trickles related use cases
that the current storage system can not. Extending the existing storage
system to support these features would have made the code much harder to
understand. This approach lets us add functionality and simplify the
code at the same time.
BUG=233437
Review URL: https://codereview.chromium.org/26141004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230529 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api')
-rw-r--r-- | sync/internal_api/public/base/DEPS | 3 | ||||
-rw-r--r-- | sync/internal_api/public/base/invalidation.cc | 34 | ||||
-rw-r--r-- | sync/internal_api/public/base/invalidation.h | 14 |
3 files changed, 48 insertions, 3 deletions
diff --git a/sync/internal_api/public/base/DEPS b/sync/internal_api/public/base/DEPS index 047cfd4..9d46a8a 100644 --- a/sync/internal_api/public/base/DEPS +++ b/sync/internal_api/public/base/DEPS @@ -6,6 +6,7 @@ include_rules = [ "-sync", "+sync/base", "+sync/internal_api/public/base", + "+sync/internal_api/public/util", + "+sync/notifier", "+sync/protocol", - "+sync/notifier" ] diff --git a/sync/internal_api/public/base/invalidation.cc b/sync/internal_api/public/base/invalidation.cc index 55fdcc7..d60a324 100644 --- a/sync/internal_api/public/base/invalidation.cc +++ b/sync/internal_api/public/base/invalidation.cc @@ -19,6 +19,7 @@ const char kObjectIdKey[] = "objectId"; const char kIsUnknownVersionKey[] = "isUnknownVersion"; const char kVersionKey[] = "version"; const char kPayloadKey[] = "payload"; +const int64 kInvalidVersion = -1; } Invalidation Invalidation::Init( @@ -30,7 +31,14 @@ Invalidation Invalidation::Init( Invalidation Invalidation::InitUnknownVersion( const invalidation::ObjectId& id) { - return Invalidation(id, true, -1, std::string(), AckHandle::CreateUnique()); + return Invalidation(id, true, kInvalidVersion, + std::string(), AckHandle::CreateUnique()); +} + +Invalidation Invalidation::InitFromDroppedInvalidation( + const Invalidation& dropped) { + return Invalidation(dropped.id_, true, kInvalidVersion, + std::string(), dropped.ack_handle_); } scoped_ptr<Invalidation> Invalidation::InitFromValue( @@ -52,7 +60,7 @@ scoped_ptr<Invalidation> Invalidation::InitFromValue( return scoped_ptr<Invalidation>(new Invalidation( id, true, - -1, + kInvalidVersion, std::string(), AckHandle::CreateUnique())); } else { @@ -105,6 +113,28 @@ void Invalidation::set_ack_handle(const AckHandle& ack_handle) { ack_handle_ = ack_handle; } +void Invalidation::set_ack_handler(syncer::WeakHandle<AckHandler> handler) { + ack_handler_ = handler; +} + +bool Invalidation::SupportsAcknowledgement() const { + return ack_handler_.IsInitialized(); +} + +// void Invalidation::Acknowledge() const { +// if (SupportsAcknowledgement()) { +// ack_handler_.Call(FROM_HERE, +// &AckHandler::Acknowledge, +// id_, +// ack_handle_); +// } +// } + +// void Invalidation::Drop(DroppedInvalidationTracker* tracker) const { +// DCHECK(tracker->object_id() == object_id()); +// tracker->Drop(ack_handler_, ack_handle_); +// } + bool Invalidation::Equals(const Invalidation& other) const { return id_ == other.id_ && is_unknown_version_ == other.is_unknown_version_ diff --git a/sync/internal_api/public/base/invalidation.h b/sync/internal_api/public/base/invalidation.h index 2b83564b..4e157e0 100644 --- a/sync/internal_api/public/base/invalidation.h +++ b/sync/internal_api/public/base/invalidation.h @@ -13,6 +13,7 @@ #include "google/cacheinvalidation/include/types.h" #include "sync/base/sync_export.h" #include "sync/internal_api/public/base/ack_handle.h" +#include "sync/internal_api/public/util/weak_handle.h" namespace syncer { @@ -30,6 +31,7 @@ class SYNC_EXPORT Invalidation { int64 version, const std::string& payload); static Invalidation InitUnknownVersion(const invalidation::ObjectId& id); + static Invalidation InitFromDroppedInvalidation(const Invalidation& dropped); static scoped_ptr<Invalidation> InitFromValue( const base::DictionaryValue& value); @@ -48,8 +50,19 @@ class SYNC_EXPORT Invalidation { const std::string& payload() const; const AckHandle& ack_handle() const; + + // TODO(rlarocque): Remove this method and use AckHandlers instead. void set_ack_handle(const AckHandle& ack_handle); + void set_ack_handler(syncer::WeakHandle<AckHandler> ack_handler); + + // True if this class has a valid AckHandler. + bool SupportsAcknowledgement() const; + + // TODO(rlarocque): Re-enable these when we switch to AckHandlers. + // void Acknowledge() const; + // void Drop(DroppedInvalidationTracker* tracker) const; + scoped_ptr<base::DictionaryValue> ToValue() const; std::string ToString() const; @@ -76,6 +89,7 @@ class SYNC_EXPORT Invalidation { // A locally generated unique ID used to manage local acknowledgements. AckHandle ack_handle_; + syncer::WeakHandle<AckHandler> ack_handler_; }; } // namespace syncer |