Home | History | Annotate | Download | only in test
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef SYNC_TEST_MOCK_INVALIDATION_TRACKER_H_
      6 #define SYNC_TEST_MOCK_INVALIDATION_TRACKER_H_
      7 
      8 #include <set>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "sync/test/trackable_mock_invalidation.h"
     12 
     13 namespace syncer {
     14 
     15 // Instantiates and track the acknowledgement state of
     16 // TrackableMockInvalidations.
     17 class MockInvalidationTracker {
     18  public:
     19   // Builers to return new TrackableMockInvalidations associated with this
     20   // object.
     21   scoped_ptr<TrackableMockInvalidation> IssueUnknownVersionInvalidation();
     22   scoped_ptr<TrackableMockInvalidation> IssueInvalidation(
     23       int64 version,
     24       const std::string& payload);
     25 
     26   MockInvalidationTracker();
     27   ~MockInvalidationTracker();
     28 
     29   // Records the acknowledgement of the invalidation
     30   // specified by the given ID.
     31   void Acknowledge(int invaliation_id);
     32 
     33   // Records the drop of the invalidation specified by the given ID.
     34   void Drop(int invalidation_id);
     35 
     36   // Returns true if the invalidation associated with the given ID is neither
     37   // acknowledged nor dropped.
     38   bool IsUnacked(int invalidation_id) const;
     39 
     40   // Returns true if the invalidation associated with the given ID is
     41   // acknowledged.
     42   bool IsAcknowledged(int invalidation_id) const;
     43 
     44   // Returns true if the invalidation associated with the given ID is dropped.
     45   bool IsDropped(int invalidation_id) const;
     46 
     47   // Returns true if all issued invalidations were acknowledged or dropped.
     48   bool AllInvalidationsAccountedFor() const;
     49 
     50  private:
     51   // A counter used to assign strictly increasing IDs to each invalidation
     52   // issued by this class.
     53   int next_id_;
     54 
     55   // Acknowledgements and drops are tracked by adding the IDs for the
     56   // acknowledged or dropped items to the proper set.  An invalidation may be
     57   // both dropped and acknowledged if it represents the recovery from a drop
     58   // event.
     59   std::set<int> dropped_;
     60   std::set<int> acknowledged_;
     61 };
     62 
     63 }  // namespace syncer
     64 
     65 #endif  // SYNC_TEST_MOCK_INVALIDATION_TRACKER_H_
     66