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

Side by Side Diff: sync/internal_api/public/base/invalidation.h

Issue 23441042: Refactor common invalidation framework types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move DEPS rule Created 7 years, 2 months 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 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_ 5 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_
6 #define SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_ 6 #define SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h" 12 #include "base/values.h"
13 #include "google/cacheinvalidation/include/types.h"
13 #include "sync/base/sync_export.h" 14 #include "sync/base/sync_export.h"
14 15 #include "sync/internal_api/public/base/ack_handle.h"
15 namespace base {
16 class DictionaryValue;
17 } // namespace
18 16
19 namespace syncer { 17 namespace syncer {
20 18
21 // Opaque class that represents a local ack handle. We don't reuse the 19 class DroppedInvalidationTracker;
22 // invalidation ack handles to avoid unnecessary dependencies. 20 class AckHandler;
23 class SYNC_EXPORT AckHandle { 21
22 // Represents a local invalidation, and is roughly analogous to
23 // invalidation::Invalidation. Unlike invalidation::Invalidation, this class
24 // supports "local" ack-tracking and simple serialization to pref values.
25 class SYNC_EXPORT Invalidation {
24 public: 26 public:
25 static AckHandle CreateUnique(); 27 // Factory functions.
26 static AckHandle InvalidAckHandle(); 28 static Invalidation Init(
29 const invalidation::ObjectId& id,
30 int64 version,
31 const std::string& payload);
32 static Invalidation InitUnknownVersion(const invalidation::ObjectId& id);
33 static scoped_ptr<Invalidation> InitFromValue(
34 const base::DictionaryValue& value);
27 35
28 bool Equals(const AckHandle& other) const; 36 ~Invalidation();
37
38 // Compares two invalidations. The comparison ignores ack-tracking state.
39 bool Equals(const Invalidation& other) const;
40
41 invalidation::ObjectId object_id() const;
42 bool is_unknown_version() const;
43
44 // Safe to call only if is_unknown_version() returns false.
45 int64 version() const;
46
47 // Safe to call only if is_unknown_version() returns false.
48 const std::string& payload() const;
49
50 const AckHandle& ack_handle() const;
51 void set_ack_handle(const AckHandle& ack_handle);
29 52
30 scoped_ptr<base::DictionaryValue> ToValue() const; 53 scoped_ptr<base::DictionaryValue> ToValue() const;
31 bool ResetFromValue(const base::DictionaryValue& value); 54 std::string ToString() const;
32
33 bool IsValid() const;
34
35 ~AckHandle();
36 55
37 private: 56 private:
38 // Explicitly copyable and assignable for STL containers. 57 Invalidation(const invalidation::ObjectId& id,
39 AckHandle(const std::string& state, base::Time timestamp); 58 bool is_unknown_version,
59 int64 version,
60 const std::string& payload,
61 AckHandle ack_handle);
40 62
41 std::string state_; 63 // The ObjectId to which this invalidation belongs.
42 base::Time timestamp_; 64 invalidation::ObjectId id_;
43 };
44 65
45 // Represents a local invalidation, and is roughly analogous to 66 // This flag is set to true if this is an unknown version invalidation.
46 // invalidation::Invalidation. It contains a version (which may be 67 bool is_unknown_version_;
47 // kUnknownVersion), a payload (which may be empty) and an
48 // associated ack handle that an InvalidationHandler implementation can use to
49 // acknowledge receipt of the invalidation. It does not embed the object ID,
50 // since it is typically associated with it through ObjectIdInvalidationMap.
51 struct SYNC_EXPORT Invalidation {
52 static const int64 kUnknownVersion;
53 68
54 Invalidation(); 69 // The version number of this invalidation. Should not be accessed if this is
55 ~Invalidation(); 70 // an unkown version invalidation.
71 int64 version_;
56 72
57 bool Equals(const Invalidation& other) const; 73 // The payaload associated with this invalidation. Should not be accessed if
74 // this is an unknown version invalidation.
75 std::string payload_;
58 76
59 scoped_ptr<base::DictionaryValue> ToValue() const; 77 // A locally generated unique ID used to manage local acknowledgements.
60 bool ResetFromValue(const base::DictionaryValue& value); 78 AckHandle ack_handle_;
61
62 int64 version;
63 std::string payload;
64 AckHandle ack_handle;
65 }; 79 };
66 80
67 } // namespace syncer 81 } // namespace syncer
68 82
69 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_ 83 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_H_
OLDNEW
« no previous file with comments | « sync/internal_api/public/base/ack_handle.cc ('k') | sync/internal_api/public/base/invalidation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698