| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 if (!SyncAssert(this == trans->directory(), FROM_HERE, | 264 if (!SyncAssert(this == trans->directory(), FROM_HERE, |
| 265 "Directories don't match", trans)) | 265 "Directories don't match", trans)) |
| 266 return false; | 266 return false; |
| 267 result->clear(); | 267 result->clear(); |
| 268 | 268 |
| 269 ScopedKernelLock lock(this); | 269 ScopedKernelLock lock(this); |
| 270 AppendChildHandles(lock, parent_id, result); | 270 AppendChildHandles(lock, parent_id, result); |
| 271 return true; | 271 return true; |
| 272 } | 272 } |
| 273 | 273 |
| 274 bool Directory::GetChildHandlesByHandle( | |
| 275 BaseTransaction* trans, int64 handle, | |
| 276 Directory::Metahandles* result) { | |
| 277 if (!SyncAssert(this == trans->directory(), FROM_HERE, | |
| 278 "Directories don't match", trans)) | |
| 279 return false; | |
| 280 | |
| 281 result->clear(); | |
| 282 | |
| 283 ScopedKernelLock lock(this); | |
| 284 EntryKernel* kernel = GetEntryByHandle(handle, &lock); | |
| 285 if (!kernel) | |
| 286 return true; | |
| 287 | |
| 288 AppendChildHandles(lock, kernel->ref(ID), result); | |
| 289 return true; | |
| 290 } | |
| 291 | |
| 292 int Directory::GetTotalNodeCount( | 274 int Directory::GetTotalNodeCount( |
| 293 BaseTransaction* trans, | 275 BaseTransaction* trans, |
| 294 EntryKernel* kernel) const { | 276 EntryKernel* kernel) const { |
| 295 if (!SyncAssert(this == trans->directory(), FROM_HERE, | 277 if (!SyncAssert(this == trans->directory(), FROM_HERE, |
| 296 "Directories don't match", trans)) | 278 "Directories don't match", trans)) |
| 297 return false; | 279 return false; |
| 298 | 280 |
| 299 int count = 1; | 281 int count = 1; |
| 300 std::deque<const OrderedChildSet*> child_sets; | 282 std::deque<const OrderedChildSet*> child_sets; |
| 301 | 283 |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 void Directory::GetAllMetaHandles(BaseTransaction* trans, | 862 void Directory::GetAllMetaHandles(BaseTransaction* trans, |
| 881 MetahandleSet* result) { | 863 MetahandleSet* result) { |
| 882 result->clear(); | 864 result->clear(); |
| 883 ScopedKernelLock lock(this); | 865 ScopedKernelLock lock(this); |
| 884 for (MetahandlesMap::iterator i = kernel_->metahandles_map.begin(); | 866 for (MetahandlesMap::iterator i = kernel_->metahandles_map.begin(); |
| 885 i != kernel_->metahandles_map.end(); ++i) { | 867 i != kernel_->metahandles_map.end(); ++i) { |
| 886 result->insert(i->first); | 868 result->insert(i->first); |
| 887 } | 869 } |
| 888 } | 870 } |
| 889 | 871 |
| 890 void Directory::GetAllEntryKernels(BaseTransaction* trans, | |
| 891 std::vector<const EntryKernel*>* result) { | |
| 892 result->clear(); | |
| 893 ScopedKernelLock lock(this); | |
| 894 for (MetahandlesMap::iterator i = kernel_->metahandles_map.begin(); | |
| 895 i != kernel_->metahandles_map.end(); ++i) { | |
| 896 result->push_back(i->second); | |
| 897 } | |
| 898 } | |
| 899 | |
| 900 void Directory::GetUnsyncedMetaHandles(BaseTransaction* trans, | 872 void Directory::GetUnsyncedMetaHandles(BaseTransaction* trans, |
| 901 Metahandles* result) { | 873 Metahandles* result) { |
| 902 result->clear(); | 874 result->clear(); |
| 903 ScopedKernelLock lock(this); | 875 ScopedKernelLock lock(this); |
| 904 copy(kernel_->unsynced_metahandles.begin(), | 876 copy(kernel_->unsynced_metahandles.begin(), |
| 905 kernel_->unsynced_metahandles.end(), back_inserter(*result)); | 877 kernel_->unsynced_metahandles.end(), back_inserter(*result)); |
| 906 } | 878 } |
| 907 | 879 |
| 908 int64 Directory::unsynced_entity_count() const { | 880 int64 Directory::unsynced_entity_count() const { |
| 909 ScopedKernelLock lock(this); | 881 ScopedKernelLock lock(this); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 940 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); | 912 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); |
| 941 it != kernel_->metahandles_map.end(); ++it) { | 913 it != kernel_->metahandles_map.end(); ++it) { |
| 942 EntryKernel* entry = it->second; | 914 EntryKernel* entry = it->second; |
| 943 const ModelType type = GetModelTypeFromSpecifics(entry->ref(SPECIFICS)); | 915 const ModelType type = GetModelTypeFromSpecifics(entry->ref(SPECIFICS)); |
| 944 (*num_entries_by_type)[type]++; | 916 (*num_entries_by_type)[type]++; |
| 945 if (entry->ref(IS_DEL)) | 917 if (entry->ref(IS_DEL)) |
| 946 (*num_to_delete_entries_by_type)[type]++; | 918 (*num_to_delete_entries_by_type)[type]++; |
| 947 } | 919 } |
| 948 } | 920 } |
| 949 | 921 |
| 922 scoped_ptr<base::ListValue> Directory::GetAllNodeDetails( |
| 923 BaseTransaction* trans) { |
| 924 scoped_ptr<base::ListValue> nodes(new base::ListValue()); |
| 925 |
| 926 ScopedKernelLock lock(this); |
| 927 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); |
| 928 it != kernel_->metahandles_map.end(); ++it) { |
| 929 EntryKernel* kernel = it->second; |
| 930 scoped_ptr<base::DictionaryValue> node( |
| 931 kernel->ToValue(GetCryptographer(trans))); |
| 932 |
| 933 // Add the position index if appropriate. This must be done here (and not |
| 934 // in EntryKernel) because the EntryKernel does not have access to its |
| 935 // siblings. |
| 936 if (kernel->ShouldMaintainPosition() && !kernel->ref(IS_DEL)) { |
| 937 node->SetInteger("positionIndex", GetPositionIndex(trans, kernel)); |
| 938 } |
| 939 |
| 940 nodes->Append(node.release()); |
| 941 } |
| 942 |
| 943 return nodes.Pass(); |
| 944 } |
| 945 |
| 950 bool Directory::CheckInvariantsOnTransactionClose( | 946 bool Directory::CheckInvariantsOnTransactionClose( |
| 951 syncable::BaseTransaction* trans, | 947 syncable::BaseTransaction* trans, |
| 952 const MetahandleSet& modified_handles) { | 948 const MetahandleSet& modified_handles) { |
| 953 // NOTE: The trans may be in the process of being destructed. Be careful if | 949 // NOTE: The trans may be in the process of being destructed. Be careful if |
| 954 // you wish to call any of its virtual methods. | 950 // you wish to call any of its virtual methods. |
| 955 switch (invariant_check_level_) { | 951 switch (invariant_check_level_) { |
| 956 case FULL_DB_VERIFICATION: { | 952 case FULL_DB_VERIFICATION: { |
| 957 MetahandleSet all_handles; | 953 MetahandleSet all_handles; |
| 958 GetAllMetaHandles(trans, &all_handles); | 954 GetAllMetaHandles(trans, &all_handles); |
| 959 return CheckTreeInvariants(trans, all_handles); | 955 return CheckTreeInvariants(trans, all_handles); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 | 1283 |
| 1288 for (OrderedChildSet::const_iterator i = children->begin(); | 1284 for (OrderedChildSet::const_iterator i = children->begin(); |
| 1289 i != children->end(); ++i) { | 1285 i != children->end(); ++i) { |
| 1290 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); | 1286 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); |
| 1291 result->push_back((*i)->ref(META_HANDLE)); | 1287 result->push_back((*i)->ref(META_HANDLE)); |
| 1292 } | 1288 } |
| 1293 } | 1289 } |
| 1294 | 1290 |
| 1295 } // namespace syncable | 1291 } // namespace syncable |
| 1296 } // namespace syncer | 1292 } // namespace syncer |
| OLD | NEW |