| 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/base_node.h" | 5 #include "sync/internal_api/public/base_node.h" |
| 6 | 6 |
| 7 #include <stack> | 7 #include <stack> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 211 } |
| 212 | 212 |
| 213 base::DictionaryValue* BaseNode::ToValue() const { | 213 base::DictionaryValue* BaseNode::ToValue() const { |
| 214 return GetEntry()->ToValue(GetTransaction()->GetCryptographer()); | 214 return GetEntry()->ToValue(GetTransaction()->GetCryptographer()); |
| 215 } | 215 } |
| 216 | 216 |
| 217 int64 BaseNode::GetExternalId() const { | 217 int64 BaseNode::GetExternalId() const { |
| 218 return GetEntry()->GetLocalExternalId(); | 218 return GetEntry()->GetLocalExternalId(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 const sync_pb::AppSpecifics& BaseNode::GetAppSpecifics() const { | |
| 222 DCHECK_EQ(GetModelType(), APPS); | |
| 223 return GetEntitySpecifics().app(); | |
| 224 } | |
| 225 | |
| 226 const sync_pb::AutofillSpecifics& BaseNode::GetAutofillSpecifics() const { | |
| 227 DCHECK_EQ(GetModelType(), AUTOFILL); | |
| 228 return GetEntitySpecifics().autofill(); | |
| 229 } | |
| 230 | |
| 231 const AutofillProfileSpecifics& BaseNode::GetAutofillProfileSpecifics() const { | |
| 232 DCHECK_EQ(GetModelType(), AUTOFILL_PROFILE); | |
| 233 return GetEntitySpecifics().autofill_profile(); | |
| 234 } | |
| 235 | |
| 236 const sync_pb::BookmarkSpecifics& BaseNode::GetBookmarkSpecifics() const { | 221 const sync_pb::BookmarkSpecifics& BaseNode::GetBookmarkSpecifics() const { |
| 237 DCHECK_EQ(GetModelType(), BOOKMARKS); | 222 DCHECK_EQ(GetModelType(), BOOKMARKS); |
| 238 return GetEntitySpecifics().bookmark(); | 223 return GetEntitySpecifics().bookmark(); |
| 239 } | 224 } |
| 240 | 225 |
| 241 const sync_pb::NigoriSpecifics& BaseNode::GetNigoriSpecifics() const { | 226 const sync_pb::NigoriSpecifics& BaseNode::GetNigoriSpecifics() const { |
| 242 DCHECK_EQ(GetModelType(), NIGORI); | 227 DCHECK_EQ(GetModelType(), NIGORI); |
| 243 return GetEntitySpecifics().nigori(); | 228 return GetEntitySpecifics().nigori(); |
| 244 } | 229 } |
| 245 | 230 |
| 246 const sync_pb::PasswordSpecificsData& BaseNode::GetPasswordSpecifics() const { | 231 const sync_pb::PasswordSpecificsData& BaseNode::GetPasswordSpecifics() const { |
| 247 DCHECK_EQ(GetModelType(), PASSWORDS); | 232 DCHECK_EQ(GetModelType(), PASSWORDS); |
| 248 return *password_data_; | 233 return *password_data_; |
| 249 } | 234 } |
| 250 | 235 |
| 251 const sync_pb::ThemeSpecifics& BaseNode::GetThemeSpecifics() const { | |
| 252 DCHECK_EQ(GetModelType(), THEMES); | |
| 253 return GetEntitySpecifics().theme(); | |
| 254 } | |
| 255 | |
| 256 const sync_pb::TypedUrlSpecifics& BaseNode::GetTypedUrlSpecifics() const { | 236 const sync_pb::TypedUrlSpecifics& BaseNode::GetTypedUrlSpecifics() const { |
| 257 DCHECK_EQ(GetModelType(), TYPED_URLS); | 237 DCHECK_EQ(GetModelType(), TYPED_URLS); |
| 258 return GetEntitySpecifics().typed_url(); | 238 return GetEntitySpecifics().typed_url(); |
| 259 } | 239 } |
| 260 | 240 |
| 261 const sync_pb::ExtensionSpecifics& BaseNode::GetExtensionSpecifics() const { | |
| 262 DCHECK_EQ(GetModelType(), EXTENSIONS); | |
| 263 return GetEntitySpecifics().extension(); | |
| 264 } | |
| 265 | |
| 266 const sync_pb::SessionSpecifics& BaseNode::GetSessionSpecifics() const { | |
| 267 DCHECK_EQ(GetModelType(), SESSIONS); | |
| 268 return GetEntitySpecifics().session(); | |
| 269 } | |
| 270 | |
| 271 const sync_pb::DeviceInfoSpecifics& BaseNode::GetDeviceInfoSpecifics() const { | |
| 272 DCHECK_EQ(GetModelType(), DEVICE_INFO); | |
| 273 return GetEntitySpecifics().device_info(); | |
| 274 } | |
| 275 | |
| 276 const sync_pb::ExperimentsSpecifics& BaseNode::GetExperimentsSpecifics() const { | 241 const sync_pb::ExperimentsSpecifics& BaseNode::GetExperimentsSpecifics() const { |
| 277 DCHECK_EQ(GetModelType(), EXPERIMENTS); | 242 DCHECK_EQ(GetModelType(), EXPERIMENTS); |
| 278 return GetEntitySpecifics().experiments(); | 243 return GetEntitySpecifics().experiments(); |
| 279 } | 244 } |
| 280 | 245 |
| 281 const sync_pb::PriorityPreferenceSpecifics& | |
| 282 BaseNode::GetPriorityPreferenceSpecifics() const { | |
| 283 DCHECK_EQ(GetModelType(), PRIORITY_PREFERENCES); | |
| 284 return GetEntitySpecifics().priority_preference(); | |
| 285 } | |
| 286 | |
| 287 const sync_pb::EntitySpecifics& BaseNode::GetEntitySpecifics() const { | 246 const sync_pb::EntitySpecifics& BaseNode::GetEntitySpecifics() const { |
| 288 return GetUnencryptedSpecifics(GetEntry()); | 247 return GetUnencryptedSpecifics(GetEntry()); |
| 289 } | 248 } |
| 290 | 249 |
| 291 ModelType BaseNode::GetModelType() const { | 250 ModelType BaseNode::GetModelType() const { |
| 292 return GetEntry()->GetModelType(); | 251 return GetEntry()->GetModelType(); |
| 293 } | 252 } |
| 294 | 253 |
| 295 const syncer::AttachmentIdList BaseNode::GetAttachmentIds() const { | 254 const syncer::AttachmentIdList BaseNode::GetAttachmentIds() const { |
| 296 AttachmentIdList result; | 255 AttachmentIdList result; |
| 297 const sync_pb::AttachmentMetadata& metadata = | 256 const sync_pb::AttachmentMetadata& metadata = |
| 298 GetEntry()->GetAttachmentMetadata(); | 257 GetEntry()->GetAttachmentMetadata(); |
| 299 for (int i = 0; i < metadata.record_size(); ++i) { | 258 for (int i = 0; i < metadata.record_size(); ++i) { |
| 300 result.push_back(AttachmentId::CreateFromProto(metadata.record(i).id())); | 259 result.push_back(AttachmentId::CreateFromProto(metadata.record(i).id())); |
| 301 } | 260 } |
| 302 return result; | 261 return result; |
| 303 } | 262 } |
| 304 | 263 |
| 305 void BaseNode::SetUnencryptedSpecifics( | 264 void BaseNode::SetUnencryptedSpecifics( |
| 306 const sync_pb::EntitySpecifics& specifics) { | 265 const sync_pb::EntitySpecifics& specifics) { |
| 307 ModelType type = GetModelTypeFromSpecifics(specifics); | 266 ModelType type = GetModelTypeFromSpecifics(specifics); |
| 308 DCHECK_NE(UNSPECIFIED, type); | 267 DCHECK_NE(UNSPECIFIED, type); |
| 309 if (GetModelType() != UNSPECIFIED) { | 268 if (GetModelType() != UNSPECIFIED) { |
| 310 DCHECK_EQ(GetModelType(), type); | 269 DCHECK_EQ(GetModelType(), type); |
| 311 } | 270 } |
| 312 unencrypted_data_.CopyFrom(specifics); | 271 unencrypted_data_.CopyFrom(specifics); |
| 313 } | 272 } |
| 314 | 273 |
| 315 } // namespace syncer | 274 } // namespace syncer |
| OLD | NEW |