1116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Copyright 2014 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// An InvalidationStateTracker is an interface that handles persisting state
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// needed for invalidations. Currently, it is responsible for managing the
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// following information:
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// - Max version seen from the invalidation server to help dedupe invalidations.
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// - Bootstrap data for the invalidation client.
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// - Payloads and locally generated ack handles, to support local acking.
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#ifndef COMPONENTS_INVALIDATION_INVALIDATION_STATE_TRACKER_H_
13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define COMPONENTS_INVALIDATION_INVALIDATION_STATE_TRACKER_H_
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map>
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/callback_forward.h"
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/ref_counted.h"
215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/invalidation/invalidation.h"
22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/invalidation/invalidation_export.h"
235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/invalidation/invalidation_util.h"
24116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/invalidation/unacked_invalidation_set.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "google/cacheinvalidation/include/types.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base {
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TaskRunner;
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace base
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace syncer {
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
33116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass INVALIDATION_EXPORT InvalidationStateTracker {
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
3546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  InvalidationStateTracker();
3646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual ~InvalidationStateTracker();
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The per-client unique ID used to register the invalidation client with the
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // server.  This is used to squelch invalidation notifications that originate
400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // from changes made by this client.  Setting the client ID clears all other
410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // state.
420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual void ClearAndSetNewClientId(const std::string& data) = 0;
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual std::string GetInvalidatorClientId() const = 0;
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used by invalidation::InvalidationClient for persistence. |data| is an
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // opaque blob that an invalidation client can use after a restart to
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // bootstrap itself. |data| is binary data (not valid UTF8, embedded nulls,
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // etc).
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetBootstrapData(const std::string& data) = 0;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual std::string GetBootstrapData() const = 0;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Used to store invalidations that have been acked to the server, but not yet
53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // handled by our clients.  We store these invalidations on disk so we won't
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // lose them if we need to restart.
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void SetSavedInvalidations(const UnackedInvalidationsMap& states) = 0;
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual UnackedInvalidationsMap GetSavedInvalidations() const = 0;
57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Erases invalidation versions, client ID, and state stored on disk.
59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void Clear() = 0;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace syncer
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif  // COMPONENTS_INVALIDATION_INVALIDATION_STATE_TRACKER_H_
65