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

Side by Side Diff: sync/engine/worker_entity_tracker.h

Issue 1933803002: [Sync] USS: Ignore encryption changes during conflict resolution 2/2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Can't use &&, whoops. Created 4 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_ENGINE_WORKER_ENTITY_TRACKER_H_ 5 #ifndef SYNC_ENGINE_WORKER_ENTITY_TRACKER_H_
6 #define SYNC_ENGINE_WORKER_ENTITY_TRACKER_H_ 6 #define SYNC_ENGINE_WORKER_ENTITY_TRACKER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "sync/base/sync_export.h" 15 #include "sync/base/sync_export.h"
16 #include "sync/protocol/sync.pb.h" 16 #include "sync/protocol/sync.pb.h"
17 17
18 namespace syncer_v2 { 18 namespace syncer_v2 {
19 struct CommitRequestData; 19 struct CommitRequestData;
20 struct CommitResponseData;
20 struct UpdateResponseData; 21 struct UpdateResponseData;
21 22
22 // Manages the pending commit and update state for an entity on the sync 23 // Manages the pending commit and update state for an entity on the sync
23 // thread. 24 // thread.
24 // 25 //
25 // It should be considered a helper class internal to the 26 // It should be considered a helper class internal to the
26 // ModelTypeWorker. 27 // ModelTypeWorker.
27 // 28 //
28 // Maintains the state associated with a particular sync entity which is 29 // Maintains the state associated with a particular sync entity which is
29 // necessary for decision-making on the sync thread. It can track pending 30 // necessary for decision-making on the sync thread. It can track pending
30 // commit state, received update state, and can detect conflicts. 31 // commit state, received update state, and can detect conflicts.
31 // 32 //
32 // This object may contain state associated with a pending commit, pending 33 // This object may contain state associated with a pending commit, pending
33 // update, or both. 34 // update, or both.
34 class SYNC_EXPORT WorkerEntityTracker { 35 class SYNC_EXPORT WorkerEntityTracker {
35 public: 36 public:
36 // Initializes the entity tracker's main fields. Does not initialize state 37 // Initializes the entity tracker's main fields. Does not initialize state
37 // related to a pending commit. 38 // related to a pending commit.
38 WorkerEntityTracker(const std::string& id, 39 WorkerEntityTracker(const std::string& id,
39 const std::string& client_tag_hash); 40 const std::string& client_tag_hash);
40 41
41 ~WorkerEntityTracker(); 42 ~WorkerEntityTracker();
42 43
43 // Returns true if this entity should be commited to the server. 44 // Returns true if this entity should be commited to the server.
44 bool HasPendingCommit() const; 45 bool HasPendingCommit() const;
45 46
46 // Populates a sync_pb::SyncEntity for a commit. Also sets the 47 // Populates a sync_pb::SyncEntity for a commit.
47 // |sequence_number|, so we can track it throughout the commit process. 48 void PopulateCommitProto(sync_pb::SyncEntity* commit_entity) const;
48 void PopulateCommitProto(sync_pb::SyncEntity* commit_entity,
49 int64_t* sequence_number) const;
50 49
51 // Updates this entity with data from the latest version that the 50 // Updates this entity with data from the latest version that the
52 // model asked us to commit. May clobber state related to the 51 // model asked us to commit. May clobber state related to the
53 // model's previous commit attempt(s). 52 // model's previous commit attempt(s).
54 void RequestCommit(const CommitRequestData& data); 53 void RequestCommit(const CommitRequestData& data);
55 54
56 // Handles the receipt of a commit response. 55 // Handles the receipt of a commit response.
57 // 56 //
58 // Since commits happen entirely on the sync thread, we can safely assume 57 // Since commits happen synchronously on the sync thread, our item's state
59 // that our item's state at the end of the commit is the same as it was at 58 // at the end of the commit is the same as it was at the start, which is
60 // the start. 59 // leveraged to let us fill some local-only data in on |ack|.
skym 2016/04/29 18:43:19 This is phrased like an implementation/definition
maxbogue 2016/05/03 17:46:15 I moved the bulk of the comment to the implementat
61 void ReceiveCommitResponse(const std::string& response_id, 60 void ReceiveCommitResponse(CommitResponseData* ack);
62 int64_t response_version,
63 int64_t sequence_number);
64 61
65 // Handles receipt of an update from the server. 62 // Handles receipt of an update from the server.
66 void ReceiveUpdate(int64_t version); 63 void ReceiveUpdate(int64_t version);
67 64
68 // Handles the receipt of an encrypted update from the server. 65 // Handles the receipt of an encrypted update from the server.
69 // 66 //
70 // Returns true if the tracker decides this item is worth keeping. Returns 67 // Returns true if the tracker decides this item is worth keeping. Returns
71 // false if the item is discarded, which could happen if the version number 68 // false if the item is discarded, which could happen if the version number
72 // is out of date. 69 // is out of date.
73 bool ReceiveEncryptedUpdate(const UpdateResponseData& data); 70 bool ReceiveEncryptedUpdate(const UpdateResponseData& data);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // to do here is return it back to the model thread when the pending commit 105 // to do here is return it back to the model thread when the pending commit
109 // is completed and confirmed. Not valid if no commit is pending. 106 // is completed and confirmed. Not valid if no commit is pending.
110 int64_t sequence_number_; 107 int64_t sequence_number_;
111 108
112 // The server version on which this item is based. 109 // The server version on which this item is based.
113 int64_t base_version_; 110 int64_t base_version_;
114 111
115 // A commit for this entity waiting for a sync cycle to be committed. 112 // A commit for this entity waiting for a sync cycle to be committed.
116 std::unique_ptr<CommitRequestData> pending_commit_; 113 std::unique_ptr<CommitRequestData> pending_commit_;
117 114
115 // The specifics hash for the pending commit if there is one, "" otherwise.
116 std::string pending_commit_specifics_hash_;
117
118 // An update for this entity which can't be applied right now. The presence 118 // An update for this entity which can't be applied right now. The presence
119 // of an pending update prevents commits. As of this writing, the only 119 // of an pending update prevents commits. As of this writing, the only
120 // source of pending updates is updates that can't currently be decrypted. 120 // source of pending updates is updates that can't currently be decrypted.
121 std::unique_ptr<UpdateResponseData> encrypted_update_; 121 std::unique_ptr<UpdateResponseData> encrypted_update_;
122 122
123 DISALLOW_COPY_AND_ASSIGN(WorkerEntityTracker); 123 DISALLOW_COPY_AND_ASSIGN(WorkerEntityTracker);
124 }; 124 };
125 125
126 } // namespace syncer_v2 126 } // namespace syncer_v2
127 127
128 #endif // SYNC_ENGINE_WORKER_ENTITY_TRACKER_H_ 128 #endif // SYNC_ENGINE_WORKER_ENTITY_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698