| 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 "chrome/browser/chromeos/drive/drive_resource_metadata.h" | 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
| 6 | 6 |
| 7 #include <leveldb/db.h> | 7 #include <leveldb/db.h> |
| 8 #include <stack> | 8 #include <stack> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 RemoveEntryFromResourceMap(entry->resource_id()); | 737 RemoveEntryFromResourceMap(entry->resource_id()); |
| 738 | 738 |
| 739 // Then delete it from tree. | 739 // Then delete it from tree. |
| 740 child_maps_[directory->resource_id()].erase(base_name); | 740 child_maps_[directory->resource_id()].erase(base_name); |
| 741 | 741 |
| 742 entry->set_parent_resource_id(std::string()); | 742 entry->set_parent_resource_id(std::string()); |
| 743 } | 743 } |
| 744 | 744 |
| 745 void DriveResourceMetadata::RemoveDirectoryChildren( | 745 void DriveResourceMetadata::RemoveDirectoryChildren( |
| 746 DriveEntryProto* directory) { | 746 DriveEntryProto* directory) { |
| 747 RemoveDirectoryChildFiles(directory); | |
| 748 RemoveDirectoryChildDirectories(directory); | |
| 749 DCHECK(child_maps_[directory->resource_id()].empty()); | |
| 750 child_maps_.erase(directory->resource_id()); | |
| 751 } | |
| 752 | |
| 753 void DriveResourceMetadata::RemoveDirectoryChildFiles( | |
| 754 DriveEntryProto* directory) { | |
| 755 DCHECK(directory->file_info().is_directory()); | 747 DCHECK(directory->file_info().is_directory()); |
| 756 DriveResourceMetadata::ChildMap* children = | 748 DriveResourceMetadata::ChildMap* children = |
| 757 &child_maps_[directory->resource_id()]; | 749 &child_maps_[directory->resource_id()]; |
| 758 for (DriveResourceMetadata::ChildMap::iterator iter = children->begin(), | 750 for (DriveResourceMetadata::ChildMap::iterator iter = children->begin(); |
| 759 iter_next = iter; iter != children->end(); iter = iter_next) { | 751 iter != children->end(); ++iter) { |
| 760 ++iter_next; | |
| 761 DriveEntryProto* child = GetEntryByResourceId(iter->second); | 752 DriveEntryProto* child = GetEntryByResourceId(iter->second); |
| 762 DCHECK(child); | 753 DCHECK(child); |
| 763 if (!child->file_info().is_directory()) { | 754 // Remove directories recursively. |
| 764 RemoveEntryFromResourceMap(iter->second); | 755 if (child->file_info().is_directory()) |
| 765 delete child; | 756 RemoveDirectoryChildren(child); |
| 766 children->erase(iter); | 757 |
| 767 } | 758 RemoveEntryFromResourceMap(iter->second); |
| 759 delete child; |
| 768 } | 760 } |
| 769 } | 761 child_maps_.erase(directory->resource_id()); |
| 770 | |
| 771 void DriveResourceMetadata::RemoveDirectoryChildDirectories( | |
| 772 DriveEntryProto* directory) { | |
| 773 DCHECK(directory->file_info().is_directory()); | |
| 774 DriveResourceMetadata::ChildMap* children = | |
| 775 &child_maps_[directory->resource_id()]; | |
| 776 for (DriveResourceMetadata::ChildMap::iterator iter = children->begin(), | |
| 777 iter_next = iter; iter != children->end(); iter = iter_next) { | |
| 778 ++iter_next; | |
| 779 DriveEntryProto* entry = GetEntryByResourceId(iter->second); | |
| 780 DCHECK(entry); | |
| 781 if (entry->file_info().is_directory()) { | |
| 782 // Remove directories recursively. | |
| 783 RemoveDirectoryChildren(entry); | |
| 784 RemoveEntryFromResourceMap(iter->second); | |
| 785 delete entry; | |
| 786 children->erase(iter); | |
| 787 } | |
| 788 } | |
| 789 } | 762 } |
| 790 | 763 |
| 791 void DriveResourceMetadata::ProtoToDirectory(const DriveDirectoryProto& proto, | 764 void DriveResourceMetadata::ProtoToDirectory(const DriveDirectoryProto& proto, |
| 792 DriveEntryProto* directory) { | 765 DriveEntryProto* directory) { |
| 793 DCHECK(proto.drive_entry().file_info().is_directory()); | 766 DCHECK(proto.drive_entry().file_info().is_directory()); |
| 794 DCHECK(!proto.drive_entry().has_file_specific_info()); | 767 DCHECK(!proto.drive_entry().has_file_specific_info()); |
| 795 | 768 |
| 796 *directory = CreateEntryWithProperBaseName(proto.drive_entry()); | 769 *directory = CreateEntryWithProperBaseName(proto.drive_entry()); |
| 797 | 770 |
| 798 for (int i = 0; i < proto.child_files_size(); ++i) { | 771 for (int i = 0; i < proto.child_files_size(); ++i) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 const ChildMap& children = child_maps_[directory->resource_id()]; | 805 const ChildMap& children = child_maps_[directory->resource_id()]; |
| 833 for (ChildMap::const_iterator iter = children.begin(); | 806 for (ChildMap::const_iterator iter = children.begin(); |
| 834 iter != children.end(); ++iter) { | 807 iter != children.end(); ++iter) { |
| 835 const DriveEntryProto& proto = *GetEntryByResourceId(iter->second); | 808 const DriveEntryProto& proto = *GetEntryByResourceId(iter->second); |
| 836 entries->push_back(proto); | 809 entries->push_back(proto); |
| 837 } | 810 } |
| 838 return entries.Pass(); | 811 return entries.Pass(); |
| 839 } | 812 } |
| 840 | 813 |
| 841 } // namespace drive | 814 } // namespace drive |
| OLD | NEW |