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

Unified Diff: chrome/browser/invalidation/fake_invalidation_service.cc

Issue 19733003: Implement cloud policy invalidations using the invalidation service framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
Index: chrome/browser/invalidation/fake_invalidation_service.cc
diff --git a/chrome/browser/invalidation/fake_invalidation_service.cc b/chrome/browser/invalidation/fake_invalidation_service.cc
index a19f4fb092b4b68777bd96cee070c8af6b61e2fb..dcf5c2f05aeb3aa0194cbdce820ce4cc604abcd9 100644
--- a/chrome/browser/invalidation/fake_invalidation_service.cc
+++ b/chrome/browser/invalidation/fake_invalidation_service.cc
@@ -9,7 +9,9 @@
namespace invalidation {
FakeInvalidationService::FakeInvalidationService()
- : client_id_(GenerateInvalidatorClientId()) {
+ : client_id_(GenerateInvalidatorClientId()),
+ received_invalid_acknowledgement_(false) {
+ invalidator_registrar_.UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED);
}
FakeInvalidationService::~FakeInvalidationService() {
@@ -34,18 +36,36 @@ void FakeInvalidationService::UnregisterInvalidationHandler(
void FakeInvalidationService::AcknowledgeInvalidation(
const invalidation::ObjectId& id,
const syncer::AckHandle& ack_handle) {
- // TODO(sync): Use assertions to ensure this function is invoked correctly.
+ // Try to find the given handle and object id in the unacknowledged list.
+ AckHandleList::iterator handle;
+ AckHandleList::iterator begin = unacknowledged_handles_.begin();
+ AckHandleList::iterator end = unacknowledged_handles_.end();
+ for (handle = begin; handle != end; ++handle)
+ if (handle->first.Equals(ack_handle) && handle->second == id)
+ break;
+ if (handle == end)
+ received_invalid_acknowledgement_ = false;
+ else
+ unacknowledged_handles_.erase(handle);
+
+ // Add to the acknowledged list.
+ acknowledged_handles_.push_back(AckHandleList::value_type(ack_handle, id));
}
syncer::InvalidatorState FakeInvalidationService::GetInvalidatorState() const {
- return syncer::INVALIDATIONS_ENABLED;
+ return invalidator_registrar_.GetInvalidatorState();
}
std::string FakeInvalidationService::GetInvalidatorClientId() const {
return client_id_;
}
-void FakeInvalidationService::EmitInvalidationForTest(
+void FakeInvalidationService::SetInvalidatorState(
+ syncer::InvalidatorState state) {
+ invalidator_registrar_.UpdateInvalidatorState(state);
+}
+
+syncer::AckHandle FakeInvalidationService::EmitInvalidationForTest(
const invalidation::ObjectId& object_id,
int64 version,
const std::string& payload) {
@@ -57,8 +77,23 @@ void FakeInvalidationService::EmitInvalidationForTest(
inv.ack_handle = syncer::AckHandle::CreateUnique();
invalidation_map.insert(std::make_pair(object_id, inv));
+ unacknowledged_handles_.push_back(
+ AckHandleList::value_type(inv.ack_handle, object_id));
invalidator_registrar_.DispatchInvalidationsToHandlers(invalidation_map);
+
+ return inv.ack_handle;
+}
+
+bool FakeInvalidationService::IsInvalidationAcknowledged(
+ const syncer::AckHandle& ack_handle) const {
+ // Try to find the given handle in the acknowledged list.
+ AckHandleList::const_iterator begin = acknowledged_handles_.begin();
+ AckHandleList::const_iterator end = acknowledged_handles_.end();
+ for (AckHandleList::const_iterator handle = begin; handle != end; ++handle)
+ if (handle->first.Equals(ack_handle))
+ return true;
+ return false;
}
} // namespace invalidation

Powered by Google App Engine
This is Rietveld 408576698