Chromium Code Reviews| 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/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "sync/internal_api/public/base_transaction.h" | 10 #include "sync/internal_api/public/base_transaction.h" |
| 11 #include "sync/internal_api/public/write_transaction.h" | 11 #include "sync/internal_api/public/write_transaction.h" |
| 12 #include "sync/internal_api/syncapi_internal.h" | 12 #include "sync/internal_api/syncapi_internal.h" |
| 13 #include "sync/protocol/app_specifics.pb.h" | |
| 14 #include "sync/protocol/autofill_specifics.pb.h" | |
| 15 #include "sync/protocol/bookmark_specifics.pb.h" | 13 #include "sync/protocol/bookmark_specifics.pb.h" |
| 16 #include "sync/protocol/extension_specifics.pb.h" | |
| 17 #include "sync/protocol/password_specifics.pb.h" | |
| 18 #include "sync/protocol/session_specifics.pb.h" | |
| 19 #include "sync/protocol/theme_specifics.pb.h" | |
| 20 #include "sync/protocol/typed_url_specifics.pb.h" | 14 #include "sync/protocol/typed_url_specifics.pb.h" |
| 21 #include "sync/syncable/mutable_entry.h" | 15 #include "sync/syncable/mutable_entry.h" |
| 22 #include "sync/syncable/nigori_util.h" | 16 #include "sync/syncable/nigori_util.h" |
| 23 #include "sync/syncable/syncable_util.h" | 17 #include "sync/syncable/syncable_util.h" |
| 24 #include "sync/util/cryptographer.h" | 18 #include "sync/util/cryptographer.h" |
| 25 | 19 |
| 26 using std::string; | 20 using std::string; |
| 27 using std::vector; | 21 using std::vector; |
| 28 | 22 |
| 29 namespace syncer { | 23 namespace syncer { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 entry_->PutNonUniqueName(kEncryptedString); | 97 entry_->PutNonUniqueName(kEncryptedString); |
| 104 else | 98 else |
| 105 entry_->PutNonUniqueName(new_legal_title); | 99 entry_->PutNonUniqueName(new_legal_title); |
| 106 | 100 |
| 107 DVLOG(1) << "Overwriting title of type " | 101 DVLOG(1) << "Overwriting title of type " |
| 108 << ModelTypeToString(type) | 102 << ModelTypeToString(type) |
| 109 << " and marking for syncing."; | 103 << " and marking for syncing."; |
| 110 MarkForSyncing(); | 104 MarkForSyncing(); |
| 111 } | 105 } |
| 112 | 106 |
| 113 void WriteNode::SetAppSpecifics( | |
| 114 const sync_pb::AppSpecifics& new_value) { | |
| 115 sync_pb::EntitySpecifics entity_specifics; | |
| 116 entity_specifics.mutable_app()->CopyFrom(new_value); | |
| 117 SetEntitySpecifics(entity_specifics); | |
| 118 } | |
| 119 | |
| 120 void WriteNode::SetAutofillSpecifics( | |
| 121 const sync_pb::AutofillSpecifics& new_value) { | |
| 122 sync_pb::EntitySpecifics entity_specifics; | |
| 123 entity_specifics.mutable_autofill()->CopyFrom(new_value); | |
| 124 SetEntitySpecifics(entity_specifics); | |
| 125 } | |
| 126 | |
| 127 void WriteNode::SetAutofillProfileSpecifics( | |
| 128 const sync_pb::AutofillProfileSpecifics& new_value) { | |
| 129 sync_pb::EntitySpecifics entity_specifics; | |
| 130 entity_specifics.mutable_autofill_profile()-> | |
| 131 CopyFrom(new_value); | |
| 132 SetEntitySpecifics(entity_specifics); | |
| 133 } | |
| 134 | |
| 135 void WriteNode::SetBookmarkSpecifics( | 107 void WriteNode::SetBookmarkSpecifics( |
| 136 const sync_pb::BookmarkSpecifics& new_value) { | 108 const sync_pb::BookmarkSpecifics& new_value) { |
| 137 sync_pb::EntitySpecifics entity_specifics; | 109 sync_pb::EntitySpecifics entity_specifics; |
| 138 entity_specifics.mutable_bookmark()->CopyFrom(new_value); | 110 entity_specifics.mutable_bookmark()->CopyFrom(new_value); |
| 139 SetEntitySpecifics(entity_specifics); | 111 SetEntitySpecifics(entity_specifics); |
| 140 } | 112 } |
| 141 | 113 |
| 142 void WriteNode::SetNigoriSpecifics( | 114 void WriteNode::SetNigoriSpecifics( |
| 143 const sync_pb::NigoriSpecifics& new_value) { | 115 const sync_pb::NigoriSpecifics& new_value) { |
| 144 sync_pb::EntitySpecifics entity_specifics; | 116 sync_pb::EntitySpecifics entity_specifics; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 168 // This will only update password_specifics if the underlying unencrypted blob | 140 // This will only update password_specifics if the underlying unencrypted blob |
| 169 // was different from |data| or was not encrypted with the proper passphrase. | 141 // was different from |data| or was not encrypted with the proper passphrase. |
| 170 if (!cryptographer->Encrypt(data, password_specifics->mutable_encrypted())) { | 142 if (!cryptographer->Encrypt(data, password_specifics->mutable_encrypted())) { |
| 171 NOTREACHED() << "Failed to encrypt password, possibly due to sync node " | 143 NOTREACHED() << "Failed to encrypt password, possibly due to sync node " |
| 172 << "corruption"; | 144 << "corruption"; |
| 173 return; | 145 return; |
| 174 } | 146 } |
| 175 SetEntitySpecifics(entity_specifics); | 147 SetEntitySpecifics(entity_specifics); |
| 176 } | 148 } |
| 177 | 149 |
| 178 void WriteNode::SetThemeSpecifics( | |
| 179 const sync_pb::ThemeSpecifics& new_value) { | |
| 180 sync_pb::EntitySpecifics entity_specifics; | |
| 181 entity_specifics.mutable_theme()->CopyFrom(new_value); | |
| 182 SetEntitySpecifics(entity_specifics); | |
| 183 } | |
| 184 | |
| 185 void WriteNode::SetSessionSpecifics( | |
| 186 const sync_pb::SessionSpecifics& new_value) { | |
| 187 sync_pb::EntitySpecifics entity_specifics; | |
| 188 entity_specifics.mutable_session()->CopyFrom(new_value); | |
| 189 SetEntitySpecifics(entity_specifics); | |
| 190 } | |
| 191 | |
| 192 void WriteNode::SetDeviceInfoSpecifics( | |
| 193 const sync_pb::DeviceInfoSpecifics& new_value) { | |
| 194 sync_pb::EntitySpecifics entity_specifics; | |
| 195 entity_specifics.mutable_device_info()->CopyFrom(new_value); | |
| 196 SetEntitySpecifics(entity_specifics); | |
| 197 } | |
| 198 | |
| 199 void WriteNode::SetExperimentsSpecifics( | |
| 200 const sync_pb::ExperimentsSpecifics& new_value) { | |
| 201 sync_pb::EntitySpecifics entity_specifics; | |
| 202 entity_specifics.mutable_experiments()->CopyFrom(new_value); | |
| 203 SetEntitySpecifics(entity_specifics); | |
| 204 } | |
| 205 | |
| 206 void WriteNode::SetPriorityPreferenceSpecifics( | |
| 207 const sync_pb::PriorityPreferenceSpecifics& new_value) { | |
| 208 sync_pb::EntitySpecifics entity_specifics; | |
| 209 entity_specifics.mutable_priority_preference()->CopyFrom(new_value); | |
| 210 SetEntitySpecifics(entity_specifics); | |
| 211 } | |
| 212 | |
| 213 void WriteNode::SetEntitySpecifics( | 150 void WriteNode::SetEntitySpecifics( |
| 214 const sync_pb::EntitySpecifics& new_value) { | 151 const sync_pb::EntitySpecifics& new_value) { |
| 215 ModelType new_specifics_type = | 152 ModelType new_specifics_type = |
| 216 GetModelTypeFromSpecifics(new_value); | 153 GetModelTypeFromSpecifics(new_value); |
| 217 CHECK(!new_value.password().has_client_only_encrypted_data()); | 154 CHECK(!new_value.password().has_client_only_encrypted_data()); |
| 218 DCHECK_NE(new_specifics_type, UNSPECIFIED); | 155 DCHECK_NE(new_specifics_type, UNSPECIFIED); |
| 219 DVLOG(1) << "Writing entity specifics of type " | 156 DVLOG(1) << "Writing entity specifics of type " |
| 220 << ModelTypeToString(new_specifics_type); | 157 << ModelTypeToString(new_specifics_type); |
| 221 DCHECK_EQ(new_specifics_type, GetModelType()); | 158 DCHECK_EQ(new_specifics_type, GetModelType()); |
| 222 | 159 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 242 SetUnencryptedSpecifics(new_value); | 179 SetUnencryptedSpecifics(new_value); |
| 243 } | 180 } |
| 244 | 181 |
| 245 DCHECK_EQ(new_specifics_type, GetModelType()); | 182 DCHECK_EQ(new_specifics_type, GetModelType()); |
| 246 } | 183 } |
| 247 | 184 |
| 248 void WriteNode::ResetFromSpecifics() { | 185 void WriteNode::ResetFromSpecifics() { |
| 249 SetEntitySpecifics(GetEntitySpecifics()); | 186 SetEntitySpecifics(GetEntitySpecifics()); |
| 250 } | 187 } |
| 251 | 188 |
| 252 void WriteNode::SetTypedUrlSpecifics( | 189 void WriteNode::SetTypedUrlSpecifics( |
|
stanisc
2015/06/10 21:53:38
Consider removing this one as well. It is used in
| |
| 253 const sync_pb::TypedUrlSpecifics& new_value) { | 190 const sync_pb::TypedUrlSpecifics& new_value) { |
| 254 sync_pb::EntitySpecifics entity_specifics; | 191 sync_pb::EntitySpecifics entity_specifics; |
| 255 entity_specifics.mutable_typed_url()->CopyFrom(new_value); | 192 entity_specifics.mutable_typed_url()->CopyFrom(new_value); |
| 256 SetEntitySpecifics(entity_specifics); | 193 SetEntitySpecifics(entity_specifics); |
| 257 } | 194 } |
| 258 | 195 |
| 259 void WriteNode::SetExtensionSpecifics( | |
| 260 const sync_pb::ExtensionSpecifics& new_value) { | |
| 261 sync_pb::EntitySpecifics entity_specifics; | |
| 262 entity_specifics.mutable_extension()->CopyFrom(new_value); | |
| 263 SetEntitySpecifics(entity_specifics); | |
| 264 } | |
| 265 | |
| 266 void WriteNode::SetExternalId(int64 id) { | 196 void WriteNode::SetExternalId(int64 id) { |
| 267 if (GetExternalId() != id) | 197 if (GetExternalId() != id) |
| 268 entry_->PutLocalExternalId(id); | 198 entry_->PutLocalExternalId(id); |
| 269 } | 199 } |
| 270 | 200 |
| 271 WriteNode::WriteNode(WriteTransaction* transaction) | 201 WriteNode::WriteNode(WriteTransaction* transaction) |
| 272 : entry_(NULL), transaction_(transaction) { | 202 : entry_(NULL), transaction_(transaction) { |
| 273 DCHECK(transaction); | 203 DCHECK(transaction); |
| 274 } | 204 } |
| 275 | 205 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 syncable::Id predecessor_id = predecessor ? | 467 syncable::Id predecessor_id = predecessor ? |
| 538 predecessor->GetEntry()->GetId() : syncable::Id(); | 468 predecessor->GetEntry()->GetId() : syncable::Id(); |
| 539 return entry_->PutPredecessor(predecessor_id); | 469 return entry_->PutPredecessor(predecessor_id); |
| 540 } | 470 } |
| 541 | 471 |
| 542 void WriteNode::MarkForSyncing() { | 472 void WriteNode::MarkForSyncing() { |
| 543 syncable::MarkForSyncing(entry_); | 473 syncable::MarkForSyncing(entry_); |
| 544 } | 474 } |
| 545 | 475 |
| 546 } // namespace syncer | 476 } // namespace syncer |
| OLD | NEW |