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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 (&trans))) | 570 (&trans))) |
571 return false; | 571 return false; |
572 delete entry; | 572 delete entry; |
573 } | 573 } |
574 if (trans.unrecoverable_error_set()) | 574 if (trans.unrecoverable_error_set()) |
575 return false; | 575 return false; |
576 } | 576 } |
577 return true; | 577 return true; |
578 } | 578 } |
579 | 579 |
580 void Directory::PurgeEntriesWithTypeIn(ModelTypeSet types) { | 580 bool Directory::PurgeEntriesWithTypeIn(ModelTypeSet types) { |
581 if (types.Empty()) | 581 if (types.Empty()) |
582 return; | 582 return true; |
583 | 583 |
584 { | 584 { |
585 WriteTransaction trans(FROM_HERE, PURGE_ENTRIES, this); | 585 WriteTransaction trans(FROM_HERE, PURGE_ENTRIES, this); |
586 { | 586 { |
587 ScopedKernelLock lock(this); | 587 ScopedKernelLock lock(this); |
588 MetahandlesIndex::iterator it = kernel_->metahandles_index->begin(); | 588 MetahandlesIndex::iterator it = kernel_->metahandles_index->begin(); |
589 while (it != kernel_->metahandles_index->end()) { | 589 while (it != kernel_->metahandles_index->end()) { |
590 const sync_pb::EntitySpecifics& local_specifics = (*it)->ref(SPECIFICS); | 590 const sync_pb::EntitySpecifics& local_specifics = (*it)->ref(SPECIFICS); |
591 const sync_pb::EntitySpecifics& server_specifics = | 591 const sync_pb::EntitySpecifics& server_specifics = |
592 (*it)->ref(SERVER_SPECIFICS); | 592 (*it)->ref(SERVER_SPECIFICS); |
593 ModelType local_type = GetModelTypeFromSpecifics(local_specifics); | 593 ModelType local_type = GetModelTypeFromSpecifics(local_specifics); |
594 ModelType server_type = GetModelTypeFromSpecifics(server_specifics); | 594 ModelType server_type = GetModelTypeFromSpecifics(server_specifics); |
595 | 595 |
596 // Note the dance around incrementing |it|, since we sometimes erase(). | 596 // Note the dance around incrementing |it|, since we sometimes erase(). |
597 if ((IsRealDataType(local_type) && types.Has(local_type)) || | 597 if ((IsRealDataType(local_type) && types.Has(local_type)) || |
598 (IsRealDataType(server_type) && types.Has(server_type))) { | 598 (IsRealDataType(server_type) && types.Has(server_type))) { |
599 if (!UnlinkEntryFromOrder(*it, &trans, &lock, DATA_TYPE_PURGE)) | 599 if (!UnlinkEntryFromOrder(*it, &trans, &lock, DATA_TYPE_PURGE)) |
600 return; | 600 return false; |
601 | 601 |
602 int64 handle = (*it)->ref(META_HANDLE); | 602 int64 handle = (*it)->ref(META_HANDLE); |
603 kernel_->metahandles_to_purge->insert(handle); | 603 kernel_->metahandles_to_purge->insert(handle); |
604 | 604 |
605 size_t num_erased = 0; | 605 size_t num_erased = 0; |
606 EntryKernel* entry = *it; | 606 EntryKernel* entry = *it; |
607 num_erased = kernel_->ids_index->erase(entry); | 607 num_erased = kernel_->ids_index->erase(entry); |
608 DCHECK_EQ(1u, num_erased); | 608 DCHECK_EQ(1u, num_erased); |
609 num_erased = kernel_->client_tag_index->erase(entry); | 609 num_erased = kernel_->client_tag_index->erase(entry); |
610 DCHECK_EQ(entry->ref(UNIQUE_CLIENT_TAG).empty(), !num_erased); | 610 DCHECK_EQ(entry->ref(UNIQUE_CLIENT_TAG).empty(), !num_erased); |
(...skipping 12 matching lines...) Expand all Loading... |
623 } | 623 } |
624 | 624 |
625 // Ensure meta tracking for these data types reflects the deleted state. | 625 // Ensure meta tracking for these data types reflects the deleted state. |
626 for (syncer::ModelTypeSet::Iterator it = types.First(); | 626 for (syncer::ModelTypeSet::Iterator it = types.First(); |
627 it.Good(); it.Inc()) { | 627 it.Good(); it.Inc()) { |
628 set_initial_sync_ended_for_type_unsafe(it.Get(), false); | 628 set_initial_sync_ended_for_type_unsafe(it.Get(), false); |
629 kernel_->persisted_info.reset_download_progress(it.Get()); | 629 kernel_->persisted_info.reset_download_progress(it.Get()); |
630 } | 630 } |
631 } | 631 } |
632 } | 632 } |
| 633 return true; |
633 } | 634 } |
634 | 635 |
635 void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) { | 636 void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) { |
636 ScopedKernelLock lock(this); | 637 ScopedKernelLock lock(this); |
637 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; | 638 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; |
638 | 639 |
639 // Because we optimistically cleared the dirty bit on the real entries when | 640 // Because we optimistically cleared the dirty bit on the real entries when |
640 // taking the snapshot, we must restore it on failure. Not doing this could | 641 // taking the snapshot, we must restore it on failure. Not doing this could |
641 // cause lost data, if no other changes are made to the in-memory entries | 642 // cause lost data, if no other changes are made to the in-memory entries |
642 // that would cause the dirty bit to get set again. Setting the bit ensures | 643 // that would cause the dirty bit to get set again. Setting the bit ensures |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 // There were no children in the linked list. | 1249 // There were no children in the linked list. |
1249 return NULL; | 1250 return NULL; |
1250 } | 1251 } |
1251 | 1252 |
1252 ScopedKernelLock::ScopedKernelLock(const Directory* dir) | 1253 ScopedKernelLock::ScopedKernelLock(const Directory* dir) |
1253 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { | 1254 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { |
1254 } | 1255 } |
1255 | 1256 |
1256 } // namespace syncable | 1257 } // namespace syncable |
1257 } // namespace syncer | 1258 } // namespace syncer |
OLD | NEW |