Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/sync/syncable/syncable.cc

Issue 2854018: sync: Add method to Directory to remove all entries for a set of ModelTypes.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix sign issue with last-minute DCHECK I threw in Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 kernel_->extended_attributes->find(key); 603 kernel_->extended_attributes->find(key);
604 if (found == kernel_->extended_attributes->end() || 604 if (found == kernel_->extended_attributes->end() ||
605 found->second.dirty || !i->second.is_deleted) { 605 found->second.dirty || !i->second.is_deleted) {
606 ++i; 606 ++i;
607 } else { 607 } else {
608 kernel_->extended_attributes->erase(found); 608 kernel_->extended_attributes->erase(found);
609 } 609 }
610 } 610 }
611 } 611 }
612 612
613 void Directory::PurgeEntriesWithTypeIn(const std::set<ModelType>& types) {
614 DCHECK_EQ(0U, types.count(UNSPECIFIED));
615 DCHECK_EQ(0U, types.count(TOP_LEVEL_FOLDER));
616
617 if (types.empty())
618 return;
619
620 ScopedKernelLock lock(this);
621 MetahandleSet to_delete;
622 MetahandlesIndex::iterator it = kernel_->metahandles_index->begin();
623 while (it != kernel_->metahandles_index->end()) {
624 const sync_pb::EntitySpecifics& local_specifics = (*it)->ref(SPECIFICS);
625 const sync_pb::EntitySpecifics& server_specifics =
626 (*it)->ref(SERVER_SPECIFICS);
627 ModelType local_type = GetModelTypeFromSpecifics(local_specifics);
628 ModelType server_type = GetModelTypeFromSpecifics(server_specifics);
629
630 // Note the dance around incrementing |it|, since we sometimes use erase().
631 if (types.count(local_type) > 0 || types.count(server_type) > 0) {
632 to_delete.insert((*it)->ref(META_HANDLE));
633 size_t num_erased = 0;
634 num_erased = kernel_->ids_index->erase(*it);
635 DCHECK_EQ(1u, num_erased);
636 num_erased = kernel_->client_tag_index->erase(*it);
637 DCHECK_EQ((*it)->ref(UNIQUE_CLIENT_TAG).empty(), !num_erased);
638 kernel_->metahandles_index->erase(it++);
639 } else {
640 ++it;
641 }
642 }
643
644 // Synchronously wipe these entries from disk.
645 store_->DeleteEntries(to_delete);
646 }
647
613 void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) { 648 void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) {
614 ScopedKernelLock lock(this); 649 ScopedKernelLock lock(this);
615 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; 650 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY;
616 651
617 // Because we optimistically cleared the dirty bit on the real entries when 652 // Because we optimistically cleared the dirty bit on the real entries when
618 // taking the snapshot, we must restore it on failure. Not doing this could 653 // taking the snapshot, we must restore it on failure. Not doing this could
619 // cause lost data, if no other changes are made to the in-memory entries 654 // cause lost data, if no other changes are made to the in-memory entries
620 // that would cause the dirty bit to get set again. Setting the bit ensures 655 // that would cause the dirty bit to get set again. Setting the bit ensures
621 // that SaveChanges will at least try again later. 656 // that SaveChanges will at least try again later.
622 for (OriginalEntries::const_iterator i = snapshot.dirty_metas.begin(); 657 for (OriginalEntries::const_iterator i = snapshot.dirty_metas.begin();
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 return s << std::dec; 1627 return s << std::dec;
1593 } 1628 }
1594 1629
1595 FastDump& operator<<(FastDump& dump, const syncable::Blob& blob) { 1630 FastDump& operator<<(FastDump& dump, const syncable::Blob& blob) {
1596 if (blob.empty()) 1631 if (blob.empty())
1597 return dump; 1632 return dump;
1598 string buffer(HexEncode(&blob[0], blob.size())); 1633 string buffer(HexEncode(&blob[0], blob.size()));
1599 dump.out_->sputn(buffer.c_str(), buffer.size()); 1634 dump.out_->sputn(buffer.c_str(), buffer.size());
1600 return dump; 1635 return dump;
1601 } 1636 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/syncable.h ('k') | chrome/browser/sync/syncable/syncable_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698