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

Side by Side Diff: sync/engine/model_type_entity.cc

Issue 442623002: Revert of sync: Add non-blocking type encryption support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
« no previous file with comments | « sync/engine/model_type_entity.h ('k') | sync/engine/model_type_entity_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "sync/engine/model_type_entity.h" 5 #include "sync/engine/model_type_entity.h"
6 #include "sync/syncable/syncable_util.h" 6 #include "sync/syncable/syncable_util.h"
7 7
8 namespace syncer { 8 namespace syncer {
9 9
10 scoped_ptr<ModelTypeEntity> ModelTypeEntity::NewLocalItem( 10 scoped_ptr<ModelTypeEntity> ModelTypeEntity::NewLocalItem(
11 const std::string& client_tag, 11 const std::string& client_tag,
12 const sync_pb::EntitySpecifics& specifics, 12 const sync_pb::EntitySpecifics& specifics,
13 base::Time now) { 13 base::Time now) {
14 return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity( 14 return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity(
15 1, 15 1,
16 0, 16 0,
17 0, 17 0,
18 kUncommittedVersion, 18 kUncommittedVersion,
19 true, 19 true,
20 std::string(), // Sync thread will assign the initial ID. 20 std::string(), // Sync thread will assign the initial ID.
21 syncable::GenerateSyncableHash(GetModelTypeFromSpecifics(specifics), 21 syncable::GenerateSyncableHash(GetModelTypeFromSpecifics(specifics),
22 client_tag), 22 client_tag),
23 client_tag, // As non-unique name. 23 client_tag, // As non-unique name.
24 specifics, 24 specifics,
25 false, 25 false,
26 now, 26 now,
27 now, 27 now));
28 std::string()));
29 } 28 }
30 29
31 scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate( 30 scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate(
32 const std::string& id, 31 const std::string& id,
33 const std::string& client_tag_hash, 32 const std::string& client_tag_hash,
34 const std::string& non_unique_name, 33 const std::string& non_unique_name,
35 int64 version, 34 int64 version,
36 const sync_pb::EntitySpecifics& specifics, 35 const sync_pb::EntitySpecifics& specifics,
37 bool deleted, 36 bool deleted,
38 base::Time ctime, 37 base::Time ctime,
39 base::Time mtime, 38 base::Time mtime) {
40 const std::string& encryption_key_name) {
41 return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity(0, 39 return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity(0,
42 0, 40 0,
43 0, 41 0,
44 version, 42 version,
45 true, 43 true,
46 id, 44 id,
47 client_tag_hash, 45 client_tag_hash,
48 non_unique_name, 46 non_unique_name,
49 specifics, 47 specifics,
50 deleted, 48 deleted,
51 ctime, 49 ctime,
52 mtime, 50 mtime));
53 encryption_key_name));
54 } 51 }
55 52
56 ModelTypeEntity::ModelTypeEntity(int64 sequence_number, 53 ModelTypeEntity::ModelTypeEntity(int64 sequence_number,
57 int64 commit_requested_sequence_number, 54 int64 commit_requested_sequence_number,
58 int64 acked_sequence_number, 55 int64 acked_sequence_number,
59 int64 base_version, 56 int64 base_version,
60 bool is_dirty, 57 bool is_dirty,
61 const std::string& id, 58 const std::string& id,
62 const std::string& client_tag_hash, 59 const std::string& client_tag_hash,
63 const std::string& non_unique_name, 60 const std::string& non_unique_name,
64 const sync_pb::EntitySpecifics& specifics, 61 const sync_pb::EntitySpecifics& specifics,
65 bool deleted, 62 bool deleted,
66 base::Time ctime, 63 base::Time ctime,
67 base::Time mtime, 64 base::Time mtime)
68 const std::string& encryption_key_name)
69 : sequence_number_(sequence_number), 65 : sequence_number_(sequence_number),
70 commit_requested_sequence_number_(commit_requested_sequence_number), 66 commit_requested_sequence_number_(commit_requested_sequence_number),
71 acked_sequence_number_(acked_sequence_number), 67 acked_sequence_number_(acked_sequence_number),
72 base_version_(base_version), 68 base_version_(base_version),
73 is_dirty_(is_dirty), 69 is_dirty_(is_dirty),
74 id_(id), 70 id_(id),
75 client_tag_hash_(client_tag_hash), 71 client_tag_hash_(client_tag_hash),
76 non_unique_name_(non_unique_name), 72 non_unique_name_(non_unique_name),
77 specifics_(specifics), 73 specifics_(specifics),
78 deleted_(deleted), 74 deleted_(deleted),
79 ctime_(ctime), 75 ctime_(ctime),
80 mtime_(mtime), 76 mtime_(mtime) {
81 encryption_key_name_(encryption_key_name) {
82 } 77 }
83 78
84 ModelTypeEntity::~ModelTypeEntity() { 79 ModelTypeEntity::~ModelTypeEntity() {
85 } 80 }
86 81
87 bool ModelTypeEntity::IsWriteRequired() const { 82 bool ModelTypeEntity::IsWriteRequired() const {
88 return is_dirty_; 83 return is_dirty_;
89 } 84 }
90 85
91 bool ModelTypeEntity::IsUnsynced() const { 86 bool ModelTypeEntity::IsUnsynced() const {
92 return sequence_number_ > acked_sequence_number_; 87 return sequence_number_ > acked_sequence_number_;
93 } 88 }
94 89
95 bool ModelTypeEntity::RequiresCommitRequest() const { 90 bool ModelTypeEntity::RequiresCommitRequest() const {
96 return sequence_number_ > commit_requested_sequence_number_; 91 return sequence_number_ > commit_requested_sequence_number_;
97 } 92 }
98 93
99 bool ModelTypeEntity::UpdateIsReflection(int64 update_version) const { 94 bool ModelTypeEntity::UpdateIsReflection(int64 update_version) const {
100 return base_version_ >= update_version; 95 return base_version_ >= update_version;
101 } 96 }
102 97
103 bool ModelTypeEntity::UpdateIsInConflict(int64 update_version) const { 98 bool ModelTypeEntity::UpdateIsInConflict(int64 update_version) const {
104 return IsUnsynced() && !UpdateIsReflection(update_version); 99 return IsUnsynced() && !UpdateIsReflection(update_version);
105 } 100 }
106 101
107 void ModelTypeEntity::ApplyUpdateFromServer( 102 void ModelTypeEntity::ApplyUpdateFromServer(
108 int64 update_version, 103 int64 update_version,
109 bool deleted, 104 bool deleted,
110 const sync_pb::EntitySpecifics& specifics, 105 const sync_pb::EntitySpecifics& specifics,
111 base::Time mtime, 106 base::Time mtime) {
112 const std::string& encryption_key_name) {
113 // There was a conflict and the server just won it. 107 // There was a conflict and the server just won it.
114 // This implicitly acks all outstanding commits because a received update 108 // This implicitly acks all outstanding commits because a received update
115 // will clobber any pending commits on the sync thread. 109 // will clobber any pending commits on the sync thread.
116 acked_sequence_number_ = sequence_number_; 110 acked_sequence_number_ = sequence_number_;
117 commit_requested_sequence_number_ = sequence_number_; 111 commit_requested_sequence_number_ = sequence_number_;
118 112
119 base_version_ = update_version; 113 base_version_ = update_version;
120 specifics_ = specifics; 114 specifics_ = specifics;
121 mtime_ = mtime; 115 mtime_ = mtime;
122 } 116 }
123 117
124 void ModelTypeEntity::MakeLocalChange( 118 void ModelTypeEntity::MakeLocalChange(
125 const sync_pb::EntitySpecifics& specifics) { 119 const sync_pb::EntitySpecifics& specifics) {
126 sequence_number_++; 120 sequence_number_++;
127 specifics_ = specifics; 121 specifics_ = specifics;
128 } 122 }
129 123
130 void ModelTypeEntity::UpdateDesiredEncryptionKey(const std::string& name) {
131 if (encryption_key_name_ == name)
132 return;
133
134 // Schedule commit with the expectation that the worker will re-encrypt with
135 // the latest encryption key as it does.
136 sequence_number_++;
137 }
138
139 void ModelTypeEntity::Delete() { 124 void ModelTypeEntity::Delete() {
140 sequence_number_++; 125 sequence_number_++;
141 specifics_.Clear(); 126 specifics_.Clear();
142 deleted_ = true; 127 deleted_ = true;
143 } 128 }
144 129
145 void ModelTypeEntity::InitializeCommitRequestData( 130 void ModelTypeEntity::InitializeCommitRequestData(
146 CommitRequestData* request) const { 131 CommitRequestData* request) const {
147 request->id = id_; 132 request->id = id_;
148 request->client_tag_hash = client_tag_hash_; 133 request->client_tag_hash = client_tag_hash_;
149 request->sequence_number = sequence_number_; 134 request->sequence_number = sequence_number_;
150 request->base_version = base_version_; 135 request->base_version = base_version_;
151 request->ctime = ctime_; 136 request->ctime = ctime_;
152 request->mtime = mtime_; 137 request->mtime = mtime_;
153 request->non_unique_name = non_unique_name_; 138 request->non_unique_name = non_unique_name_;
154 request->deleted = deleted_; 139 request->deleted = deleted_;
155 request->specifics.CopyFrom(specifics_); 140 request->specifics.CopyFrom(specifics_);
156 } 141 }
157 142
158 void ModelTypeEntity::SetCommitRequestInProgress() { 143 void ModelTypeEntity::SetCommitRequestInProgress() {
159 commit_requested_sequence_number_ = sequence_number_; 144 commit_requested_sequence_number_ = sequence_number_;
160 } 145 }
161 146
162 void ModelTypeEntity::ReceiveCommitResponse( 147 void ModelTypeEntity::ReceiveCommitResponse(const std::string& id,
163 const std::string& id, 148 int64 sequence_number,
164 int64 sequence_number, 149 int64 response_version) {
165 int64 response_version,
166 const std::string& encryption_key_name) {
167 id_ = id; // The server can assign us a new ID in a commit response. 150 id_ = id; // The server can assign us a new ID in a commit response.
168 acked_sequence_number_ = sequence_number; 151 acked_sequence_number_ = sequence_number;
169 base_version_ = response_version; 152 base_version_ = response_version;
170 encryption_key_name_ = encryption_key_name;
171 } 153 }
172 154
173 void ModelTypeEntity::ClearTransientSyncState() { 155 void ModelTypeEntity::ClearTransientSyncState() {
174 // If we have any unacknowledged commit requests outstatnding, they've been 156 // If we have any unacknowledged commit requests outstatnding, they've been
175 // dropped and we should forget about them. 157 // dropped and we should forget about them.
176 commit_requested_sequence_number_ = acked_sequence_number_; 158 commit_requested_sequence_number_ = acked_sequence_number_;
177 } 159 }
178 160
179 void ModelTypeEntity::ClearSyncState() { 161 void ModelTypeEntity::ClearSyncState() {
180 base_version_ = kUncommittedVersion; 162 base_version_ = kUncommittedVersion;
181 is_dirty_ = true; 163 is_dirty_ = true;
182 sequence_number_ = 1; 164 sequence_number_ = 1;
183 commit_requested_sequence_number_ = 0; 165 commit_requested_sequence_number_ = 0;
184 acked_sequence_number_ = 0; 166 acked_sequence_number_ = 0;
185 id_.clear(); 167 id_.clear();
186 } 168 }
187 169
188 } // namespace syncer 170 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/model_type_entity.h ('k') | sync/engine/model_type_entity_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698