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

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

Issue 442053002: sync: Add non-blocking type encryption (retry) (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()));
28 } 29 }
29 30
30 scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate( 31 scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate(
31 const std::string& id, 32 const std::string& id,
32 const std::string& client_tag_hash, 33 const std::string& client_tag_hash,
33 const std::string& non_unique_name, 34 const std::string& non_unique_name,
34 int64 version, 35 int64 version,
35 const sync_pb::EntitySpecifics& specifics, 36 const sync_pb::EntitySpecifics& specifics,
36 bool deleted, 37 bool deleted,
37 base::Time ctime, 38 base::Time ctime,
38 base::Time mtime) { 39 base::Time mtime,
40 const std::string& encryption_key_name) {
39 return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity(0, 41 return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity(0,
40 0, 42 0,
41 0, 43 0,
42 version, 44 version,
43 true, 45 true,
44 id, 46 id,
45 client_tag_hash, 47 client_tag_hash,
46 non_unique_name, 48 non_unique_name,
47 specifics, 49 specifics,
48 deleted, 50 deleted,
49 ctime, 51 ctime,
50 mtime)); 52 mtime,
53 encryption_key_name));
51 } 54 }
52 55
53 ModelTypeEntity::ModelTypeEntity(int64 sequence_number, 56 ModelTypeEntity::ModelTypeEntity(int64 sequence_number,
54 int64 commit_requested_sequence_number, 57 int64 commit_requested_sequence_number,
55 int64 acked_sequence_number, 58 int64 acked_sequence_number,
56 int64 base_version, 59 int64 base_version,
57 bool is_dirty, 60 bool is_dirty,
58 const std::string& id, 61 const std::string& id,
59 const std::string& client_tag_hash, 62 const std::string& client_tag_hash,
60 const std::string& non_unique_name, 63 const std::string& non_unique_name,
61 const sync_pb::EntitySpecifics& specifics, 64 const sync_pb::EntitySpecifics& specifics,
62 bool deleted, 65 bool deleted,
63 base::Time ctime, 66 base::Time ctime,
64 base::Time mtime) 67 base::Time mtime,
68 const std::string& encryption_key_name)
65 : sequence_number_(sequence_number), 69 : sequence_number_(sequence_number),
66 commit_requested_sequence_number_(commit_requested_sequence_number), 70 commit_requested_sequence_number_(commit_requested_sequence_number),
67 acked_sequence_number_(acked_sequence_number), 71 acked_sequence_number_(acked_sequence_number),
68 base_version_(base_version), 72 base_version_(base_version),
69 is_dirty_(is_dirty), 73 is_dirty_(is_dirty),
70 id_(id), 74 id_(id),
71 client_tag_hash_(client_tag_hash), 75 client_tag_hash_(client_tag_hash),
72 non_unique_name_(non_unique_name), 76 non_unique_name_(non_unique_name),
73 specifics_(specifics), 77 specifics_(specifics),
74 deleted_(deleted), 78 deleted_(deleted),
75 ctime_(ctime), 79 ctime_(ctime),
76 mtime_(mtime) { 80 mtime_(mtime),
81 encryption_key_name_(encryption_key_name) {
77 } 82 }
78 83
79 ModelTypeEntity::~ModelTypeEntity() { 84 ModelTypeEntity::~ModelTypeEntity() {
80 } 85 }
81 86
82 bool ModelTypeEntity::IsWriteRequired() const { 87 bool ModelTypeEntity::IsWriteRequired() const {
83 return is_dirty_; 88 return is_dirty_;
84 } 89 }
85 90
86 bool ModelTypeEntity::IsUnsynced() const { 91 bool ModelTypeEntity::IsUnsynced() const {
87 return sequence_number_ > acked_sequence_number_; 92 return sequence_number_ > acked_sequence_number_;
88 } 93 }
89 94
90 bool ModelTypeEntity::RequiresCommitRequest() const { 95 bool ModelTypeEntity::RequiresCommitRequest() const {
91 return sequence_number_ > commit_requested_sequence_number_; 96 return sequence_number_ > commit_requested_sequence_number_;
92 } 97 }
93 98
94 bool ModelTypeEntity::UpdateIsReflection(int64 update_version) const { 99 bool ModelTypeEntity::UpdateIsReflection(int64 update_version) const {
95 return base_version_ >= update_version; 100 return base_version_ >= update_version;
96 } 101 }
97 102
98 bool ModelTypeEntity::UpdateIsInConflict(int64 update_version) const { 103 bool ModelTypeEntity::UpdateIsInConflict(int64 update_version) const {
99 return IsUnsynced() && !UpdateIsReflection(update_version); 104 return IsUnsynced() && !UpdateIsReflection(update_version);
100 } 105 }
101 106
102 void ModelTypeEntity::ApplyUpdateFromServer( 107 void ModelTypeEntity::ApplyUpdateFromServer(
103 int64 update_version, 108 int64 update_version,
104 bool deleted, 109 bool deleted,
105 const sync_pb::EntitySpecifics& specifics, 110 const sync_pb::EntitySpecifics& specifics,
106 base::Time mtime) { 111 base::Time mtime,
112 const std::string& encryption_key_name) {
107 // There was a conflict and the server just won it. 113 // There was a conflict and the server just won it.
108 // This implicitly acks all outstanding commits because a received update 114 // This implicitly acks all outstanding commits because a received update
109 // will clobber any pending commits on the sync thread. 115 // will clobber any pending commits on the sync thread.
110 acked_sequence_number_ = sequence_number_; 116 acked_sequence_number_ = sequence_number_;
111 commit_requested_sequence_number_ = sequence_number_; 117 commit_requested_sequence_number_ = sequence_number_;
112 118
113 base_version_ = update_version; 119 base_version_ = update_version;
114 specifics_ = specifics; 120 specifics_ = specifics;
115 mtime_ = mtime; 121 mtime_ = mtime;
116 } 122 }
117 123
118 void ModelTypeEntity::MakeLocalChange( 124 void ModelTypeEntity::MakeLocalChange(
119 const sync_pb::EntitySpecifics& specifics) { 125 const sync_pb::EntitySpecifics& specifics) {
120 sequence_number_++; 126 sequence_number_++;
121 specifics_ = specifics; 127 specifics_ = specifics;
122 } 128 }
123 129
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
124 void ModelTypeEntity::Delete() { 139 void ModelTypeEntity::Delete() {
125 sequence_number_++; 140 sequence_number_++;
126 specifics_.Clear(); 141 specifics_.Clear();
127 deleted_ = true; 142 deleted_ = true;
128 } 143 }
129 144
130 void ModelTypeEntity::InitializeCommitRequestData( 145 void ModelTypeEntity::InitializeCommitRequestData(
131 CommitRequestData* request) const { 146 CommitRequestData* request) const {
132 request->id = id_; 147 request->id = id_;
133 request->client_tag_hash = client_tag_hash_; 148 request->client_tag_hash = client_tag_hash_;
134 request->sequence_number = sequence_number_; 149 request->sequence_number = sequence_number_;
135 request->base_version = base_version_; 150 request->base_version = base_version_;
136 request->ctime = ctime_; 151 request->ctime = ctime_;
137 request->mtime = mtime_; 152 request->mtime = mtime_;
138 request->non_unique_name = non_unique_name_; 153 request->non_unique_name = non_unique_name_;
139 request->deleted = deleted_; 154 request->deleted = deleted_;
140 request->specifics.CopyFrom(specifics_); 155 request->specifics.CopyFrom(specifics_);
141 } 156 }
142 157
143 void ModelTypeEntity::SetCommitRequestInProgress() { 158 void ModelTypeEntity::SetCommitRequestInProgress() {
144 commit_requested_sequence_number_ = sequence_number_; 159 commit_requested_sequence_number_ = sequence_number_;
145 } 160 }
146 161
147 void ModelTypeEntity::ReceiveCommitResponse(const std::string& id, 162 void ModelTypeEntity::ReceiveCommitResponse(
148 int64 sequence_number, 163 const std::string& id,
149 int64 response_version) { 164 int64 sequence_number,
165 int64 response_version,
166 const std::string& encryption_key_name) {
150 id_ = id; // The server can assign us a new ID in a commit response. 167 id_ = id; // The server can assign us a new ID in a commit response.
151 acked_sequence_number_ = sequence_number; 168 acked_sequence_number_ = sequence_number;
152 base_version_ = response_version; 169 base_version_ = response_version;
170 encryption_key_name_ = encryption_key_name;
153 } 171 }
154 172
155 void ModelTypeEntity::ClearTransientSyncState() { 173 void ModelTypeEntity::ClearTransientSyncState() {
156 // If we have any unacknowledged commit requests outstatnding, they've been 174 // If we have any unacknowledged commit requests outstatnding, they've been
157 // dropped and we should forget about them. 175 // dropped and we should forget about them.
158 commit_requested_sequence_number_ = acked_sequence_number_; 176 commit_requested_sequence_number_ = acked_sequence_number_;
159 } 177 }
160 178
161 void ModelTypeEntity::ClearSyncState() { 179 void ModelTypeEntity::ClearSyncState() {
162 base_version_ = kUncommittedVersion; 180 base_version_ = kUncommittedVersion;
163 is_dirty_ = true; 181 is_dirty_ = true;
164 sequence_number_ = 1; 182 sequence_number_ = 1;
165 commit_requested_sequence_number_ = 0; 183 commit_requested_sequence_number_ = 0;
166 acked_sequence_number_ = 0; 184 acked_sequence_number_ = 0;
167 id_.clear(); 185 id_.clear();
168 } 186 }
169 187
170 } // namespace syncer 188 } // 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