summaryrefslogtreecommitdiffstats
path: root/sync/tools
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-08 23:38:21 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-08 23:38:21 +0000
commit51e6efd247934b09cd531428411f6ed377e5665d (patch)
tree24286f252a2815997dadbb43972cee09f47ed64b /sync/tools
parenta39feb9e9cc9ac5c63e8a481aee6e8f8ef39c872 (diff)
downloadchromium_src-51e6efd247934b09cd531428411f6ed377e5665d.zip
chromium_src-51e6efd247934b09cd531428411f6ed377e5665d.tar.gz
chromium_src-51e6efd247934b09cd531428411f6ed377e5665d.tar.bz2
sync: Inject sync/'s dependency on invalidations
Defines an InvalidationInterface class and uses it to break any direct dependencies from sync code on syncer::Invalidation. Despite its name, syncer::Invalidation should belong solely to the invalidations component, which code in the sync/ directory should not depend on. Changes the interface in the sync engine from copying syncer::Invalidation to managing scoped_ptr<InvalidationInterface>. This change in memory management was required to support the use of an abstract interface. Removes the DroppedInvaldiationTracker. This class was previously only used by sync. The small benefit provided by this class is outweighed by the amount of glue code it would take to maintain it. Changes tests to conform to the new interface. Adds some test-only implementations of InvalidationInterface and some associated classes. BUG=259559 Review URL: https://codereview.chromium.org/322333004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@281884 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/tools')
-rw-r--r--sync/tools/sync_client.cc78
1 files changed, 76 insertions, 2 deletions
diff --git a/sync/tools/sync_client.cc b/sync/tools/sync_client.cc
index a5890cf..2b626db 100644
--- a/sync/tools/sync_client.cc
+++ b/sync/tools/sync_client.cc
@@ -42,6 +42,7 @@
#include "sync/internal_api/public/util/weak_handle.h"
#include "sync/js/js_event_details.h"
#include "sync/js/js_event_handler.h"
+#include "sync/notifier/object_id_invalidation_map.h"
#include "sync/test/fake_encryptor.h"
#include "sync/tools/null_invalidation_state_tracker.h"
@@ -184,6 +185,78 @@ class LoggingJsEventHandler
}
};
+class InvalidationAdapter : public syncer::InvalidationInterface {
+ public:
+ explicit InvalidationAdapter(const syncer::Invalidation& invalidation)
+ : invalidation_(invalidation) {}
+ virtual ~InvalidationAdapter() {}
+
+ virtual bool IsUnknownVersion() const OVERRIDE {
+ return invalidation_.is_unknown_version();
+ }
+
+ virtual const std::string& GetPayload() const OVERRIDE {
+ return invalidation_.payload();
+ }
+
+ virtual int64 GetVersion() const OVERRIDE {
+ return invalidation_.version();
+ }
+
+ virtual void Acknowledge() OVERRIDE {
+ invalidation_.Acknowledge();
+ }
+
+ virtual void Drop() OVERRIDE {
+ invalidation_.Drop();
+ }
+
+ private:
+ syncer::Invalidation invalidation_;
+};
+
+class InvalidatorShim : public InvalidationHandler {
+ public:
+ explicit InvalidatorShim(SyncManager* sync_manager)
+ : sync_manager_(sync_manager) {}
+
+ virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE {
+ sync_manager_->OnInvalidatorStateChange(state);
+ }
+
+ virtual void OnIncomingInvalidation(
+ const ObjectIdInvalidationMap& invalidation_map) OVERRIDE {
+ syncer::ObjectIdSet ids = invalidation_map.GetObjectIds();
+ for (syncer::ObjectIdSet::const_iterator ids_it = ids.begin();
+ ids_it != ids.end();
+ ++ids_it) {
+ syncer::ModelType type;
+ if (!NotificationTypeToRealModelType(ids_it->name(), &type)) {
+ DLOG(WARNING) << "Notification has invalid id: "
+ << syncer::ObjectIdToString(*ids_it);
+ } else {
+ syncer::SingleObjectInvalidationSet invalidation_set =
+ invalidation_map.ForObject(*ids_it);
+ for (syncer::SingleObjectInvalidationSet::const_iterator inv_it =
+ invalidation_set.begin();
+ inv_it != invalidation_set.end();
+ ++inv_it) {
+ scoped_ptr<syncer::InvalidationInterface> inv_adapter(
+ new InvalidationAdapter(*inv_it));
+ sync_manager_->OnIncomingInvalidation(type, inv_adapter.Pass());
+ }
+ }
+ }
+ }
+
+ virtual std::string GetOwnerName() const OVERRIDE {
+ return "InvalidatorShim";
+ }
+
+ private:
+ SyncManager* sync_manager_;
+};
+
void LogUnrecoverableErrorContext() {
base::debug::StackTrace().Print();
}
@@ -380,9 +453,10 @@ int SyncClientMain(int argc, char* argv[]) {
// TODO(akalin): Avoid passing in model parameters multiple times by
// organizing handling of model types.
invalidator->UpdateCredentials(credentials.email, credentials.sync_token);
- invalidator->RegisterHandler(sync_manager.get());
+ scoped_ptr<InvalidatorShim> shim(new InvalidatorShim(sync_manager.get()));
+ invalidator->RegisterHandler(shim.get());
invalidator->UpdateRegisteredIds(
- sync_manager.get(), ModelTypeSetToObjectIdSet(model_types));
+ shim.get(), ModelTypeSetToObjectIdSet(model_types));
sync_manager->StartSyncingNormally(routing_info);
sync_loop.Run();