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

Side by Side Diff: chrome/browser/invalidation/fake_invalidation_service.cc

Issue 23754021: Invalidation trickles mega-patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "sync/notifier/object_id_invalidation_map.h"
8 9
9 namespace invalidation { 10 namespace invalidation {
10 11
11 FakeInvalidationService::FakeInvalidationService() 12 FakeInvalidationService::FakeInvalidationService()
12 : client_id_(GenerateInvalidatorClientId()), 13 : client_id_(GenerateInvalidatorClientId()) {
13 received_invalid_acknowledgement_(false) {
14 invalidator_registrar_.UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED); 14 invalidator_registrar_.UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED);
15 } 15 }
16 16
17 FakeInvalidationService::~FakeInvalidationService() { 17 FakeInvalidationService::~FakeInvalidationService() {
18 } 18 }
19 19
20 void FakeInvalidationService::RegisterInvalidationHandler( 20 void FakeInvalidationService::RegisterInvalidationHandler(
21 syncer::InvalidationHandler* handler) { 21 syncer::InvalidationHandler* handler) {
22 invalidator_registrar_.RegisterHandler(handler); 22 invalidator_registrar_.RegisterHandler(handler);
23 } 23 }
24 24
25 void FakeInvalidationService::UpdateRegisteredInvalidationIds( 25 void FakeInvalidationService::UpdateRegisteredInvalidationIds(
26 syncer::InvalidationHandler* handler, 26 syncer::InvalidationHandler* handler,
27 const syncer::ObjectIdSet& ids) { 27 const syncer::ObjectIdSet& ids) {
28 invalidator_registrar_.UpdateRegisteredIds(handler, ids); 28 invalidator_registrar_.UpdateRegisteredIds(handler, ids);
29 } 29 }
30 30
31 void FakeInvalidationService::UnregisterInvalidationHandler( 31 void FakeInvalidationService::UnregisterInvalidationHandler(
32 syncer::InvalidationHandler* handler) { 32 syncer::InvalidationHandler* handler) {
33 invalidator_registrar_.UnregisterHandler(handler); 33 invalidator_registrar_.UnregisterHandler(handler);
34 } 34 }
35 35
36 void FakeInvalidationService::AcknowledgeInvalidation(
37 const invalidation::ObjectId& id,
38 const syncer::AckHandle& ack_handle) {
39 // Try to find the given handle and object id in the unacknowledged list.
40 AckHandleList::iterator handle;
41 AckHandleList::iterator begin = unacknowledged_handles_.begin();
42 AckHandleList::iterator end = unacknowledged_handles_.end();
43 for (handle = begin; handle != end; ++handle)
44 if (handle->first.Equals(ack_handle) && handle->second == id)
45 break;
46 if (handle == end)
47 received_invalid_acknowledgement_ = false;
48 else
49 unacknowledged_handles_.erase(handle);
50
51 // Add to the acknowledged list.
52 acknowledged_handles_.push_back(AckHandleList::value_type(ack_handle, id));
53 }
54
55 syncer::InvalidatorState FakeInvalidationService::GetInvalidatorState() const { 36 syncer::InvalidatorState FakeInvalidationService::GetInvalidatorState() const {
56 return invalidator_registrar_.GetInvalidatorState(); 37 return invalidator_registrar_.GetInvalidatorState();
57 } 38 }
58 39
59 std::string FakeInvalidationService::GetInvalidatorClientId() const { 40 std::string FakeInvalidationService::GetInvalidatorClientId() const {
60 return client_id_; 41 return client_id_;
61 } 42 }
62 43
63 void FakeInvalidationService::SetInvalidatorState( 44 void FakeInvalidationService::SetInvalidatorState(
64 syncer::InvalidatorState state) { 45 syncer::InvalidatorState state) {
65 invalidator_registrar_.UpdateInvalidatorState(state); 46 invalidator_registrar_.UpdateInvalidatorState(state);
66 } 47 }
67 48
68 syncer::AckHandle FakeInvalidationService::EmitInvalidationForTest( 49 void FakeInvalidationService::EmitInvalidationForTest(
69 const invalidation::ObjectId& object_id, 50 const syncer::Invalidation& invalidation) {
70 int64 version, 51 // This function might need to modify the invalidator, so we start by making
71 const std::string& payload) { 52 // an identical copy of it.
53 syncer::Invalidation invalidation_copy(invalidation);
54
55 // If no one is listening to this invalidation, do not send it out.
56 syncer::ObjectIdSet registered_ids =
57 invalidator_registrar_.GetAllRegisteredIds();
58 if (registered_ids.find(invalidation.GetObjectId()) == registered_ids.end()) {
59 mock_ack_handler_.RegisterUnsentInvalidation(&invalidation_copy);
60 return;
61 }
62
63 // Otherwise, register the invalidation with the mock_ack_handler_ and deliver
64 // it to the appropriate consumer.
65 mock_ack_handler_.RegisterInvalidation(&invalidation_copy);
72 syncer::ObjectIdInvalidationMap invalidation_map; 66 syncer::ObjectIdInvalidationMap invalidation_map;
73 67 invalidation_map.Insert(invalidation_copy);
74 syncer::Invalidation inv;
75 inv.version = version;
76 inv.payload = payload;
77 inv.ack_handle = syncer::AckHandle::CreateUnique();
78
79 invalidation_map.insert(std::make_pair(object_id, inv));
80 unacknowledged_handles_.push_back(
81 AckHandleList::value_type(inv.ack_handle, object_id));
82
83 invalidator_registrar_.DispatchInvalidationsToHandlers(invalidation_map); 68 invalidator_registrar_.DispatchInvalidationsToHandlers(invalidation_map);
84
85 return inv.ack_handle;
86 } 69 }
87 70
88 bool FakeInvalidationService::IsInvalidationAcknowledged( 71 syncer::MockAckHandler* FakeInvalidationService::GetMockAckHandler() {
89 const syncer::AckHandle& ack_handle) const { 72 return &mock_ack_handler_;
90 // Try to find the given handle in the acknowledged list.
91 AckHandleList::const_iterator begin = acknowledged_handles_.begin();
92 AckHandleList::const_iterator end = acknowledged_handles_.end();
93 for (AckHandleList::const_iterator handle = begin; handle != end; ++handle)
94 if (handle->first.Equals(ack_handle))
95 return true;
96 return false;
97 } 73 }
98 74
99 } // namespace invalidation 75 } // namespace invalidation
OLDNEW
« no previous file with comments | « chrome/browser/invalidation/fake_invalidation_service.h ('k') | chrome/browser/invalidation/invalidation_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698