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

Side by Side Diff: chrome/browser/sync/internal_api/write_node.cc

Issue 9460047: sync: remove use of protobuf extensions in protocol to reduce static init overhead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nigori access in testserver Created 8 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "chrome/browser/sync/internal_api/write_node.h" 5 #include "chrome/browser/sync/internal_api/write_node.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/sync/engine/nigori_util.h" 10 #include "chrome/browser/sync/engine/nigori_util.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return true; 96 return true;
97 } 97 }
98 98
99 if (generated_specifics.has_encrypted()) { 99 if (generated_specifics.has_encrypted()) {
100 // Overwrite the possibly sensitive non-specifics data. 100 // Overwrite the possibly sensitive non-specifics data.
101 entry->Put(syncable::NON_UNIQUE_NAME, kEncryptedString); 101 entry->Put(syncable::NON_UNIQUE_NAME, kEncryptedString);
102 // For bookmarks we actually put bogus data into the unencrypted specifics, 102 // For bookmarks we actually put bogus data into the unencrypted specifics,
103 // else the server will try to do it for us. 103 // else the server will try to do it for us.
104 if (type == syncable::BOOKMARKS) { 104 if (type == syncable::BOOKMARKS) {
105 sync_pb::BookmarkSpecifics* bookmark_specifics = 105 sync_pb::BookmarkSpecifics* bookmark_specifics =
106 generated_specifics.MutableExtension(sync_pb::bookmark); 106 generated_specifics.mutable_bookmark();
107 if (!entry->Get(syncable::IS_DIR)) 107 if (!entry->Get(syncable::IS_DIR))
108 bookmark_specifics->set_url(kEncryptedString); 108 bookmark_specifics->set_url(kEncryptedString);
109 bookmark_specifics->set_title(kEncryptedString); 109 bookmark_specifics->set_title(kEncryptedString);
110 } 110 }
111 } 111 }
112 entry->Put(syncable::SPECIFICS, generated_specifics); 112 entry->Put(syncable::SPECIFICS, generated_specifics);
113 DVLOG(1) << "Overwriting specifics of type " 113 DVLOG(1) << "Overwriting specifics of type "
114 << syncable::ModelTypeToString(type) 114 << syncable::ModelTypeToString(type)
115 << " and marking for syncing."; 115 << " and marking for syncing.";
116 syncable::MarkForSyncing(entry); 116 syncable::MarkForSyncing(entry);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // necessary, nothing needs to change. 165 // necessary, nothing needs to change.
166 if (title_matches && !encrypted_without_overwriting_name) { 166 if (title_matches && !encrypted_without_overwriting_name) {
167 DVLOG(2) << "Title matches, dropping change."; 167 DVLOG(2) << "Title matches, dropping change.";
168 return; 168 return;
169 } 169 }
170 170
171 // For bookmarks, we also set the title field in the specifics. 171 // For bookmarks, we also set the title field in the specifics.
172 // TODO(zea): refactor bookmarks to not need this functionality. 172 // TODO(zea): refactor bookmarks to not need this functionality.
173 if (GetModelType() == syncable::BOOKMARKS) { 173 if (GetModelType() == syncable::BOOKMARKS) {
174 sync_pb::EntitySpecifics specifics = GetEntitySpecifics(); 174 sync_pb::EntitySpecifics specifics = GetEntitySpecifics();
175 specifics.MutableExtension(sync_pb::bookmark)->set_title(new_legal_title); 175 specifics.mutable_bookmark()->set_title(new_legal_title);
176 SetEntitySpecifics(specifics); // Does it's own encryption checking. 176 SetEntitySpecifics(specifics); // Does it's own encryption checking.
177 } 177 }
178 178
179 // For bookmarks, this has to happen after we set the title in the specifics, 179 // For bookmarks, this has to happen after we set the title in the specifics,
180 // because the presence of a title in the NON_UNIQUE_NAME is what controls 180 // because the presence of a title in the NON_UNIQUE_NAME is what controls
181 // the logic deciding whether this is an empty node or a legacy bookmark. 181 // the logic deciding whether this is an empty node or a legacy bookmark.
182 // See BaseNode::GetUnencryptedSpecific(..). 182 // See BaseNode::GetUnencryptedSpecific(..).
183 if (needs_encryption) 183 if (needs_encryption)
184 entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString); 184 entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString);
185 else 185 else
186 entry_->Put(syncable::NON_UNIQUE_NAME, new_legal_title); 186 entry_->Put(syncable::NON_UNIQUE_NAME, new_legal_title);
187 187
188 DVLOG(1) << "Overwriting title of type " 188 DVLOG(1) << "Overwriting title of type "
189 << syncable::ModelTypeToString(type) 189 << syncable::ModelTypeToString(type)
190 << " and marking for syncing."; 190 << " and marking for syncing.";
191 MarkForSyncing(); 191 MarkForSyncing();
192 } 192 }
193 193
194 void WriteNode::SetURL(const GURL& url) { 194 void WriteNode::SetURL(const GURL& url) {
195 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); 195 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
196 new_value.set_url(url.spec()); 196 new_value.set_url(url.spec());
197 SetBookmarkSpecifics(new_value); 197 SetBookmarkSpecifics(new_value);
198 } 198 }
199 199
200 void WriteNode::SetAppSpecifics( 200 void WriteNode::SetAppSpecifics(
201 const sync_pb::AppSpecifics& new_value) { 201 const sync_pb::AppSpecifics& new_value) {
202 sync_pb::EntitySpecifics entity_specifics; 202 sync_pb::EntitySpecifics entity_specifics;
203 entity_specifics.MutableExtension(sync_pb::app)->CopyFrom(new_value); 203 entity_specifics.mutable_app()->CopyFrom(new_value);
204 SetEntitySpecifics(entity_specifics); 204 SetEntitySpecifics(entity_specifics);
205 } 205 }
206 206
207 void WriteNode::SetAutofillSpecifics( 207 void WriteNode::SetAutofillSpecifics(
208 const sync_pb::AutofillSpecifics& new_value) { 208 const sync_pb::AutofillSpecifics& new_value) {
209 sync_pb::EntitySpecifics entity_specifics; 209 sync_pb::EntitySpecifics entity_specifics;
210 entity_specifics.MutableExtension(sync_pb::autofill)->CopyFrom(new_value); 210 entity_specifics.mutable_autofill()->CopyFrom(new_value);
211 SetEntitySpecifics(entity_specifics); 211 SetEntitySpecifics(entity_specifics);
212 } 212 }
213 213
214 void WriteNode::SetAutofillProfileSpecifics( 214 void WriteNode::SetAutofillProfileSpecifics(
215 const sync_pb::AutofillProfileSpecifics& new_value) { 215 const sync_pb::AutofillProfileSpecifics& new_value) {
216 sync_pb::EntitySpecifics entity_specifics; 216 sync_pb::EntitySpecifics entity_specifics;
217 entity_specifics.MutableExtension(sync_pb::autofill_profile)-> 217 entity_specifics.mutable_autofill_profile()->
218 CopyFrom(new_value); 218 CopyFrom(new_value);
219 SetEntitySpecifics(entity_specifics); 219 SetEntitySpecifics(entity_specifics);
220 } 220 }
221 221
222 void WriteNode::SetBookmarkSpecifics( 222 void WriteNode::SetBookmarkSpecifics(
223 const sync_pb::BookmarkSpecifics& new_value) { 223 const sync_pb::BookmarkSpecifics& new_value) {
224 sync_pb::EntitySpecifics entity_specifics; 224 sync_pb::EntitySpecifics entity_specifics;
225 entity_specifics.MutableExtension(sync_pb::bookmark)->CopyFrom(new_value); 225 entity_specifics.mutable_bookmark()->CopyFrom(new_value);
226 SetEntitySpecifics(entity_specifics); 226 SetEntitySpecifics(entity_specifics);
227 } 227 }
228 228
229 void WriteNode::SetNigoriSpecifics( 229 void WriteNode::SetNigoriSpecifics(
230 const sync_pb::NigoriSpecifics& new_value) { 230 const sync_pb::NigoriSpecifics& new_value) {
231 sync_pb::EntitySpecifics entity_specifics; 231 sync_pb::EntitySpecifics entity_specifics;
232 entity_specifics.MutableExtension(sync_pb::nigori)->CopyFrom(new_value); 232 entity_specifics.mutable_nigori()->CopyFrom(new_value);
233 SetEntitySpecifics(entity_specifics); 233 SetEntitySpecifics(entity_specifics);
234 } 234 }
235 235
236 void WriteNode::SetPasswordSpecifics( 236 void WriteNode::SetPasswordSpecifics(
237 const sync_pb::PasswordSpecificsData& data) { 237 const sync_pb::PasswordSpecificsData& data) {
238 DCHECK_EQ(syncable::PASSWORDS, GetModelType()); 238 DCHECK_EQ(syncable::PASSWORDS, GetModelType());
239 239
240 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); 240 Cryptographer* cryptographer = GetTransaction()->GetCryptographer();
241 241
242 // We have to do the idempotency check here (vs in UpdateEntryWithEncryption) 242 // We have to do the idempotency check here (vs in UpdateEntryWithEncryption)
243 // because Passwords have their encrypted data within the PasswordSpecifics, 243 // because Passwords have their encrypted data within the PasswordSpecifics,
244 // vs within the EntitySpecifics like all the other types. 244 // vs within the EntitySpecifics like all the other types.
245 const sync_pb::EntitySpecifics& old_specifics = GetEntry()->Get(SPECIFICS); 245 const sync_pb::EntitySpecifics& old_specifics = GetEntry()->Get(SPECIFICS);
246 sync_pb::EntitySpecifics entity_specifics; 246 sync_pb::EntitySpecifics entity_specifics;
247 // Copy over the old specifics if they exist. 247 // Copy over the old specifics if they exist.
248 if (syncable::GetModelTypeFromSpecifics(old_specifics) == 248 if (syncable::GetModelTypeFromSpecifics(old_specifics) ==
249 syncable::PASSWORDS) { 249 syncable::PASSWORDS) {
250 entity_specifics.CopyFrom(old_specifics); 250 entity_specifics.CopyFrom(old_specifics);
251 } else { 251 } else {
252 syncable::AddDefaultExtensionValue(syncable::PASSWORDS, 252 syncable::AddDefaultExtensionValue(syncable::PASSWORDS,
253 &entity_specifics); 253 &entity_specifics);
254 } 254 }
255 sync_pb::PasswordSpecifics* password_specifics = 255 sync_pb::PasswordSpecifics* password_specifics =
256 entity_specifics.MutableExtension(sync_pb::password); 256 entity_specifics.mutable_password();
257 // This will only update password_specifics if the underlying unencrypted blob 257 // This will only update password_specifics if the underlying unencrypted blob
258 // was different from |data| or was not encrypted with the proper passphrase. 258 // was different from |data| or was not encrypted with the proper passphrase.
259 if (!cryptographer->Encrypt(data, password_specifics->mutable_encrypted())) { 259 if (!cryptographer->Encrypt(data, password_specifics->mutable_encrypted())) {
260 NOTREACHED() << "Failed to encrypt password, possibly due to sync node " 260 NOTREACHED() << "Failed to encrypt password, possibly due to sync node "
261 << "corruption"; 261 << "corruption";
262 return; 262 return;
263 } 263 }
264 SetEntitySpecifics(entity_specifics); 264 SetEntitySpecifics(entity_specifics);
265 } 265 }
266 266
267 void WriteNode::SetThemeSpecifics( 267 void WriteNode::SetThemeSpecifics(
268 const sync_pb::ThemeSpecifics& new_value) { 268 const sync_pb::ThemeSpecifics& new_value) {
269 sync_pb::EntitySpecifics entity_specifics; 269 sync_pb::EntitySpecifics entity_specifics;
270 entity_specifics.MutableExtension(sync_pb::theme)->CopyFrom(new_value); 270 entity_specifics.mutable_theme()->CopyFrom(new_value);
271 SetEntitySpecifics(entity_specifics); 271 SetEntitySpecifics(entity_specifics);
272 } 272 }
273 273
274 void WriteNode::SetSessionSpecifics( 274 void WriteNode::SetSessionSpecifics(
275 const sync_pb::SessionSpecifics& new_value) { 275 const sync_pb::SessionSpecifics& new_value) {
276 sync_pb::EntitySpecifics entity_specifics; 276 sync_pb::EntitySpecifics entity_specifics;
277 entity_specifics.MutableExtension(sync_pb::session)->CopyFrom(new_value); 277 entity_specifics.mutable_session()->CopyFrom(new_value);
278 SetEntitySpecifics(entity_specifics); 278 SetEntitySpecifics(entity_specifics);
279 } 279 }
280 280
281 void WriteNode::SetEntitySpecifics( 281 void WriteNode::SetEntitySpecifics(
282 const sync_pb::EntitySpecifics& new_value) { 282 const sync_pb::EntitySpecifics& new_value) {
283 syncable::ModelType new_specifics_type = 283 syncable::ModelType new_specifics_type =
284 syncable::GetModelTypeFromSpecifics(new_value); 284 syncable::GetModelTypeFromSpecifics(new_value);
285 DCHECK_NE(new_specifics_type, syncable::UNSPECIFIED); 285 DCHECK_NE(new_specifics_type, syncable::UNSPECIFIED);
286 DVLOG(1) << "Writing entity specifics of type " 286 DVLOG(1) << "Writing entity specifics of type "
287 << syncable::ModelTypeToString(new_specifics_type); 287 << syncable::ModelTypeToString(new_specifics_type);
(...skipping 29 matching lines...) Expand all
317 DCHECK_EQ(new_specifics_type, GetModelType()); 317 DCHECK_EQ(new_specifics_type, GetModelType());
318 } 318 }
319 319
320 void WriteNode::ResetFromSpecifics() { 320 void WriteNode::ResetFromSpecifics() {
321 SetEntitySpecifics(GetEntitySpecifics()); 321 SetEntitySpecifics(GetEntitySpecifics());
322 } 322 }
323 323
324 void WriteNode::SetTypedUrlSpecifics( 324 void WriteNode::SetTypedUrlSpecifics(
325 const sync_pb::TypedUrlSpecifics& new_value) { 325 const sync_pb::TypedUrlSpecifics& new_value) {
326 sync_pb::EntitySpecifics entity_specifics; 326 sync_pb::EntitySpecifics entity_specifics;
327 entity_specifics.MutableExtension(sync_pb::typed_url)->CopyFrom(new_value); 327 entity_specifics.mutable_typed_url()->CopyFrom(new_value);
328 SetEntitySpecifics(entity_specifics); 328 SetEntitySpecifics(entity_specifics);
329 } 329 }
330 330
331 void WriteNode::SetExtensionSpecifics( 331 void WriteNode::SetExtensionSpecifics(
332 const sync_pb::ExtensionSpecifics& new_value) { 332 const sync_pb::ExtensionSpecifics& new_value) {
333 sync_pb::EntitySpecifics entity_specifics; 333 sync_pb::EntitySpecifics entity_specifics;
334 entity_specifics.MutableExtension(sync_pb::extension)->CopyFrom(new_value); 334 entity_specifics.mutable_extension()->CopyFrom(new_value);
335 SetEntitySpecifics(entity_specifics); 335 SetEntitySpecifics(entity_specifics);
336 } 336 }
337 337
338 void WriteNode::SetExternalId(int64 id) { 338 void WriteNode::SetExternalId(int64 id) {
339 if (GetExternalId() != id) 339 if (GetExternalId() != id)
340 entry_->Put(syncable::LOCAL_EXTERNAL_ID, id); 340 entry_->Put(syncable::LOCAL_EXTERNAL_ID, id);
341 } 341 }
342 342
343 WriteNode::WriteNode(WriteTransaction* transaction) 343 WriteNode::WriteNode(WriteTransaction* transaction)
344 : entry_(NULL), transaction_(transaction) { 344 : entry_(NULL), transaction_(transaction) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); 572 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
573 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); 573 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size());
574 SetBookmarkSpecifics(new_value); 574 SetBookmarkSpecifics(new_value);
575 } 575 }
576 576
577 void WriteNode::MarkForSyncing() { 577 void WriteNode::MarkForSyncing() {
578 syncable::MarkForSyncing(entry_); 578 syncable::MarkForSyncing(entry_);
579 } 579 }
580 580
581 } // namespace sync_api 581 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698