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 #ifndef CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ |
6 #define CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ | 6 #define CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ |
7 | 7 |
| 8 #include <list> |
| 9 #include <utility> |
| 10 |
8 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
9 #include "chrome/browser/invalidation/invalidation_service.h" | 12 #include "chrome/browser/invalidation/invalidation_service.h" |
10 #include "sync/notifier/invalidator_registrar.h" | 13 #include "sync/notifier/invalidator_registrar.h" |
11 | 14 |
12 namespace invalidation { | 15 namespace invalidation { |
13 | 16 |
14 // An InvalidationService that emits invalidations only when | 17 // An InvalidationService that emits invalidations only when |
15 // its EmitInvalidationForTest method is called. | 18 // its EmitInvalidationForTest method is called. |
16 class FakeInvalidationService : public InvalidationService { | 19 class FakeInvalidationService : public InvalidationService { |
17 public: | 20 public: |
18 FakeInvalidationService(); | 21 FakeInvalidationService(); |
19 virtual ~FakeInvalidationService(); | 22 virtual ~FakeInvalidationService(); |
20 | 23 |
21 virtual void RegisterInvalidationHandler( | 24 virtual void RegisterInvalidationHandler( |
22 syncer::InvalidationHandler* handler) OVERRIDE; | 25 syncer::InvalidationHandler* handler) OVERRIDE; |
23 virtual void UpdateRegisteredInvalidationIds( | 26 virtual void UpdateRegisteredInvalidationIds( |
24 syncer::InvalidationHandler* handler, | 27 syncer::InvalidationHandler* handler, |
25 const syncer::ObjectIdSet& ids) OVERRIDE; | 28 const syncer::ObjectIdSet& ids) OVERRIDE; |
26 virtual void UnregisterInvalidationHandler( | 29 virtual void UnregisterInvalidationHandler( |
27 syncer::InvalidationHandler* handler) OVERRIDE; | 30 syncer::InvalidationHandler* handler) OVERRIDE; |
28 | 31 |
29 virtual void AcknowledgeInvalidation( | 32 virtual void AcknowledgeInvalidation( |
30 const invalidation::ObjectId& id, | 33 const invalidation::ObjectId& id, |
31 const syncer::AckHandle& ack_handle) OVERRIDE; | 34 const syncer::AckHandle& ack_handle) OVERRIDE; |
32 | 35 |
33 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | 36 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; |
34 virtual std::string GetInvalidatorClientId() const OVERRIDE; | 37 virtual std::string GetInvalidatorClientId() const OVERRIDE; |
35 | 38 |
36 void EmitInvalidationForTest( | 39 void SetInvalidatorState(syncer::InvalidatorState state); |
| 40 |
| 41 const syncer::InvalidatorRegistrar& invalidator_registrar() const { |
| 42 return invalidator_registrar_; |
| 43 } |
| 44 syncer::AckHandle EmitInvalidationForTest( |
37 const invalidation::ObjectId& object_id, | 45 const invalidation::ObjectId& object_id, |
38 int64 version, | 46 int64 version, |
39 const std::string& payload); | 47 const std::string& payload); |
40 | 48 |
| 49 // Determines if the given AckHandle has been acknowledged. |
| 50 bool IsInvalidationAcknowledged(const syncer::AckHandle& ack_handle) const; |
| 51 |
| 52 // Determines if AcknowledgeInvalidation was ever called with an invalid |
| 53 // ObjectId/AckHandle pair. |
| 54 bool ReceivedInvalidAcknowledgement() { |
| 55 return received_invalid_acknowledgement_; |
| 56 } |
| 57 |
41 private: | 58 private: |
42 std::string client_id_; | 59 std::string client_id_; |
43 syncer::InvalidatorRegistrar invalidator_registrar_; | 60 syncer::InvalidatorRegistrar invalidator_registrar_; |
| 61 typedef std::list<std::pair<syncer::AckHandle, invalidation::ObjectId> > |
| 62 AckHandleList; |
| 63 AckHandleList unacknowledged_handles_; |
| 64 AckHandleList acknowledged_handles_; |
| 65 bool received_invalid_acknowledgement_; |
44 | 66 |
45 DISALLOW_COPY_AND_ASSIGN(FakeInvalidationService); | 67 DISALLOW_COPY_AND_ASSIGN(FakeInvalidationService); |
46 }; | 68 }; |
47 | 69 |
48 } // namespace invalidation | 70 } // namespace invalidation |
49 | 71 |
50 #endif // CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ | 72 #endif // CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ |
OLD | NEW |