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/syncable/directory.h" | 5 #include "sync/syncable/directory.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/perftimer.h" | 8 #include "base/perftimer.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 kernel_->metahandles_index->erase(it++); | 589 kernel_->metahandles_index->erase(it++); |
590 delete entry; | 590 delete entry; |
591 } else { | 591 } else { |
592 ++it; | 592 ++it; |
593 } | 593 } |
594 } | 594 } |
595 | 595 |
596 // Ensure meta tracking for these data types reflects the deleted state. | 596 // Ensure meta tracking for these data types reflects the deleted state. |
597 for (ModelTypeSet::Iterator it = types.First(); | 597 for (ModelTypeSet::Iterator it = types.First(); |
598 it.Good(); it.Inc()) { | 598 it.Good(); it.Inc()) { |
599 set_initial_sync_ended_for_type_unsafe(it.Get(), false); | |
600 kernel_->persisted_info.reset_download_progress(it.Get()); | 599 kernel_->persisted_info.reset_download_progress(it.Get()); |
601 kernel_->persisted_info.transaction_version[it.Get()] = 0; | 600 kernel_->persisted_info.transaction_version[it.Get()] = 0; |
602 } | 601 } |
603 } | 602 } |
604 } | 603 } |
605 return true; | 604 return true; |
606 } | 605 } |
607 | 606 |
608 void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) { | 607 void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) { |
609 ScopedKernelLock lock(this); | 608 ScopedKernelLock lock(this); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 int64 Directory::GetTransactionVersion(ModelType type) const { | 659 int64 Directory::GetTransactionVersion(ModelType type) const { |
661 kernel_->transaction_mutex.AssertAcquired(); | 660 kernel_->transaction_mutex.AssertAcquired(); |
662 return kernel_->persisted_info.transaction_version[type]; | 661 return kernel_->persisted_info.transaction_version[type]; |
663 } | 662 } |
664 | 663 |
665 void Directory::IncrementTransactionVersion(ModelType type) { | 664 void Directory::IncrementTransactionVersion(ModelType type) { |
666 kernel_->transaction_mutex.AssertAcquired(); | 665 kernel_->transaction_mutex.AssertAcquired(); |
667 kernel_->persisted_info.transaction_version[type]++; | 666 kernel_->persisted_info.transaction_version[type]++; |
668 } | 667 } |
669 | 668 |
670 ModelTypeSet Directory::initial_sync_ended_types() const { | 669 ModelTypeSet Directory::InitialSyncEndedTypes() { |
671 ScopedKernelLock lock(this); | 670 syncable::ReadTransaction trans(FROM_HERE, this); |
672 return kernel_->persisted_info.initial_sync_ended; | 671 const ModelTypeSet all_types = ModelTypeSet::All(); |
| 672 ModelTypeSet initial_sync_ended_types; |
| 673 for (ModelTypeSet::Iterator i = all_types.First(); i.Good(); i.Inc()) { |
| 674 if (InitialSyncEndedForType(&trans, i.Get())) { |
| 675 initial_sync_ended_types.Put(i.Get()); |
| 676 } |
| 677 } |
| 678 return initial_sync_ended_types; |
673 } | 679 } |
674 | 680 |
675 bool Directory::initial_sync_ended_for_type(ModelType type) const { | 681 bool Directory::InitialSyncEndedForType(ModelType type) { |
676 ScopedKernelLock lock(this); | 682 syncable::ReadTransaction trans(FROM_HERE, this); |
677 return kernel_->persisted_info.initial_sync_ended.Has(type); | 683 return InitialSyncEndedForType(&trans, type); |
| 684 } |
| 685 |
| 686 bool Directory::InitialSyncEndedForType( |
| 687 BaseTransaction* trans, ModelType type) { |
| 688 // True iff the type's root node has been received and applied. |
| 689 syncable::Entry entry(trans, |
| 690 syncable::GET_BY_SERVER_TAG, |
| 691 ModelTypeToRootTag(type)); |
| 692 return entry.good() && entry.Get(syncable::BASE_VERSION) != CHANGES_VERSION; |
678 } | 693 } |
679 | 694 |
680 template <class T> void Directory::TestAndSet( | 695 template <class T> void Directory::TestAndSet( |
681 T* kernel_data, const T* data_to_set) { | 696 T* kernel_data, const T* data_to_set) { |
682 if (*kernel_data != *data_to_set) { | 697 if (*kernel_data != *data_to_set) { |
683 *kernel_data = *data_to_set; | 698 *kernel_data = *data_to_set; |
684 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; | 699 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; |
685 } | 700 } |
686 } | 701 } |
687 | 702 |
688 void Directory::set_initial_sync_ended_for_type(ModelType type, bool x) { | |
689 ScopedKernelLock lock(this); | |
690 set_initial_sync_ended_for_type_unsafe(type, x); | |
691 } | |
692 | |
693 void Directory::set_initial_sync_ended_for_type_unsafe(ModelType type, | |
694 bool x) { | |
695 if (kernel_->persisted_info.initial_sync_ended.Has(type) == x) | |
696 return; | |
697 if (x) { | |
698 kernel_->persisted_info.initial_sync_ended.Put(type); | |
699 } else { | |
700 kernel_->persisted_info.initial_sync_ended.Remove(type); | |
701 } | |
702 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; | |
703 } | |
704 | |
705 void Directory::SetNotificationStateUnsafe( | 703 void Directory::SetNotificationStateUnsafe( |
706 const std::string& notification_state) { | 704 const std::string& notification_state) { |
707 if (notification_state == kernel_->persisted_info.notification_state) | 705 if (notification_state == kernel_->persisted_info.notification_state) |
708 return; | 706 return; |
709 kernel_->persisted_info.notification_state = notification_state; | 707 kernel_->persisted_info.notification_state = notification_state; |
710 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; | 708 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; |
711 } | 709 } |
712 | 710 |
713 string Directory::store_birthday() const { | 711 string Directory::store_birthday() const { |
714 ScopedKernelLock lock(this); | 712 ScopedKernelLock lock(this); |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 // There were no children in the linked list. | 1265 // There were no children in the linked list. |
1268 return NULL; | 1266 return NULL; |
1269 } | 1267 } |
1270 | 1268 |
1271 ScopedKernelLock::ScopedKernelLock(const Directory* dir) | 1269 ScopedKernelLock::ScopedKernelLock(const Directory* dir) |
1272 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { | 1270 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { |
1273 } | 1271 } |
1274 | 1272 |
1275 } // namespace syncable | 1273 } // namespace syncable |
1276 } // namespace syncer | 1274 } // namespace syncer |
OLD | NEW |