OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/syncable/syncable.h" | 5 #include "chrome/browser/sync/syncable/syncable.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <functional> | 9 #include <functional> |
10 #include <iomanip> | 10 #include <iomanip> |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 251 |
252 EntryKernel::EntryKernel() : dirty_(false) { | 252 EntryKernel::EntryKernel() : dirty_(false) { |
253 // Everything else should already be default-initialized. | 253 // Everything else should already be default-initialized. |
254 for (int i = INT64_FIELDS_BEGIN; i < INT64_FIELDS_END; ++i) { | 254 for (int i = INT64_FIELDS_BEGIN; i < INT64_FIELDS_END; ++i) { |
255 int64_fields[i] = 0; | 255 int64_fields[i] = 0; |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 EntryKernel::~EntryKernel() {} | 259 EntryKernel::~EntryKernel() {} |
260 | 260 |
261 syncable::ModelType EntryKernel::GetServerModelType() const { | |
262 ModelType specifics_type = GetModelTypeFromSpecifics(ref(SERVER_SPECIFICS)); | |
263 if (specifics_type != UNSPECIFIED) | |
264 return specifics_type; | |
265 if (ref(ID).IsRoot()) | |
266 return TOP_LEVEL_FOLDER; | |
267 // Loose check for server-created top-level folders that aren't | |
268 // bound to a particular model type. | |
269 if (!ref(UNIQUE_SERVER_TAG).empty() && ref(SERVER_IS_DIR)) | |
270 return TOP_LEVEL_FOLDER; | |
271 | |
272 return UNSPECIFIED; | |
273 } | |
274 | |
275 bool EntryKernel::ContainsString(const std::string& lowercase_query) const { | 261 bool EntryKernel::ContainsString(const std::string& lowercase_query) const { |
276 // TODO(lipalani) - figure out what to do if the node is encrypted. | 262 // TODO(lipalani) - figure out what to do if the node is encrypted. |
277 const sync_pb::EntitySpecifics& specifics = ref(SPECIFICS); | 263 const sync_pb::EntitySpecifics& specifics = ref(SPECIFICS); |
278 std::string temp; | 264 std::string temp; |
279 // The protobuf serialized string contains the original strings. So | 265 // The protobuf serialized string contains the original strings. So |
280 // we will just serialize it and search it. | 266 // we will just serialize it and search it. |
281 specifics.SerializeToString(&temp); | 267 specifics.SerializeToString(&temp); |
282 | 268 |
283 // Now convert to lower case. | 269 // Now convert to lower case. |
284 StringToLowerASCII(&temp); | 270 StringToLowerASCII(&temp); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 321 |
336 StringValue* IdToValue(const Id& id) { | 322 StringValue* IdToValue(const Id& id) { |
337 return id.ToValue(); | 323 return id.ToValue(); |
338 } | 324 } |
339 | 325 |
340 } // namespace | 326 } // namespace |
341 | 327 |
342 DictionaryValue* EntryKernel::ToValue() const { | 328 DictionaryValue* EntryKernel::ToValue() const { |
343 DictionaryValue* kernel_info = new DictionaryValue(); | 329 DictionaryValue* kernel_info = new DictionaryValue(); |
344 kernel_info->SetBoolean("isDirty", is_dirty()); | 330 kernel_info->SetBoolean("isDirty", is_dirty()); |
345 kernel_info->Set("serverModelType", ModelTypeToValue(GetServerModelType())); | |
346 | 331 |
347 // Int64 fields. | 332 // Int64 fields. |
348 SetFieldValues(*this, kernel_info, | 333 SetFieldValues(*this, kernel_info, |
349 &GetMetahandleFieldString, &Int64ToValue, | 334 &GetMetahandleFieldString, &Int64ToValue, |
350 INT64_FIELDS_BEGIN, META_HANDLE); | 335 INT64_FIELDS_BEGIN, META_HANDLE); |
351 SetFieldValues(*this, kernel_info, | 336 SetFieldValues(*this, kernel_info, |
352 &GetBaseVersionString, &Int64ToValue, | 337 &GetBaseVersionString, &Int64ToValue, |
353 META_HANDLE + 1, BASE_VERSION); | 338 META_HANDLE + 1, BASE_VERSION); |
354 SetFieldValues(*this, kernel_info, | 339 SetFieldValues(*this, kernel_info, |
355 &GetInt64FieldString, &Int64ToValue, | 340 &GetInt64FieldString, &Int64ToValue, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 const browser_sync::WeakHandle<TransactionObserver>& | 426 const browser_sync::WeakHandle<TransactionObserver>& |
442 transaction_observer) | 427 transaction_observer) |
443 : db_path(db_path), | 428 : db_path(db_path), |
444 refcount(1), | 429 refcount(1), |
445 next_write_transaction_id(0), | 430 next_write_transaction_id(0), |
446 name(name), | 431 name(name), |
447 metahandles_index(new Directory::MetahandlesIndex), | 432 metahandles_index(new Directory::MetahandlesIndex), |
448 ids_index(new Directory::IdsIndex), | 433 ids_index(new Directory::IdsIndex), |
449 parent_id_child_index(new Directory::ParentIdChildIndex), | 434 parent_id_child_index(new Directory::ParentIdChildIndex), |
450 client_tag_index(new Directory::ClientTagIndex), | 435 client_tag_index(new Directory::ClientTagIndex), |
| 436 unapplied_update_metahandles(new MetahandleSet), |
451 unsynced_metahandles(new MetahandleSet), | 437 unsynced_metahandles(new MetahandleSet), |
452 dirty_metahandles(new MetahandleSet), | 438 dirty_metahandles(new MetahandleSet), |
453 metahandles_to_purge(new MetahandleSet), | 439 metahandles_to_purge(new MetahandleSet), |
454 info_status(Directory::KERNEL_SHARE_INFO_VALID), | 440 info_status(Directory::KERNEL_SHARE_INFO_VALID), |
455 persisted_info(info.kernel_info), | 441 persisted_info(info.kernel_info), |
456 cache_guid(info.cache_guid), | 442 cache_guid(info.cache_guid), |
457 next_metahandle(info.max_metahandle + 1), | 443 next_metahandle(info.max_metahandle + 1), |
458 delegate(delegate), | 444 delegate(delegate), |
459 transaction_observer(transaction_observer) { | 445 transaction_observer(transaction_observer) { |
460 DCHECK(delegate); | 446 DCHECK(delegate); |
461 DCHECK(transaction_observer.IsInitialized()); | 447 DCHECK(transaction_observer.IsInitialized()); |
462 } | 448 } |
463 | 449 |
464 void Directory::Kernel::AddRef() { | 450 void Directory::Kernel::AddRef() { |
465 base::subtle::NoBarrier_AtomicIncrement(&refcount, 1); | 451 base::subtle::NoBarrier_AtomicIncrement(&refcount, 1); |
466 } | 452 } |
467 | 453 |
468 void Directory::Kernel::Release() { | 454 void Directory::Kernel::Release() { |
469 if (!base::subtle::NoBarrier_AtomicIncrement(&refcount, -1)) | 455 if (!base::subtle::NoBarrier_AtomicIncrement(&refcount, -1)) |
470 delete this; | 456 delete this; |
471 } | 457 } |
472 | 458 |
473 Directory::Kernel::~Kernel() { | 459 Directory::Kernel::~Kernel() { |
474 CHECK_EQ(0, refcount); | 460 CHECK_EQ(0, refcount); |
475 delete unsynced_metahandles; | 461 delete unsynced_metahandles; |
| 462 delete unapplied_update_metahandles; |
476 delete dirty_metahandles; | 463 delete dirty_metahandles; |
477 delete metahandles_to_purge; | 464 delete metahandles_to_purge; |
478 delete parent_id_child_index; | 465 delete parent_id_child_index; |
479 delete client_tag_index; | 466 delete client_tag_index; |
480 delete ids_index; | 467 delete ids_index; |
481 STLDeleteElements(metahandles_index); | 468 STLDeleteElements(metahandles_index); |
482 delete metahandles_index; | 469 delete metahandles_index; |
483 } | 470 } |
484 | 471 |
485 Directory::Directory() : kernel_(NULL), store_(NULL) { | 472 Directory::Directory() : kernel_(NULL), store_(NULL) { |
(...skipping 16 matching lines...) Expand all Loading... |
502 } | 489 } |
503 | 490 |
504 void Directory::InitializeIndices() { | 491 void Directory::InitializeIndices() { |
505 MetahandlesIndex::iterator it = kernel_->metahandles_index->begin(); | 492 MetahandlesIndex::iterator it = kernel_->metahandles_index->begin(); |
506 for (; it != kernel_->metahandles_index->end(); ++it) { | 493 for (; it != kernel_->metahandles_index->end(); ++it) { |
507 EntryKernel* entry = *it; | 494 EntryKernel* entry = *it; |
508 InitializeIndexEntry<ParentIdAndHandleIndexer>(entry, | 495 InitializeIndexEntry<ParentIdAndHandleIndexer>(entry, |
509 kernel_->parent_id_child_index); | 496 kernel_->parent_id_child_index); |
510 InitializeIndexEntry<IdIndexer>(entry, kernel_->ids_index); | 497 InitializeIndexEntry<IdIndexer>(entry, kernel_->ids_index); |
511 InitializeIndexEntry<ClientTagIndexer>(entry, kernel_->client_tag_index); | 498 InitializeIndexEntry<ClientTagIndexer>(entry, kernel_->client_tag_index); |
512 const int64 metahandle = entry->ref(META_HANDLE); | |
513 if (entry->ref(IS_UNSYNCED)) | 499 if (entry->ref(IS_UNSYNCED)) |
514 kernel_->unsynced_metahandles->insert(metahandle); | 500 kernel_->unsynced_metahandles->insert(entry->ref(META_HANDLE)); |
515 if (entry->ref(IS_UNAPPLIED_UPDATE)) { | 501 if (entry->ref(IS_UNAPPLIED_UPDATE)) |
516 const ModelType type = entry->GetServerModelType(); | 502 kernel_->unapplied_update_metahandles->insert(entry->ref(META_HANDLE)); |
517 kernel_->unapplied_update_metahandles[type].insert(metahandle); | |
518 } | |
519 DCHECK(!entry->is_dirty()); | 503 DCHECK(!entry->is_dirty()); |
520 } | 504 } |
521 } | 505 } |
522 | 506 |
523 DirectoryBackingStore* Directory::CreateBackingStore( | 507 DirectoryBackingStore* Directory::CreateBackingStore( |
524 const string& dir_name, const FilePath& backing_filepath) { | 508 const string& dir_name, const FilePath& backing_filepath) { |
525 return new DirectoryBackingStore(dir_name, backing_filepath); | 509 return new DirectoryBackingStore(dir_name, backing_filepath); |
526 } | 510 } |
527 | 511 |
528 DirOpenResult Directory::OpenImpl( | 512 DirOpenResult Directory::OpenImpl( |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 kernel_->transaction_mutex.AssertAcquired(); | 695 kernel_->transaction_mutex.AssertAcquired(); |
712 kernel_->dirty_metahandles->clear(); | 696 kernel_->dirty_metahandles->clear(); |
713 } | 697 } |
714 | 698 |
715 bool Directory::SafeToPurgeFromMemory(const EntryKernel* const entry) const { | 699 bool Directory::SafeToPurgeFromMemory(const EntryKernel* const entry) const { |
716 bool safe = entry->ref(IS_DEL) && !entry->is_dirty() && | 700 bool safe = entry->ref(IS_DEL) && !entry->is_dirty() && |
717 !entry->ref(SYNCING) && !entry->ref(IS_UNAPPLIED_UPDATE) && | 701 !entry->ref(SYNCING) && !entry->ref(IS_UNAPPLIED_UPDATE) && |
718 !entry->ref(IS_UNSYNCED); | 702 !entry->ref(IS_UNSYNCED); |
719 | 703 |
720 if (safe) { | 704 if (safe) { |
721 const int64 handle = entry->ref(META_HANDLE); | 705 int64 handle = entry->ref(META_HANDLE); |
722 const ModelType type = entry->GetServerModelType(); | |
723 CHECK_EQ(kernel_->dirty_metahandles->count(handle), 0U); | 706 CHECK_EQ(kernel_->dirty_metahandles->count(handle), 0U); |
724 // TODO(tim): Bug 49278. | 707 // TODO(tim): Bug 49278. |
725 CHECK(!kernel_->unsynced_metahandles->count(handle)); | 708 CHECK(!kernel_->unsynced_metahandles->count(handle)); |
726 CHECK(!kernel_->unapplied_update_metahandles[type].count(handle)); | 709 CHECK(!kernel_->unapplied_update_metahandles->count(handle)); |
727 } | 710 } |
728 | 711 |
729 return safe; | 712 return safe; |
730 } | 713 } |
731 | 714 |
732 void Directory::TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot) { | 715 void Directory::TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot) { |
733 ReadTransaction trans(FROM_HERE, this); | 716 ReadTransaction trans(FROM_HERE, this); |
734 ScopedKernelLock lock(this); | 717 ScopedKernelLock lock(this); |
735 // Deep copy dirty entries from kernel_->metahandles_index into snapshot and | 718 // Deep copy dirty entries from kernel_->metahandles_index into snapshot and |
736 // clear dirty flags. | 719 // clear dirty flags. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 kernel_->metahandles_to_purge->insert(handle); | 830 kernel_->metahandles_to_purge->insert(handle); |
848 | 831 |
849 size_t num_erased = 0; | 832 size_t num_erased = 0; |
850 EntryKernel* entry = *it; | 833 EntryKernel* entry = *it; |
851 num_erased = kernel_->ids_index->erase(entry); | 834 num_erased = kernel_->ids_index->erase(entry); |
852 DCHECK_EQ(1u, num_erased); | 835 DCHECK_EQ(1u, num_erased); |
853 num_erased = kernel_->client_tag_index->erase(entry); | 836 num_erased = kernel_->client_tag_index->erase(entry); |
854 DCHECK_EQ(entry->ref(UNIQUE_CLIENT_TAG).empty(), !num_erased); | 837 DCHECK_EQ(entry->ref(UNIQUE_CLIENT_TAG).empty(), !num_erased); |
855 num_erased = kernel_->unsynced_metahandles->erase(handle); | 838 num_erased = kernel_->unsynced_metahandles->erase(handle); |
856 DCHECK_EQ(entry->ref(IS_UNSYNCED), num_erased > 0); | 839 DCHECK_EQ(entry->ref(IS_UNSYNCED), num_erased > 0); |
857 num_erased = | 840 num_erased = kernel_->unapplied_update_metahandles->erase(handle); |
858 kernel_->unapplied_update_metahandles[server_type].erase(handle); | |
859 DCHECK_EQ(entry->ref(IS_UNAPPLIED_UPDATE), num_erased > 0); | 841 DCHECK_EQ(entry->ref(IS_UNAPPLIED_UPDATE), num_erased > 0); |
860 num_erased = kernel_->parent_id_child_index->erase(entry); | 842 num_erased = kernel_->parent_id_child_index->erase(entry); |
861 DCHECK_EQ(entry->ref(IS_DEL), !num_erased); | 843 DCHECK_EQ(entry->ref(IS_DEL), !num_erased); |
862 kernel_->metahandles_index->erase(it++); | 844 kernel_->metahandles_index->erase(it++); |
863 delete entry; | 845 delete entry; |
864 } else { | 846 } else { |
865 ++it; | 847 ++it; |
866 } | 848 } |
867 } | 849 } |
868 | 850 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 ScopedKernelLock lock(this); | 1000 ScopedKernelLock lock(this); |
1019 copy(kernel_->unsynced_metahandles->begin(), | 1001 copy(kernel_->unsynced_metahandles->begin(), |
1020 kernel_->unsynced_metahandles->end(), back_inserter(*result)); | 1002 kernel_->unsynced_metahandles->end(), back_inserter(*result)); |
1021 } | 1003 } |
1022 | 1004 |
1023 int64 Directory::unsynced_entity_count() const { | 1005 int64 Directory::unsynced_entity_count() const { |
1024 ScopedKernelLock lock(this); | 1006 ScopedKernelLock lock(this); |
1025 return kernel_->unsynced_metahandles->size(); | 1007 return kernel_->unsynced_metahandles->size(); |
1026 } | 1008 } |
1027 | 1009 |
1028 syncable::ModelTypeBitSet | 1010 void Directory::GetUnappliedUpdateMetaHandles(BaseTransaction* trans, |
1029 Directory::GetServerTypesWithUnappliedUpdates( | |
1030 BaseTransaction* trans) const { | |
1031 syncable::ModelTypeBitSet server_types; | |
1032 ScopedKernelLock lock(this); | |
1033 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) { | |
1034 if (!kernel_->unapplied_update_metahandles[i].empty()) { | |
1035 server_types.set(i); | |
1036 } | |
1037 } | |
1038 return server_types; | |
1039 } | |
1040 | |
1041 void Directory::GetUnappliedUpdateMetaHandles( | |
1042 BaseTransaction* trans, | |
1043 syncable::ModelTypeBitSet server_types, | |
1044 UnappliedUpdateMetaHandles* result) { | 1011 UnappliedUpdateMetaHandles* result) { |
1045 result->clear(); | 1012 result->clear(); |
1046 ScopedKernelLock lock(this); | 1013 ScopedKernelLock lock(this); |
1047 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) { | 1014 copy(kernel_->unapplied_update_metahandles->begin(), |
1048 const ModelType type = ModelTypeFromInt(i); | 1015 kernel_->unapplied_update_metahandles->end(), |
1049 if (server_types.test(type)) { | 1016 back_inserter(*result)); |
1050 std::copy(kernel_->unapplied_update_metahandles[type].begin(), | |
1051 kernel_->unapplied_update_metahandles[type].end(), | |
1052 back_inserter(*result)); | |
1053 } | |
1054 } | |
1055 } | 1017 } |
1056 | 1018 |
1057 | 1019 |
1058 class IdFilter { | 1020 class IdFilter { |
1059 public: | 1021 public: |
1060 virtual ~IdFilter() { } | 1022 virtual ~IdFilter() { } |
1061 virtual bool ShouldConsider(const Id& id) const = 0; | 1023 virtual bool ShouldConsider(const Id& id) const = 0; |
1062 }; | 1024 }; |
1063 | 1025 |
1064 | 1026 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 | 1369 |
1408 Id Entry::ComputePrevIdFromServerPosition(const Id& parent_id) const { | 1370 Id Entry::ComputePrevIdFromServerPosition(const Id& parent_id) const { |
1409 return dir()->ComputePrevIdFromServerPosition(kernel_, parent_id); | 1371 return dir()->ComputePrevIdFromServerPosition(kernel_, parent_id); |
1410 } | 1372 } |
1411 | 1373 |
1412 DictionaryValue* Entry::ToValue() const { | 1374 DictionaryValue* Entry::ToValue() const { |
1413 DictionaryValue* entry_info = new DictionaryValue(); | 1375 DictionaryValue* entry_info = new DictionaryValue(); |
1414 entry_info->SetBoolean("good", good()); | 1376 entry_info->SetBoolean("good", good()); |
1415 if (good()) { | 1377 if (good()) { |
1416 entry_info->Set("kernel", kernel_->ToValue()); | 1378 entry_info->Set("kernel", kernel_->ToValue()); |
| 1379 entry_info->Set("serverModelType", |
| 1380 ModelTypeToValue(GetServerModelTypeHelper())); |
1417 entry_info->Set("modelType", | 1381 entry_info->Set("modelType", |
1418 ModelTypeToValue(GetModelType())); | 1382 ModelTypeToValue(GetModelType())); |
1419 entry_info->SetBoolean("existsOnClientBecauseNameIsNonEmpty", | 1383 entry_info->SetBoolean("existsOnClientBecauseNameIsNonEmpty", |
1420 ExistsOnClientBecauseNameIsNonEmpty()); | 1384 ExistsOnClientBecauseNameIsNonEmpty()); |
1421 entry_info->SetBoolean("isRoot", IsRoot()); | 1385 entry_info->SetBoolean("isRoot", IsRoot()); |
1422 } | 1386 } |
1423 return entry_info; | 1387 return entry_info; |
1424 } | 1388 } |
1425 | 1389 |
1426 const string& Entry::Get(StringField field) const { | 1390 const string& Entry::Get(StringField field) const { |
1427 DCHECK(kernel_); | 1391 DCHECK(kernel_); |
1428 return kernel_->ref(field); | 1392 return kernel_->ref(field); |
1429 } | 1393 } |
1430 | 1394 |
1431 syncable::ModelType Entry::GetServerModelType() const { | 1395 syncable::ModelType Entry::GetServerModelType() const { |
1432 ModelType specifics_type = kernel_->GetServerModelType(); | 1396 ModelType specifics_type = GetServerModelTypeHelper(); |
1433 if (specifics_type != UNSPECIFIED) | 1397 if (specifics_type != UNSPECIFIED) |
1434 return specifics_type; | 1398 return specifics_type; |
1435 | 1399 |
1436 // Otherwise, we don't have a server type yet. That should only happen | 1400 // Otherwise, we don't have a server type yet. That should only happen |
1437 // if the item is an uncommitted locally created item. | 1401 // if the item is an uncommitted locally created item. |
1438 // It's possible we'll need to relax these checks in the future; they're | 1402 // It's possible we'll need to relax these checks in the future; they're |
1439 // just here for now as a safety measure. | 1403 // just here for now as a safety measure. |
1440 DCHECK(Get(IS_UNSYNCED)); | 1404 DCHECK(Get(IS_UNSYNCED)); |
1441 DCHECK_EQ(Get(SERVER_VERSION), 0); | 1405 DCHECK_EQ(Get(SERVER_VERSION), 0); |
1442 DCHECK(Get(SERVER_IS_DEL)); | 1406 DCHECK(Get(SERVER_IS_DEL)); |
1443 // Note: can't enforce !Get(ID).ServerKnows() here because that could | 1407 // Note: can't enforce !Get(ID).ServerKnows() here because that could |
1444 // actually happen if we hit AttemptReuniteLostCommitResponses. | 1408 // actually happen if we hit AttemptReuniteLostCommitResponses. |
1445 return UNSPECIFIED; | 1409 return UNSPECIFIED; |
1446 } | 1410 } |
1447 | 1411 |
| 1412 syncable::ModelType Entry::GetServerModelTypeHelper() const { |
| 1413 ModelType specifics_type = GetModelTypeFromSpecifics(Get(SERVER_SPECIFICS)); |
| 1414 if (specifics_type != UNSPECIFIED) |
| 1415 return specifics_type; |
| 1416 if (IsRoot()) |
| 1417 return TOP_LEVEL_FOLDER; |
| 1418 // Loose check for server-created top-level folders that aren't |
| 1419 // bound to a particular model type. |
| 1420 if (!Get(UNIQUE_SERVER_TAG).empty() && Get(SERVER_IS_DIR)) |
| 1421 return TOP_LEVEL_FOLDER; |
| 1422 |
| 1423 return UNSPECIFIED; |
| 1424 } |
| 1425 |
1448 syncable::ModelType Entry::GetModelType() const { | 1426 syncable::ModelType Entry::GetModelType() const { |
1449 ModelType specifics_type = GetModelTypeFromSpecifics(Get(SPECIFICS)); | 1427 ModelType specifics_type = GetModelTypeFromSpecifics(Get(SPECIFICS)); |
1450 if (specifics_type != UNSPECIFIED) | 1428 if (specifics_type != UNSPECIFIED) |
1451 return specifics_type; | 1429 return specifics_type; |
1452 if (IsRoot()) | 1430 if (IsRoot()) |
1453 return TOP_LEVEL_FOLDER; | 1431 return TOP_LEVEL_FOLDER; |
1454 // Loose check for server-created top-level folders that aren't | 1432 // Loose check for server-created top-level folders that aren't |
1455 // bound to a particular model type. | 1433 // bound to a particular model type. |
1456 if (!Get(UNIQUE_SERVER_TAG).empty() && Get(IS_DIR)) | 1434 if (!Get(UNIQUE_SERVER_TAG).empty() && Get(IS_DIR)) |
1457 return TOP_LEVEL_FOLDER; | 1435 return TOP_LEVEL_FOLDER; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1624 bool MutableEntry::Put(StringField field, const string& value) { | 1602 bool MutableEntry::Put(StringField field, const string& value) { |
1625 return PutImpl(field, value); | 1603 return PutImpl(field, value); |
1626 } | 1604 } |
1627 | 1605 |
1628 bool MutableEntry::Put(ProtoField field, | 1606 bool MutableEntry::Put(ProtoField field, |
1629 const sync_pb::EntitySpecifics& value) { | 1607 const sync_pb::EntitySpecifics& value) { |
1630 DCHECK(kernel_); | 1608 DCHECK(kernel_); |
1631 // TODO(ncarter): This is unfortunately heavyweight. Can we do | 1609 // TODO(ncarter): This is unfortunately heavyweight. Can we do |
1632 // better? | 1610 // better? |
1633 if (kernel_->ref(field).SerializeAsString() != value.SerializeAsString()) { | 1611 if (kernel_->ref(field).SerializeAsString() != value.SerializeAsString()) { |
1634 const bool update_unapplied_updates_index = | |
1635 (field == SERVER_SPECIFICS) && kernel_->ref(IS_UNAPPLIED_UPDATE); | |
1636 if (update_unapplied_updates_index) { | |
1637 // Remove ourselves from unapplied_update_metahandles with our | |
1638 // old server type. | |
1639 const syncable::ModelType old_server_type = | |
1640 kernel_->GetServerModelType(); | |
1641 const int64 metahandle = kernel_->ref(META_HANDLE); | |
1642 size_t erase_count = | |
1643 dir()->kernel_->unapplied_update_metahandles[old_server_type] | |
1644 .erase(metahandle); | |
1645 DCHECK_EQ(erase_count, 1u); | |
1646 } | |
1647 | |
1648 kernel_->put(field, value); | 1612 kernel_->put(field, value); |
1649 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); | 1613 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); |
1650 | |
1651 if (update_unapplied_updates_index) { | |
1652 // Add ourselves back into unapplied_update_metahandles with our | |
1653 // new server type. | |
1654 const syncable::ModelType new_server_type = | |
1655 kernel_->GetServerModelType(); | |
1656 const int64 metahandle = kernel_->ref(META_HANDLE); | |
1657 dir()->kernel_->unapplied_update_metahandles[new_server_type] | |
1658 .insert(metahandle); | |
1659 } | |
1660 } | 1614 } |
1661 return true; | 1615 return true; |
1662 } | 1616 } |
1663 | 1617 |
1664 bool MutableEntry::Put(BitField field, bool value) { | 1618 bool MutableEntry::Put(BitField field, bool value) { |
1665 DCHECK(kernel_); | 1619 DCHECK(kernel_); |
1666 if (kernel_->ref(field) != value) { | 1620 if (kernel_->ref(field) != value) { |
1667 kernel_->put(field, value); | 1621 kernel_->put(field, value); |
1668 kernel_->mark_dirty(GetDirtyIndexHelper()); | 1622 kernel_->mark_dirty(GetDirtyIndexHelper()); |
1669 } | 1623 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 kernel_->put(field, value); | 1666 kernel_->put(field, value); |
1713 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); | 1667 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); |
1714 } | 1668 } |
1715 return true; | 1669 return true; |
1716 } | 1670 } |
1717 | 1671 |
1718 bool MutableEntry::Put(IndexedBitField field, bool value) { | 1672 bool MutableEntry::Put(IndexedBitField field, bool value) { |
1719 DCHECK(kernel_); | 1673 DCHECK(kernel_); |
1720 if (kernel_->ref(field) != value) { | 1674 if (kernel_->ref(field) != value) { |
1721 MetahandleSet* index; | 1675 MetahandleSet* index; |
1722 if (IS_UNSYNCED == field) { | 1676 if (IS_UNSYNCED == field) |
1723 index = dir()->kernel_->unsynced_metahandles; | 1677 index = dir()->kernel_->unsynced_metahandles; |
1724 } else { | 1678 else |
1725 // Use kernel_->GetServerModelType() instead of | 1679 index = dir()->kernel_->unapplied_update_metahandles; |
1726 // GetServerModelType() as we may trigger some DCHECKs in the | |
1727 // latter. | |
1728 index = | |
1729 &dir()->kernel_->unapplied_update_metahandles[ | |
1730 kernel_->GetServerModelType()]; | |
1731 } | |
1732 | 1680 |
1733 ScopedKernelLock lock(dir()); | 1681 ScopedKernelLock lock(dir()); |
1734 if (value) | 1682 if (value) |
1735 CHECK(index->insert(kernel_->ref(META_HANDLE)).second); | 1683 CHECK(index->insert(kernel_->ref(META_HANDLE)).second); |
1736 else | 1684 else |
1737 CHECK_EQ(1U, index->erase(kernel_->ref(META_HANDLE))); | 1685 CHECK_EQ(1U, index->erase(kernel_->ref(META_HANDLE))); |
1738 kernel_->put(field, value); | 1686 kernel_->put(field, value); |
1739 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); | 1687 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); |
1740 } | 1688 } |
1741 return true; | 1689 return true; |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 if (entry->ref(NEXT_ID).IsRoot() || | 2066 if (entry->ref(NEXT_ID).IsRoot() || |
2119 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { | 2067 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { |
2120 return entry; | 2068 return entry; |
2121 } | 2069 } |
2122 } | 2070 } |
2123 // There were no children in the linked list. | 2071 // There were no children in the linked list. |
2124 return NULL; | 2072 return NULL; |
2125 } | 2073 } |
2126 | 2074 |
2127 } // namespace syncable | 2075 } // namespace syncable |
OLD | NEW |