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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1401 | 1363 |
1402 Id Entry::ComputePrevIdFromServerPosition(const Id& parent_id) const { | 1364 Id Entry::ComputePrevIdFromServerPosition(const Id& parent_id) const { |
1403 return dir()->ComputePrevIdFromServerPosition(kernel_, parent_id); | 1365 return dir()->ComputePrevIdFromServerPosition(kernel_, parent_id); |
1404 } | 1366 } |
1405 | 1367 |
1406 DictionaryValue* Entry::ToValue() const { | 1368 DictionaryValue* Entry::ToValue() const { |
1407 DictionaryValue* entry_info = new DictionaryValue(); | 1369 DictionaryValue* entry_info = new DictionaryValue(); |
1408 entry_info->SetBoolean("good", good()); | 1370 entry_info->SetBoolean("good", good()); |
1409 if (good()) { | 1371 if (good()) { |
1410 entry_info->Set("kernel", kernel_->ToValue()); | 1372 entry_info->Set("kernel", kernel_->ToValue()); |
| 1373 entry_info->Set("serverModelType", |
| 1374 ModelTypeToValue(GetServerModelTypeHelper())); |
1411 entry_info->Set("modelType", | 1375 entry_info->Set("modelType", |
1412 ModelTypeToValue(GetModelType())); | 1376 ModelTypeToValue(GetModelType())); |
1413 entry_info->SetBoolean("existsOnClientBecauseNameIsNonEmpty", | 1377 entry_info->SetBoolean("existsOnClientBecauseNameIsNonEmpty", |
1414 ExistsOnClientBecauseNameIsNonEmpty()); | 1378 ExistsOnClientBecauseNameIsNonEmpty()); |
1415 entry_info->SetBoolean("isRoot", IsRoot()); | 1379 entry_info->SetBoolean("isRoot", IsRoot()); |
1416 } | 1380 } |
1417 return entry_info; | 1381 return entry_info; |
1418 } | 1382 } |
1419 | 1383 |
1420 const string& Entry::Get(StringField field) const { | 1384 const string& Entry::Get(StringField field) const { |
1421 DCHECK(kernel_); | 1385 DCHECK(kernel_); |
1422 return kernel_->ref(field); | 1386 return kernel_->ref(field); |
1423 } | 1387 } |
1424 | 1388 |
1425 syncable::ModelType Entry::GetServerModelType() const { | 1389 syncable::ModelType Entry::GetServerModelType() const { |
1426 ModelType specifics_type = kernel_->GetServerModelType(); | 1390 ModelType specifics_type = GetServerModelTypeHelper(); |
1427 if (specifics_type != UNSPECIFIED) | 1391 if (specifics_type != UNSPECIFIED) |
1428 return specifics_type; | 1392 return specifics_type; |
1429 | 1393 |
1430 // Otherwise, we don't have a server type yet. That should only happen | 1394 // Otherwise, we don't have a server type yet. That should only happen |
1431 // if the item is an uncommitted locally created item. | 1395 // if the item is an uncommitted locally created item. |
1432 // It's possible we'll need to relax these checks in the future; they're | 1396 // It's possible we'll need to relax these checks in the future; they're |
1433 // just here for now as a safety measure. | 1397 // just here for now as a safety measure. |
1434 DCHECK(Get(IS_UNSYNCED)); | 1398 DCHECK(Get(IS_UNSYNCED)); |
1435 DCHECK_EQ(Get(SERVER_VERSION), 0); | 1399 DCHECK_EQ(Get(SERVER_VERSION), 0); |
1436 DCHECK(Get(SERVER_IS_DEL)); | 1400 DCHECK(Get(SERVER_IS_DEL)); |
1437 // Note: can't enforce !Get(ID).ServerKnows() here because that could | 1401 // Note: can't enforce !Get(ID).ServerKnows() here because that could |
1438 // actually happen if we hit AttemptReuniteLostCommitResponses. | 1402 // actually happen if we hit AttemptReuniteLostCommitResponses. |
1439 return UNSPECIFIED; | 1403 return UNSPECIFIED; |
1440 } | 1404 } |
1441 | 1405 |
| 1406 syncable::ModelType Entry::GetServerModelTypeHelper() const { |
| 1407 ModelType specifics_type = GetModelTypeFromSpecifics(Get(SERVER_SPECIFICS)); |
| 1408 if (specifics_type != UNSPECIFIED) |
| 1409 return specifics_type; |
| 1410 if (IsRoot()) |
| 1411 return TOP_LEVEL_FOLDER; |
| 1412 // Loose check for server-created top-level folders that aren't |
| 1413 // bound to a particular model type. |
| 1414 if (!Get(UNIQUE_SERVER_TAG).empty() && Get(SERVER_IS_DIR)) |
| 1415 return TOP_LEVEL_FOLDER; |
| 1416 |
| 1417 return UNSPECIFIED; |
| 1418 } |
| 1419 |
1442 syncable::ModelType Entry::GetModelType() const { | 1420 syncable::ModelType Entry::GetModelType() const { |
1443 ModelType specifics_type = GetModelTypeFromSpecifics(Get(SPECIFICS)); | 1421 ModelType specifics_type = GetModelTypeFromSpecifics(Get(SPECIFICS)); |
1444 if (specifics_type != UNSPECIFIED) | 1422 if (specifics_type != UNSPECIFIED) |
1445 return specifics_type; | 1423 return specifics_type; |
1446 if (IsRoot()) | 1424 if (IsRoot()) |
1447 return TOP_LEVEL_FOLDER; | 1425 return TOP_LEVEL_FOLDER; |
1448 // Loose check for server-created top-level folders that aren't | 1426 // Loose check for server-created top-level folders that aren't |
1449 // bound to a particular model type. | 1427 // bound to a particular model type. |
1450 if (!Get(UNIQUE_SERVER_TAG).empty() && Get(IS_DIR)) | 1428 if (!Get(UNIQUE_SERVER_TAG).empty() && Get(IS_DIR)) |
1451 return TOP_LEVEL_FOLDER; | 1429 return TOP_LEVEL_FOLDER; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 bool MutableEntry::Put(StringField field, const string& value) { | 1596 bool MutableEntry::Put(StringField field, const string& value) { |
1619 return PutImpl(field, value); | 1597 return PutImpl(field, value); |
1620 } | 1598 } |
1621 | 1599 |
1622 bool MutableEntry::Put(ProtoField field, | 1600 bool MutableEntry::Put(ProtoField field, |
1623 const sync_pb::EntitySpecifics& value) { | 1601 const sync_pb::EntitySpecifics& value) { |
1624 DCHECK(kernel_); | 1602 DCHECK(kernel_); |
1625 // TODO(ncarter): This is unfortunately heavyweight. Can we do | 1603 // TODO(ncarter): This is unfortunately heavyweight. Can we do |
1626 // better? | 1604 // better? |
1627 if (kernel_->ref(field).SerializeAsString() != value.SerializeAsString()) { | 1605 if (kernel_->ref(field).SerializeAsString() != value.SerializeAsString()) { |
1628 const bool update_unapplied_updates_index = | |
1629 (field == SERVER_SPECIFICS) && kernel_->ref(IS_UNAPPLIED_UPDATE); | |
1630 if (update_unapplied_updates_index) { | |
1631 // Remove ourselves from unapplied_update_metahandles with our | |
1632 // old server type. | |
1633 const syncable::ModelType old_server_type = | |
1634 kernel_->GetServerModelType(); | |
1635 const int64 metahandle = kernel_->ref(META_HANDLE); | |
1636 size_t erase_count = | |
1637 dir()->kernel_->unapplied_update_metahandles[old_server_type] | |
1638 .erase(metahandle); | |
1639 DCHECK_EQ(erase_count, 1u); | |
1640 } | |
1641 | |
1642 kernel_->put(field, value); | 1606 kernel_->put(field, value); |
1643 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); | 1607 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); |
1644 | |
1645 if (update_unapplied_updates_index) { | |
1646 // Add ourselves back into unapplied_update_metahandles with our | |
1647 // new server type. | |
1648 const syncable::ModelType new_server_type = | |
1649 kernel_->GetServerModelType(); | |
1650 const int64 metahandle = kernel_->ref(META_HANDLE); | |
1651 dir()->kernel_->unapplied_update_metahandles[new_server_type] | |
1652 .insert(metahandle); | |
1653 } | |
1654 } | 1608 } |
1655 return true; | 1609 return true; |
1656 } | 1610 } |
1657 | 1611 |
1658 bool MutableEntry::Put(BitField field, bool value) { | 1612 bool MutableEntry::Put(BitField field, bool value) { |
1659 DCHECK(kernel_); | 1613 DCHECK(kernel_); |
1660 if (kernel_->ref(field) != value) { | 1614 if (kernel_->ref(field) != value) { |
1661 kernel_->put(field, value); | 1615 kernel_->put(field, value); |
1662 kernel_->mark_dirty(GetDirtyIndexHelper()); | 1616 kernel_->mark_dirty(GetDirtyIndexHelper()); |
1663 } | 1617 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 kernel_->put(field, value); | 1660 kernel_->put(field, value); |
1707 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); | 1661 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); |
1708 } | 1662 } |
1709 return true; | 1663 return true; |
1710 } | 1664 } |
1711 | 1665 |
1712 bool MutableEntry::Put(IndexedBitField field, bool value) { | 1666 bool MutableEntry::Put(IndexedBitField field, bool value) { |
1713 DCHECK(kernel_); | 1667 DCHECK(kernel_); |
1714 if (kernel_->ref(field) != value) { | 1668 if (kernel_->ref(field) != value) { |
1715 MetahandleSet* index; | 1669 MetahandleSet* index; |
1716 if (IS_UNSYNCED == field) { | 1670 if (IS_UNSYNCED == field) |
1717 index = dir()->kernel_->unsynced_metahandles; | 1671 index = dir()->kernel_->unsynced_metahandles; |
1718 } else { | 1672 else |
1719 // Use kernel_->GetServerModelType() instead of | 1673 index = dir()->kernel_->unapplied_update_metahandles; |
1720 // GetServerModelType() as we may trigger some DCHECKs in the | |
1721 // latter. | |
1722 index = | |
1723 &dir()->kernel_->unapplied_update_metahandles[ | |
1724 kernel_->GetServerModelType()]; | |
1725 } | |
1726 | 1674 |
1727 ScopedKernelLock lock(dir()); | 1675 ScopedKernelLock lock(dir()); |
1728 if (value) | 1676 if (value) |
1729 CHECK(index->insert(kernel_->ref(META_HANDLE)).second); | 1677 CHECK(index->insert(kernel_->ref(META_HANDLE)).second); |
1730 else | 1678 else |
1731 CHECK_EQ(1U, index->erase(kernel_->ref(META_HANDLE))); | 1679 CHECK_EQ(1U, index->erase(kernel_->ref(META_HANDLE))); |
1732 kernel_->put(field, value); | 1680 kernel_->put(field, value); |
1733 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); | 1681 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); |
1734 } | 1682 } |
1735 return true; | 1683 return true; |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 if (entry->ref(NEXT_ID).IsRoot() || | 2060 if (entry->ref(NEXT_ID).IsRoot() || |
2113 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { | 2061 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { |
2114 return entry; | 2062 return entry; |
2115 } | 2063 } |
2116 } | 2064 } |
2117 // There were no children in the linked list. | 2065 // There were no children in the linked list. |
2118 return NULL; | 2066 return NULL; |
2119 } | 2067 } |
2120 | 2068 |
2121 } // namespace syncable | 2069 } // namespace syncable |
OLD | NEW |