OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/invalidation/fake_invalidation_service.h" | 5 #include "chrome/browser/invalidation/fake_invalidation_service.h" |
6 | 6 |
7 #include "chrome/browser/invalidation/invalidation_service_util.h" | 7 #include "chrome/browser/invalidation/invalidation_service_util.h" |
8 | 8 |
9 namespace invalidation { | 9 namespace invalidation { |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... | |
27 } | 27 } |
28 | 28 |
29 void FakeInvalidationService::UnregisterInvalidationHandler( | 29 void FakeInvalidationService::UnregisterInvalidationHandler( |
30 syncer::InvalidationHandler* handler) { | 30 syncer::InvalidationHandler* handler) { |
31 invalidator_registrar_.UnregisterHandler(handler); | 31 invalidator_registrar_.UnregisterHandler(handler); |
32 } | 32 } |
33 | 33 |
34 void FakeInvalidationService::AcknowledgeInvalidation( | 34 void FakeInvalidationService::AcknowledgeInvalidation( |
35 const invalidation::ObjectId& id, | 35 const invalidation::ObjectId& id, |
36 const syncer::AckHandle& ack_handle) { | 36 const syncer::AckHandle& ack_handle) { |
37 // TODO(sync): Use assertions to ensure this function is invoked correctly. | 37 // Try to find the given handle and object id in the unacknowledged list. |
38 AckHandleList::iterator handle; | |
39 AckHandleList::iterator begin = unacknowledged_handles_.begin(); | |
40 AckHandleList::iterator end = unacknowledged_handles_.end(); | |
41 for (handle = begin; handle != end; handle++) | |
Joao da Silva
2013/07/23 20:44:47
++handle
Steve Condie
2013/07/24 01:42:04
Done.
| |
42 if (handle->first.Equals(ack_handle) && handle->second == id) | |
43 break; | |
44 if (handle == end) | |
45 received_invalid_acknowledgement_ = false; | |
46 else | |
47 unacknowledged_handles_.erase(handle); | |
48 | |
49 // Add to the acknowledged list. | |
50 acknowledged_handles_.push_back(AckHandleList::value_type(ack_handle, id)); | |
38 } | 51 } |
39 | 52 |
40 syncer::InvalidatorState FakeInvalidationService::GetInvalidatorState() const { | 53 syncer::InvalidatorState FakeInvalidationService::GetInvalidatorState() const { |
41 return syncer::INVALIDATIONS_ENABLED; | 54 return syncer::INVALIDATIONS_ENABLED; |
42 } | 55 } |
43 | 56 |
44 std::string FakeInvalidationService::GetInvalidatorClientId() const { | 57 std::string FakeInvalidationService::GetInvalidatorClientId() const { |
45 return client_id_; | 58 return client_id_; |
46 } | 59 } |
47 | 60 |
48 void FakeInvalidationService::EmitInvalidationForTest( | 61 syncer::AckHandle FakeInvalidationService::EmitInvalidationForTest( |
49 const invalidation::ObjectId& object_id, | 62 const invalidation::ObjectId& object_id, |
50 int64 version, | 63 int64 version, |
51 const std::string& payload) { | 64 const std::string& payload) { |
52 syncer::ObjectIdInvalidationMap invalidation_map; | 65 syncer::ObjectIdInvalidationMap invalidation_map; |
53 | 66 |
54 syncer::Invalidation inv; | 67 syncer::Invalidation inv; |
55 inv.version = version; | 68 inv.version = version; |
56 inv.payload = payload; | 69 inv.payload = payload; |
57 inv.ack_handle = syncer::AckHandle::CreateUnique(); | 70 inv.ack_handle = syncer::AckHandle::CreateUnique(); |
58 | 71 |
59 invalidation_map.insert(std::make_pair(object_id, inv)); | 72 invalidation_map.insert(std::make_pair(object_id, inv)); |
60 | 73 |
61 invalidator_registrar_.DispatchInvalidationsToHandlers(invalidation_map); | 74 invalidator_registrar_.DispatchInvalidationsToHandlers(invalidation_map); |
75 | |
76 unacknowledged_handles_.push_back( | |
77 AckHandleList::value_type(inv.ack_handle, object_id)); | |
78 return inv.ack_handle; | |
79 } | |
80 | |
81 bool FakeInvalidationService::IsInvalidationAcknowledged( | |
82 const syncer::AckHandle& ack_handle) const { | |
83 // Try to find the given handle in the acknowledged list. | |
84 AckHandleList::const_iterator begin = acknowledged_handles_.begin(); | |
85 AckHandleList::const_iterator end = acknowledged_handles_.end(); | |
86 for (AckHandleList::const_iterator handle = begin; handle != end; handle++) | |
Joao da Silva
2013/07/23 20:44:47
++handle
Steve Condie
2013/07/24 01:42:04
Done.
| |
87 if (handle->first.Equals(ack_handle)) | |
88 return true; | |
89 return false; | |
62 } | 90 } |
63 | 91 |
64 } // namespace invalidation | 92 } // namespace invalidation |
OLD | NEW |