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

Unified Diff: sync/notifier/mock_ack_handler.cc

Issue 40303005: Add code for new invalidation local ack system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another attempt at fixing win Created 7 years, 2 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/notifier/mock_ack_handler.h ('k') | sync/sync_notifier.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/notifier/mock_ack_handler.cc
diff --git a/sync/notifier/mock_ack_handler.cc b/sync/notifier/mock_ack_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a4c834e27fc0a7fde400faa07492aa6071ec26e
--- /dev/null
+++ b/sync/notifier/mock_ack_handler.cc
@@ -0,0 +1,85 @@
+// Copyright 2013 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/notifier/mock_ack_handler.h"
+
+#include "sync/internal_api/public/base/ack_handle.h"
+#include "sync/internal_api/public/base/invalidation.h"
+
+namespace syncer {
+
+namespace {
+
+struct AckHandleMatcher {
+ AckHandleMatcher(const AckHandle& handle);
+ bool operator()(const syncer::Invalidation& invalidation) const;
+
+ syncer::AckHandle handle_;
+};
+
+AckHandleMatcher::AckHandleMatcher(const AckHandle& handle)
+ : handle_(handle) {}
+
+bool AckHandleMatcher::operator()(
+ const syncer::Invalidation& invalidation) const {
+ return handle_.Equals(invalidation.ack_handle());
+}
+
+} // namespace
+
+MockAckHandler::MockAckHandler() {}
+
+MockAckHandler::~MockAckHandler() {}
+
+void MockAckHandler::RegisterInvalidation(Invalidation* invalidation) {
+ unacked_invalidations_.push_back(*invalidation);
+ invalidation->set_ack_handler(WeakHandleThis());
+}
+
+void MockAckHandler::RegisterUnsentInvalidation(Invalidation* invalidation) {
+ unsent_invalidations_.push_back(*invalidation);
+}
+
+bool MockAckHandler::IsUnacked(const Invalidation& invalidation) const {
+ AckHandleMatcher matcher(invalidation.ack_handle());
+ InvalidationVector::const_iterator it = std::find_if(
+ unacked_invalidations_.begin(),
+ unacked_invalidations_.end(),
+ matcher);
+ return it != unacked_invalidations_.end();
+}
+
+bool MockAckHandler::IsUnsent(const Invalidation& invalidation) const {
+ AckHandleMatcher matcher(invalidation.ack_handle());
+ InvalidationVector::const_iterator it1 = std::find_if(
+ unsent_invalidations_.begin(),
+ unsent_invalidations_.end(),
+ matcher);
+ return it1 != unsent_invalidations_.end();
+}
+
+void MockAckHandler::Acknowledge(
+ const invalidation::ObjectId& id,
+ const AckHandle& handle) {
+ AckHandleMatcher matcher(handle);
+ InvalidationVector::iterator it = std::find_if(
+ unacked_invalidations_.begin(),
+ unacked_invalidations_.end(),
+ matcher);
+ if (it != unacked_invalidations_.end()) {
+ acked_invalidations_.push_back(*it);
+ unacked_invalidations_.erase(it);
+ }
+}
+
+void MockAckHandler::Drop(
+ const invalidation::ObjectId& id,
+ const AckHandle& handle) {
+}
+
+WeakHandle<AckHandler> MockAckHandler::WeakHandleThis() {
+ return WeakHandle<AckHandler>(AsWeakPtr());
+}
+
+} // namespace syncer
« no previous file with comments | « sync/notifier/mock_ack_handler.h ('k') | sync/sync_notifier.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698