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 //
     31 // Copy and assign are allowed for this class so we can use it in STL
     32 // containers.
     33 class SYNC_EXPORT DroppedInvalidationTracker {
     34  public:
     35   explicit DroppedInvalidationTracker(const invalidation::ObjectId& id);
     36   ~DroppedInvalidationTracker();
     37 
     38   const invalidation::ObjectId& object_id() const;
     39 
     40   // Called by Invalidation::Drop() to keep track of a drop event.
     41   //
     42   // Takes ownership of the internals belonging to a soon to be discarded
     43   // dropped invalidation.  See also the comment for this class'
     44   // |drop_ack_handler_| member.
     45   void RecordDropEvent(WeakHandle<AckHandler> handler, AckHandle handle);
     46 
     47   // Returns true if we're still recovering from a drop event.
     48   bool IsRecoveringFromDropEvent() const;
     49 
     50   // Called by the InvalidationHandler when it recovers from the drop event.
     51   void RecordRecoveryFromDropEvent();
     52 
     53  private:
     54   invalidation::ObjectId id_;
     55   AckHandle drop_ack_handle_;
     56 
     57   // This flag is set to true when we have dropped an invalidation and have not
     58   // yet recovered from this drop event.  Note that this may not always coincide
     59   // with drop_ack_handler_ being initialized because a null AckHandler could be
     60   // passed in to RecordDropEvent().
     61   bool recovering_from_drop_;
     62 
     63   // A WeakHandle to the enitity responsible for persisting invalidation
     64   // acknowledgement state on disk.  We can get away with using a WeakHandle
     65   // because we don't care if our drop recovery message doesn't gets delivered
     66   // in some shutdown cases.  If that happens, we'll have to process the
     67   // invalidation state again on the next restart.  It would be a waste of time
     68   // and resources, but otherwise not particularly harmful.
     69   WeakHandle<AckHandler> drop_ack_handler_;
     70 };
     71 
     72 }  // namespace syncer
     73 
     74 #endif  // SYNC_NOTIFIER_DROPPED_INVALIDATION_TRACKER_H_
     75