Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: sync/notifier/invalidation_state_tracker.h

Issue 56113003: Implement new invalidations ack tracking system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 // An InvalidationStateTracker is an interface that handles persisting state 5 // An InvalidationStateTracker is an interface that handles persisting state
6 // needed for invalidations. Currently, it is responsible for managing the 6 // needed for invalidations. Currently, it is responsible for managing the
7 // following information: 7 // following information:
8 // - Max version seen from the invalidation server to help dedupe invalidations. 8 // - Max version seen from the invalidation server to help dedupe invalidations.
9 // - Bootstrap data for the invalidation client. 9 // - Bootstrap data for the invalidation client.
10 // - Payloads and locally generated ack handles, to support local acking. 10 // - Payloads and locally generated ack handles, to support local acking.
11 11
12 #ifndef SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ 12 #ifndef SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_
13 #define SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ 13 #define SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_
14 14
15 #include <map> 15 #include <map>
16 #include <string> 16 #include <string>
17 17
18 #include "base/basictypes.h" 18 #include "base/basictypes.h"
19 #include "base/callback_forward.h" 19 #include "base/callback_forward.h"
20 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
21 #include "google/cacheinvalidation/include/types.h" 21 #include "google/cacheinvalidation/include/types.h"
22 #include "sync/base/sync_export.h" 22 #include "sync/base/sync_export.h"
23 #include "sync/internal_api/public/base/invalidation.h" 23 #include "sync/internal_api/public/base/invalidation.h"
24 #include "sync/notifier/invalidation_util.h" 24 #include "sync/notifier/invalidation_util.h"
25 #include "sync/notifier/unacked_invalidation_set.h"
25 26
26 namespace base { 27 namespace base {
27 class TaskRunner; 28 class TaskRunner;
28 } // namespace base 29 } // namespace base
29 30
30 namespace syncer { 31 namespace syncer {
31 32
32 struct SYNC_EXPORT InvalidationState {
33 InvalidationState();
34 ~InvalidationState();
35
36 int64 version;
37 std::string payload;
38 AckHandle expected;
39 AckHandle current;
40 };
41
42 // TODO(dcheng): Remove this in favor of adding an Equals() method.
43 SYNC_EXPORT_PRIVATE bool operator==(const InvalidationState& lhs,
44 const InvalidationState& rhs);
45
46 typedef std::map<invalidation::ObjectId, InvalidationState, ObjectIdLessThan>
47 InvalidationStateMap;
48 typedef std::map<invalidation::ObjectId, AckHandle, ObjectIdLessThan>
49 AckHandleMap;
50
51 class InvalidationStateTracker { 33 class InvalidationStateTracker {
52 public: 34 public:
53 InvalidationStateTracker() {} 35 InvalidationStateTracker() {}
54 36
55 virtual InvalidationStateMap GetAllInvalidationStates() const = 0;
56
57 // |max_version| should be strictly greater than any existing max
58 // version for |model_type|.
59 virtual void SetMaxVersionAndPayload(const invalidation::ObjectId& id,
60 int64 max_version,
61 const std::string& payload) = 0;
62 // Removes all state tracked for |ids|.
63 virtual void Forget(const ObjectIdSet& ids) = 0;
64
65 // The per-client unique ID used to register the invalidation client with the 37 // The per-client unique ID used to register the invalidation client with the
66 // server. This is used to squelch invalidation notifications that originate 38 // server. This is used to squelch invalidation notifications that originate
67 // from changes made by this client. 39 // from changes made by this client.
68 virtual void SetInvalidatorClientId(const std::string& data) = 0; 40 virtual void SetInvalidatorClientId(const std::string& data) = 0;
69 virtual std::string GetInvalidatorClientId() const = 0; 41 virtual std::string GetInvalidatorClientId() const = 0;
70 42
71 // Used by invalidation::InvalidationClient for persistence. |data| is an 43 // Used by invalidation::InvalidationClient for persistence. |data| is an
72 // opaque blob that an invalidation client can use after a restart to 44 // opaque blob that an invalidation client can use after a restart to
73 // bootstrap itself. |data| is binary data (not valid UTF8, embedded nulls, 45 // bootstrap itself. |data| is binary data (not valid UTF8, embedded nulls,
74 // etc). 46 // etc).
75 virtual void SetBootstrapData(const std::string& data) = 0; 47 virtual void SetBootstrapData(const std::string& data) = 0;
76 virtual std::string GetBootstrapData() const = 0; 48 virtual std::string GetBootstrapData() const = 0;
77 49
50 // Used to store invalidations that have been acked to the server, but not yet
51 // handled by our clients. We stores these invalidations on disk so we won't
tim (not reviewing) 2013/11/18 21:59:05 nit - 'We store'
rlarocque 2013/11/19 00:35:49 Done.
52 // lose them if we need to restart.
53 virtual void SetSavedInvalidations(const UnackedInvalidationsMap& states) = 0;
54 virtual UnackedInvalidationsMap GetSavedInvalidations() const = 0;
55
78 // Erases invalidation versions, client ID, and state stored on disk. 56 // Erases invalidation versions, client ID, and state stored on disk.
79 virtual void Clear() = 0; 57 virtual void Clear() = 0;
80 58
81 // Used for generating our own local ack handles. Generates a new ack handle
82 // for each object id in |ids|. The result is returned via |callback| posted
83 // to |task_runner|.
84 virtual void GenerateAckHandles(
85 const ObjectIdSet& ids,
86 const scoped_refptr<base::TaskRunner>& task_runner,
87 base::Callback<void(const AckHandleMap&)> callback) = 0;
88
89 // Records an acknowledgement for |id|. Note that no attempt at ordering is
90 // made. Acknowledge() only records the last ack_handle it received, even if
91 // the last ack_handle it received was generated before the value currently
92 // recorded.
93 virtual void Acknowledge(const invalidation::ObjectId& id,
94 const AckHandle& ack_handle) = 0;
95
96 protected: 59 protected:
97 virtual ~InvalidationStateTracker() {} 60 virtual ~InvalidationStateTracker() {}
98 }; 61 };
99 62
100 } // namespace syncer 63 } // namespace syncer
101 64
102 #endif // SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_ 65 #endif // SYNC_NOTIFIER_INVALIDATION_STATE_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698