| 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/resource_metadata.h" | 5 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "chrome/browser/chromeos/drive/drive.pb.h" | 10 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 440 |
| 441 ResourceEntry old_entry; | 441 ResourceEntry old_entry; |
| 442 if (!storage_->GetEntry(entry.resource_id(), &old_entry)) | 442 if (!storage_->GetEntry(entry.resource_id(), &old_entry)) |
| 443 return FILE_ERROR_NOT_FOUND; | 443 return FILE_ERROR_NOT_FOUND; |
| 444 | 444 |
| 445 if (old_entry.parent_local_id().empty() || // Reject root. | 445 if (old_entry.parent_local_id().empty() || // Reject root. |
| 446 old_entry.file_info().is_directory() != // Reject incompatible input. | 446 old_entry.file_info().is_directory() != // Reject incompatible input. |
| 447 entry.file_info().is_directory()) | 447 entry.file_info().is_directory()) |
| 448 return FILE_ERROR_INVALID_OPERATION; | 448 return FILE_ERROR_INVALID_OPERATION; |
| 449 | 449 |
| 450 // Update data. | 450 // Make sure that the new parent exists and it is a directory. |
| 451 ResourceEntry new_parent; | 451 ResourceEntry new_parent; |
| 452 if (!storage_->GetEntry(entry.parent_local_id(), &new_parent) || | 452 if (!storage_->GetEntry(entry.parent_local_id(), &new_parent)) |
| 453 !new_parent.file_info().is_directory()) | |
| 454 return FILE_ERROR_NOT_FOUND; | 453 return FILE_ERROR_NOT_FOUND; |
| 455 | 454 |
| 455 if (!new_parent.file_info().is_directory()) |
| 456 return FILE_ERROR_NOT_A_DIRECTORY; |
| 457 |
| 456 // Remove from the old parent and add it to the new parent with the new data. | 458 // Remove from the old parent and add it to the new parent with the new data. |
| 457 if (!PutEntryUnderDirectory(entry)) | 459 if (!PutEntryUnderDirectory(entry)) |
| 458 return FILE_ERROR_FAILED; | 460 return FILE_ERROR_FAILED; |
| 459 return FILE_ERROR_OK; | 461 return FILE_ERROR_OK; |
| 460 } | 462 } |
| 461 | 463 |
| 462 void ResourceMetadata::RefreshDirectoryOnUIThread( | 464 void ResourceMetadata::RefreshDirectoryOnUIThread( |
| 463 const DirectoryFetchInfo& directory_fetch_info, | 465 const DirectoryFetchInfo& directory_fetch_info, |
| 464 const ResourceEntryMap& entry_map, | 466 const ResourceEntryMap& entry_map, |
| 465 const FileMoveCallback& callback) { | 467 const FileMoveCallback& callback) { |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 for (size_t i = 0; i < children.size(); ++i) { | 770 for (size_t i = 0; i < children.size(); ++i) { |
| 769 if (!RemoveEntryRecursively(children[i])) | 771 if (!RemoveEntryRecursively(children[i])) |
| 770 return false; | 772 return false; |
| 771 } | 773 } |
| 772 } | 774 } |
| 773 return storage_->RemoveEntry(resource_id); | 775 return storage_->RemoveEntry(resource_id); |
| 774 } | 776 } |
| 775 | 777 |
| 776 } // namespace internal | 778 } // namespace internal |
| 777 } // namespace drive | 779 } // namespace drive |
| OLD | NEW |