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 "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 kernel_->needle.put(META_HANDLE, metahandle); | 499 kernel_->needle.put(META_HANDLE, metahandle); |
500 MetahandlesIndex::iterator found = | 500 MetahandlesIndex::iterator found = |
501 kernel_->metahandles_index->find(&kernel_->needle); | 501 kernel_->metahandles_index->find(&kernel_->needle); |
502 if (found != kernel_->metahandles_index->end()) { | 502 if (found != kernel_->metahandles_index->end()) { |
503 // Found it in memory. Easy. | 503 // Found it in memory. Easy. |
504 return *found; | 504 return *found; |
505 } | 505 } |
506 return NULL; | 506 return NULL; |
507 } | 507 } |
508 | 508 |
509 void Directory::GetChildHandles(BaseTransaction* trans, const Id& parent_id, | 509 void Directory::GetChildHandlesById( |
510 Directory::ChildHandles* result) { | 510 BaseTransaction* trans, const Id& parent_id, |
511 Directory::ChildHandles* result) { | |
511 CHECK(this == trans->directory()); | 512 CHECK(this == trans->directory()); |
512 result->clear(); | 513 result->clear(); |
lipalani1
2011/06/02 18:51:52
Can we move result->clear to the private function?
akalin
2011/06/02 22:13:33
I don't think we should; the other function (GetCh
| |
513 { | 514 { |
514 ScopedKernelLock lock(this); | 515 ScopedKernelLock lock(this); |
lipalani1
2011/06/02 18:51:52
If the result->clear is moved is the block necessa
akalin
2011/06/02 22:13:33
The block isn't necessary anyway, so removed it.
| |
515 | 516 GetChildHandles(lock, parent_id, result); |
516 typedef ParentIdChildIndex::iterator iterator; | |
517 for (iterator i = GetParentChildIndexLowerBound(lock, parent_id), | |
518 end = GetParentChildIndexUpperBound(lock, parent_id); | |
519 i != end; ++i) { | |
520 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); | |
521 result->push_back((*i)->ref(META_HANDLE)); | |
522 } | |
523 } | 517 } |
524 } | 518 } |
525 | 519 |
520 void Directory::GetChildHandlesByHandle( | |
521 BaseTransaction* trans, int64 handle, | |
522 Directory::ChildHandles* result) { | |
523 CHECK(this == trans->directory()); | |
524 result->clear(); | |
525 { | |
526 ScopedKernelLock lock(this); | |
527 EntryKernel* kernel = GetEntryByHandle(handle, &lock); | |
528 if (!kernel) | |
529 return; | |
530 | |
531 GetChildHandles(lock, kernel->ref(ID), result); | |
532 } | |
533 } | |
534 | |
526 EntryKernel* Directory::GetRootEntry() { | 535 EntryKernel* Directory::GetRootEntry() { |
527 return GetEntryById(Id()); | 536 return GetEntryById(Id()); |
528 } | 537 } |
529 | 538 |
530 void ZeroFields(EntryKernel* entry, int first_field) { | 539 void ZeroFields(EntryKernel* entry, int first_field) { |
531 int i = first_field; | 540 int i = first_field; |
532 // Note that bitset<> constructor sets all bits to zero, and strings | 541 // Note that bitset<> constructor sets all bits to zero, and strings |
533 // initialize to empty. | 542 // initialize to empty. |
534 for ( ; i < INT64_FIELDS_END; ++i) | 543 for ( ; i < INT64_FIELDS_END; ++i) |
535 entry->put(static_cast<Int64Field>(i), 0); | 544 entry->put(static_cast<Int64Field>(i), 0); |
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1945 | 1954 |
1946 Directory::ParentIdChildIndex::iterator | 1955 Directory::ParentIdChildIndex::iterator |
1947 Directory::GetParentChildIndexUpperBound(const ScopedKernelLock& lock, | 1956 Directory::GetParentChildIndexUpperBound(const ScopedKernelLock& lock, |
1948 const Id& parent_id) { | 1957 const Id& parent_id) { |
1949 // The upper bound of |parent_id|'s range is the lower | 1958 // The upper bound of |parent_id|'s range is the lower |
1950 // bound of |++parent_id|'s range. | 1959 // bound of |++parent_id|'s range. |
1951 return GetParentChildIndexLowerBound(lock, | 1960 return GetParentChildIndexLowerBound(lock, |
1952 parent_id.GetLexicographicSuccessor()); | 1961 parent_id.GetLexicographicSuccessor()); |
1953 } | 1962 } |
1954 | 1963 |
1964 void Directory::GetChildHandles(const ScopedKernelLock& lock, | |
1965 const Id& parent_id, | |
lipalani1
2011/06/02 18:51:52
Can this function be const? Also the callers? I th
akalin
2011/06/02 22:13:33
In this case, it isn't the lock, but the fact that
| |
1966 Directory::ChildHandles* result) { | |
lipalani1
2011/06/02 18:51:52
Nit - CHECK(result != NULL)
akalin
2011/06/02 22:13:33
Done.
| |
1967 typedef ParentIdChildIndex::iterator iterator; | |
1968 for (iterator i = GetParentChildIndexLowerBound(lock, parent_id), | |
1969 end = GetParentChildIndexUpperBound(lock, parent_id); | |
1970 i != end; ++i) { | |
1971 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); | |
1972 result->push_back((*i)->ref(META_HANDLE)); | |
1973 } | |
1974 } | |
1975 | |
1955 } // namespace syncable | 1976 } // namespace syncable |
OLD | NEW |