| 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/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 for (size_t i = 0; i < children.size(); ++i) { | 328 for (size_t i = 0; i < children.size(); ++i) { |
| 329 if (!storage_->GetEntry(children[i], &entries[i])) | 329 if (!storage_->GetEntry(children[i], &entries[i])) |
| 330 return FILE_ERROR_FAILED; | 330 return FILE_ERROR_FAILED; |
| 331 } | 331 } |
| 332 out_entries->swap(entries); | 332 out_entries->swap(entries); |
| 333 return FILE_ERROR_OK; | 333 return FILE_ERROR_OK; |
| 334 } | 334 } |
| 335 | 335 |
| 336 FileError ResourceMetadata::RefreshEntry(const ResourceEntry& entry) { | 336 FileError ResourceMetadata::RefreshEntry(const ResourceEntry& entry) { |
| 337 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 337 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
| 338 // TODO(hashimoto): Return an error if the operation will result in having | |
| 339 // multiple entries with the same resource ID. | |
| 340 | 338 |
| 341 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path())) | 339 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path())) |
| 342 return FILE_ERROR_NO_LOCAL_SPACE; | 340 return FILE_ERROR_NO_LOCAL_SPACE; |
| 343 | 341 |
| 344 ResourceEntry old_entry; | 342 ResourceEntry old_entry; |
| 345 if (!storage_->GetEntry(entry.local_id(), &old_entry)) | 343 if (!storage_->GetEntry(entry.local_id(), &old_entry)) |
| 346 return FILE_ERROR_NOT_FOUND; | 344 return FILE_ERROR_NOT_FOUND; |
| 347 | 345 |
| 348 if (old_entry.parent_local_id().empty() || // Reject root. | 346 if (old_entry.parent_local_id().empty() || // Reject root. |
| 349 old_entry.file_info().is_directory() != // Reject incompatible input. | 347 old_entry.file_info().is_directory() != // Reject incompatible input. |
| 350 entry.file_info().is_directory()) | 348 entry.file_info().is_directory()) |
| 351 return FILE_ERROR_INVALID_OPERATION; | 349 return FILE_ERROR_INVALID_OPERATION; |
| 352 | 350 |
| 351 if (!entry.resource_id().empty()) { |
| 352 // Multiple entries cannot share the same resource ID. |
| 353 std::string local_id; |
| 354 FileError error = GetIdByResourceId(entry.resource_id(), &local_id); |
| 355 switch (error) { |
| 356 case FILE_ERROR_OK: |
| 357 if (local_id != entry.local_id()) |
| 358 return FILE_ERROR_INVALID_OPERATION; |
| 359 break; |
| 360 |
| 361 case FILE_ERROR_NOT_FOUND: |
| 362 break; |
| 363 |
| 364 default: |
| 365 return error; |
| 366 } |
| 367 } |
| 368 |
| 353 // Make sure that the new parent exists and it is a directory. | 369 // Make sure that the new parent exists and it is a directory. |
| 354 ResourceEntry new_parent; | 370 ResourceEntry new_parent; |
| 355 if (!storage_->GetEntry(entry.parent_local_id(), &new_parent)) | 371 if (!storage_->GetEntry(entry.parent_local_id(), &new_parent)) |
| 356 return FILE_ERROR_NOT_FOUND; | 372 return FILE_ERROR_NOT_FOUND; |
| 357 | 373 |
| 358 if (!new_parent.file_info().is_directory()) | 374 if (!new_parent.file_info().is_directory()) |
| 359 return FILE_ERROR_NOT_A_DIRECTORY; | 375 return FILE_ERROR_NOT_A_DIRECTORY; |
| 360 | 376 |
| 361 // Remove from the old parent and add it to the new parent with the new data. | 377 // Remove from the old parent and add it to the new parent with the new data. |
| 362 if (!PutEntryUnderDirectory(entry)) | 378 if (!PutEntryUnderDirectory(entry)) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 for (size_t i = 0; i < children.size(); ++i) { | 501 for (size_t i = 0; i < children.size(); ++i) { |
| 486 if (!RemoveEntryRecursively(children[i])) | 502 if (!RemoveEntryRecursively(children[i])) |
| 487 return false; | 503 return false; |
| 488 } | 504 } |
| 489 } | 505 } |
| 490 return storage_->RemoveEntry(id); | 506 return storage_->RemoveEntry(id); |
| 491 } | 507 } |
| 492 | 508 |
| 493 } // namespace internal | 509 } // namespace internal |
| 494 } // namespace drive | 510 } // namespace drive |
| OLD | NEW |