Home | History | Annotate | Download | only in notifier
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef SYNC_NOTIFIER_DROPPED_INVALIDATION_TRACKER_H_
      6 #define SYNC_NOTIFIER_DROPPED_INVALIDATION_TRACKER_H_
      7 
      8 #include "google/cacheinvalidation/include/types.h"
      9 #include "sync/base/sync_export.h"
     10 #include "sync/internal_api/public/base/ack_handle.h"
     11 #include "sync/internal_api/public/util/weak_handle.h"
     12 #include "sync/notifier/ack_handler.h"
     13 
     14 namespace syncer {
     15 
     16 class Invalidation;
     17 
     18 // Helps InvalidationHandlers keep track of dropped invalidations for a given
     19 // ObjectId.
     20 //
     21 // The intent of this class is to hide some of the implementation details around
     22 // how the invalidations system manages dropping and drop recovery.  Any
     23 // invalidation handler that intends to buffer and occasionally drop
     24 // invalidations should keep one instance of it per registered ObjectId.
     25 //
     26 // When an invalidation handler wishes to drop an invalidation, it must provide
     27 // an instance of this class to that Invalidation's Drop() method.  In order to
     28 // indicate recovery from a drop, the handler can call this class'
     29 // RecordRecoveryFromDropEvent().
     30 class SYNC_EXPORT DroppedInvalidationTracker {
     31  public:
     32   explicit DroppedInvalidationTracker(const invalidation::ObjectId& id);
     33   ~DroppedInvalidationTracker();
     34 
     35   const invalidation::ObjectId& object_id() const;
     36 
     37   // Called by Invalidation::Drop() to keep track of a drop event.
     38   //
     39   // Takes ownership of the internals belonging to a soon to be discarded
     40   // dropped invalidation.  See also the comment for this class'
     41   // |drop_ack_handler_| member.
     42   void RecordDropEvent(WeakHandle<AckHandler> handler, AckHandle handle);
     43 
     44   // Returns true if we're still recovering from a drop event.
     45   bool IsRecoveringFromDropEvent() const;
     46 
     47   // Called by the InvalidationHandler when it recovers from the drop event.
     48   void RecordRecoveryFromDropEvent();
     49 
     50  private:
     51   invalidation::ObjectId id_;
     52   AckHandle drop_ack_handle_;
     53 
     54   // A WeakHandle to the enitity responsible for persisting invalidation
     55   // acknowledgement state on disk.  We can get away with using a WeakHandle
     56   // because we don't care if our drop recovery message doesn't gets delivered
     57   // in some shutdown cases.  If that happens, we'll have to process the
     58   // invalidation state again on the next restart.  It would be a waste of time
     59   // and resources, but otherwise not particularly harmful.
     60   WeakHandle<AckHandler> drop_ack_handler_;
     61 
     62   DISALLOW_COPY_AND_ASSIGN(DroppedInvalidationTracker);
     63 };
     64 
     65 }  // namespace syncer
     66 
     67 #endif  // SYNC_NOTIFIER_DROPPED_INVALIDATION_TRACKER_H_
     68