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 "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 314 |
315 ScopedKernelLock lock(this); | 315 ScopedKernelLock lock(this); |
316 EntryKernel* kernel = GetEntryByHandle(handle, &lock); | 316 EntryKernel* kernel = GetEntryByHandle(handle, &lock); |
317 if (!kernel) | 317 if (!kernel) |
318 return true; | 318 return true; |
319 | 319 |
320 AppendChildHandles(lock, kernel->ref(ID), result); | 320 AppendChildHandles(lock, kernel->ref(ID), result); |
321 return true; | 321 return true; |
322 } | 322 } |
323 | 323 |
| 324 int Directory::GetTotalNodeCount( |
| 325 BaseTransaction* trans, |
| 326 EntryKernel* kernel) const { |
| 327 if (!SyncAssert(this == trans->directory(), FROM_HERE, |
| 328 "Directories don't match", trans)) |
| 329 return false; |
| 330 |
| 331 int count = 1; |
| 332 std::deque<const OrderedChildSet*> child_sets; |
| 333 |
| 334 GetChildSetForKernel(trans, kernel, &child_sets); |
| 335 while (!child_sets.empty()) { |
| 336 const OrderedChildSet* set = child_sets.front(); |
| 337 child_sets.pop_front(); |
| 338 for (OrderedChildSet::const_iterator it = set->begin(); |
| 339 it != set->end(); ++it) { |
| 340 count++; |
| 341 GetChildSetForKernel(trans, *it, &child_sets); |
| 342 } |
| 343 } |
| 344 |
| 345 return count; |
| 346 } |
| 347 |
| 348 void Directory::GetChildSetForKernel( |
| 349 BaseTransaction* trans, |
| 350 EntryKernel* kernel, |
| 351 std::deque<const OrderedChildSet*>* child_sets) const { |
| 352 if (!kernel->ref(IS_DIR)) |
| 353 return; // Not a directory => no children. |
| 354 |
| 355 const OrderedChildSet* descendants = |
| 356 kernel_->parent_child_index->GetChildren(kernel->ref(ID)); |
| 357 if (!descendants) |
| 358 return; // This directory has no children. |
| 359 |
| 360 // Add our children to the list of items to be traversed. |
| 361 child_sets->push_back(descendants); |
| 362 } |
| 363 |
324 EntryKernel* Directory::GetRootEntry() { | 364 EntryKernel* Directory::GetRootEntry() { |
325 return GetEntryById(Id()); | 365 return GetEntryById(Id()); |
326 } | 366 } |
327 | 367 |
328 bool Directory::InsertEntry(WriteTransaction* trans, EntryKernel* entry) { | 368 bool Directory::InsertEntry(WriteTransaction* trans, EntryKernel* entry) { |
329 ScopedKernelLock lock(this); | 369 ScopedKernelLock lock(this); |
330 return InsertEntry(trans, entry, &lock); | 370 return InsertEntry(trans, entry, &lock); |
331 } | 371 } |
332 | 372 |
333 bool Directory::InsertEntry(WriteTransaction* trans, | 373 bool Directory::InsertEntry(WriteTransaction* trans, |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 result->push_back((*i)->ref(META_HANDLE)); | 1212 result->push_back((*i)->ref(META_HANDLE)); |
1173 } | 1213 } |
1174 } | 1214 } |
1175 | 1215 |
1176 ScopedKernelLock::ScopedKernelLock(const Directory* dir) | 1216 ScopedKernelLock::ScopedKernelLock(const Directory* dir) |
1177 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { | 1217 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { |
1178 } | 1218 } |
1179 | 1219 |
1180 } // namespace syncable | 1220 } // namespace syncable |
1181 } // namespace syncer | 1221 } // namespace syncer |
OLD | NEW |