| OLD | NEW |
| 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 "sync/internal_api/public/write_node.h" | 5 #include "sync/internal_api/public/write_node.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "sync/internal_api/public/base_transaction.h" | 9 #include "sync/internal_api/public/base_transaction.h" |
| 10 #include "sync/internal_api/public/write_transaction.h" | 10 #include "sync/internal_api/public/write_transaction.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 if (entry_->Get(syncable::IS_DIR) == folder) | 35 if (entry_->Get(syncable::IS_DIR) == folder) |
| 36 return; // Skip redundant changes. | 36 return; // Skip redundant changes. |
| 37 | 37 |
| 38 entry_->Put(syncable::IS_DIR, folder); | 38 entry_->Put(syncable::IS_DIR, folder); |
| 39 MarkForSyncing(); | 39 MarkForSyncing(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void WriteNode::SetTitle(const std::wstring& title) { | 42 void WriteNode::SetTitle(const std::wstring& title) { |
| 43 DCHECK_NE(GetModelType(), UNSPECIFIED); | 43 DCHECK_NE(GetModelType(), UNSPECIFIED); |
| 44 ModelType type = GetModelType(); | 44 ModelType type = GetModelType(); |
| 45 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); | |
| 46 // It's possible the nigori lost the set of encrypted types. If the current | 45 // It's possible the nigori lost the set of encrypted types. If the current |
| 47 // specifics are already encrypted, we want to ensure we continue encrypting. | 46 // specifics are already encrypted, we want to ensure we continue encrypting. |
| 48 bool needs_encryption = cryptographer->GetEncryptedTypes().Has(type) || | 47 bool needs_encryption = GetTransaction()->GetEncryptedTypes().Has(type) || |
| 49 entry_->Get(SPECIFICS).has_encrypted(); | 48 entry_->Get(SPECIFICS).has_encrypted(); |
| 50 | 49 |
| 51 // If this datatype is encrypted and is not a bookmark, we disregard the | 50 // If this datatype is encrypted and is not a bookmark, we disregard the |
| 52 // specified title in favor of kEncryptedString. For encrypted bookmarks the | 51 // specified title in favor of kEncryptedString. For encrypted bookmarks the |
| 53 // NON_UNIQUE_NAME will still be kEncryptedString, but we store the real title | 52 // NON_UNIQUE_NAME will still be kEncryptedString, but we store the real title |
| 54 // into the specifics. All strings compared are server legal strings. | 53 // into the specifics. All strings compared are server legal strings. |
| 55 std::string new_legal_title; | 54 std::string new_legal_title; |
| 56 if (type != BOOKMARKS && needs_encryption) { | 55 if (type != BOOKMARKS && needs_encryption) { |
| 57 new_legal_title = kEncryptedString; | 56 new_legal_title = kEncryptedString; |
| 58 } else { | 57 } else { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 GetModelTypeFromSpecifics(new_value); | 195 GetModelTypeFromSpecifics(new_value); |
| 197 DCHECK_NE(new_specifics_type, UNSPECIFIED); | 196 DCHECK_NE(new_specifics_type, UNSPECIFIED); |
| 198 DVLOG(1) << "Writing entity specifics of type " | 197 DVLOG(1) << "Writing entity specifics of type " |
| 199 << ModelTypeToString(new_specifics_type); | 198 << ModelTypeToString(new_specifics_type); |
| 200 // GetModelType() can be unspecified if this is the first time this | 199 // GetModelType() can be unspecified if this is the first time this |
| 201 // node is being initialized (see PutModelType()). Otherwise, it | 200 // node is being initialized (see PutModelType()). Otherwise, it |
| 202 // should match |new_specifics_type|. | 201 // should match |new_specifics_type|. |
| 203 if (GetModelType() != UNSPECIFIED) { | 202 if (GetModelType() != UNSPECIFIED) { |
| 204 DCHECK_EQ(new_specifics_type, GetModelType()); | 203 DCHECK_EQ(new_specifics_type, GetModelType()); |
| 205 } | 204 } |
| 206 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); | |
| 207 | 205 |
| 208 // Preserve unknown fields. | 206 // Preserve unknown fields. |
| 209 const sync_pb::EntitySpecifics& old_specifics = entry_->Get(SPECIFICS); | 207 const sync_pb::EntitySpecifics& old_specifics = entry_->Get(SPECIFICS); |
| 210 sync_pb::EntitySpecifics new_specifics; | 208 sync_pb::EntitySpecifics new_specifics; |
| 211 new_specifics.CopyFrom(new_value); | 209 new_specifics.CopyFrom(new_value); |
| 212 new_specifics.mutable_unknown_fields()->MergeFrom( | 210 new_specifics.mutable_unknown_fields()->MergeFrom( |
| 213 old_specifics.unknown_fields()); | 211 old_specifics.unknown_fields()); |
| 214 | 212 |
| 215 // Will update the entry if encryption was necessary. | 213 // Will update the entry if encryption was necessary. |
| 216 if (!UpdateEntryWithEncryption(cryptographer, new_specifics, entry_)) { | 214 if (!UpdateEntryWithEncryption(GetTransaction()->GetWrappedTrans(), |
| 215 new_specifics, |
| 216 entry_)) { |
| 217 return; | 217 return; |
| 218 } | 218 } |
| 219 if (entry_->Get(SPECIFICS).has_encrypted()) { | 219 if (entry_->Get(SPECIFICS).has_encrypted()) { |
| 220 // EncryptIfNecessary already updated the entry for us and marked for | 220 // EncryptIfNecessary already updated the entry for us and marked for |
| 221 // syncing if it was needed. Now we just make a copy of the unencrypted | 221 // syncing if it was needed. Now we just make a copy of the unencrypted |
| 222 // specifics so that if this node is updated, we do not have to decrypt the | 222 // specifics so that if this node is updated, we do not have to decrypt the |
| 223 // old data. Note that this only modifies the node's local data, not the | 223 // old data. Note that this only modifies the node's local data, not the |
| 224 // entry itself. | 224 // entry itself. |
| 225 SetUnencryptedSpecifics(new_value); | 225 SetUnencryptedSpecifics(new_value); |
| 226 } | 226 } |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); | 503 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); |
| 504 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); | 504 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); |
| 505 SetBookmarkSpecifics(new_value); | 505 SetBookmarkSpecifics(new_value); |
| 506 } | 506 } |
| 507 | 507 |
| 508 void WriteNode::MarkForSyncing() { | 508 void WriteNode::MarkForSyncing() { |
| 509 syncable::MarkForSyncing(entry_); | 509 syncable::MarkForSyncing(entry_); |
| 510 } | 510 } |
| 511 | 511 |
| 512 } // namespace syncer | 512 } // namespace syncer |
| OLD | NEW |