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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 DCHECK(metadata); | 91 DCHECK(metadata); |
92 DCHECK(out_file_path); | 92 DCHECK(out_file_path); |
93 FileError error = metadata->AddEntry(entry); | 93 FileError error = metadata->AddEntry(entry); |
94 if (error == FILE_ERROR_OK) | 94 if (error == FILE_ERROR_OK) |
95 *out_file_path = metadata->GetFilePath(entry.resource_id()); | 95 *out_file_path = metadata->GetFilePath(entry.resource_id()); |
96 return error; | 96 return error; |
97 } | 97 } |
98 | 98 |
99 } // namespace | 99 } // namespace |
100 | 100 |
101 std::string DirectoryFetchInfo::ToString() const { | |
102 return ("resource_id: " + resource_id_ + | |
103 ", changestamp: " + base::Int64ToString(changestamp_)); | |
104 } | |
105 | |
106 EntryInfoResult::EntryInfoResult() : error(FILE_ERROR_FAILED) { | 101 EntryInfoResult::EntryInfoResult() : error(FILE_ERROR_FAILED) { |
107 } | 102 } |
108 | 103 |
109 EntryInfoResult::~EntryInfoResult() { | 104 EntryInfoResult::~EntryInfoResult() { |
110 } | 105 } |
111 | 106 |
112 EntryInfoPairResult::EntryInfoPairResult() { | 107 EntryInfoPairResult::EntryInfoPairResult() { |
113 } | 108 } |
114 | 109 |
115 EntryInfoPairResult::~EntryInfoPairResult() { | 110 EntryInfoPairResult::~EntryInfoPairResult() { |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 449 |
455 if (!new_parent.file_info().is_directory()) | 450 if (!new_parent.file_info().is_directory()) |
456 return FILE_ERROR_NOT_A_DIRECTORY; | 451 return FILE_ERROR_NOT_A_DIRECTORY; |
457 | 452 |
458 // Remove from the old parent and add it to the new parent with the new data. | 453 // Remove from the old parent and add it to the new parent with the new data. |
459 if (!PutEntryUnderDirectory(entry)) | 454 if (!PutEntryUnderDirectory(entry)) |
460 return FILE_ERROR_FAILED; | 455 return FILE_ERROR_FAILED; |
461 return FILE_ERROR_OK; | 456 return FILE_ERROR_OK; |
462 } | 457 } |
463 | 458 |
464 void ResourceMetadata::RefreshDirectoryOnUIThread( | |
465 const DirectoryFetchInfo& directory_fetch_info, | |
466 const ResourceEntryMap& entry_map, | |
467 const FileMoveCallback& callback) { | |
468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
469 DCHECK(!callback.is_null()); | |
470 | |
471 PostFileMoveTask(blocking_task_runner_.get(), | |
472 base::Bind(&ResourceMetadata::RefreshDirectory, | |
473 base::Unretained(this), | |
474 directory_fetch_info, | |
475 entry_map), | |
476 callback); | |
477 } | |
478 | |
479 void ResourceMetadata::GetChildDirectories( | 459 void ResourceMetadata::GetChildDirectories( |
480 const std::string& resource_id, | 460 const std::string& resource_id, |
481 std::set<base::FilePath>* child_directories) { | 461 std::set<base::FilePath>* child_directories) { |
482 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 462 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
483 | 463 |
484 std::vector<std::string> children; | 464 std::vector<std::string> children; |
485 storage_->GetChildren(resource_id, &children); | 465 storage_->GetChildren(resource_id, &children); |
486 for (size_t i = 0; i < children.size(); ++i) { | 466 for (size_t i = 0; i < children.size(); ++i) { |
487 ResourceEntry entry; | 467 ResourceEntry entry; |
488 if (storage_->GetEntry(children[i], &entry) && | 468 if (storage_->GetEntry(children[i], &entry) && |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 GetResourceEntryByPathOnUIThread( | 594 GetResourceEntryByPathOnUIThread( |
615 first_path, | 595 first_path, |
616 base::Bind( | 596 base::Bind( |
617 &ResourceMetadata::GetResourceEntryPairByPathsOnUIThreadAfterGetFirst, | 597 &ResourceMetadata::GetResourceEntryPairByPathsOnUIThreadAfterGetFirst, |
618 weak_ptr_factory_.GetWeakPtr(), | 598 weak_ptr_factory_.GetWeakPtr(), |
619 first_path, | 599 first_path, |
620 second_path, | 600 second_path, |
621 callback)); | 601 callback)); |
622 } | 602 } |
623 | 603 |
624 FileError ResourceMetadata::RefreshDirectory( | |
625 const DirectoryFetchInfo& directory_fetch_info, | |
626 const ResourceEntryMap& entry_map, | |
627 base::FilePath* out_file_path) { | |
628 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | |
629 DCHECK(!directory_fetch_info.empty()); | |
630 | |
631 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path())) | |
632 return FILE_ERROR_NO_LOCAL_SPACE; | |
633 | |
634 ResourceEntry directory; | |
635 if (!storage_->GetEntry(directory_fetch_info.resource_id(), &directory)) | |
636 return FILE_ERROR_NOT_FOUND; | |
637 | |
638 if (!directory.file_info().is_directory()) | |
639 return FILE_ERROR_NOT_A_DIRECTORY; | |
640 | |
641 // Go through the entry map. Handle existing entries and new entries. | |
642 for (ResourceEntryMap::const_iterator it = entry_map.begin(); | |
643 it != entry_map.end(); ++it) { | |
644 if (!EnoughDiskSpaceIsAvailableForDBOperation(storage_->directory_path())) | |
645 return FILE_ERROR_NO_LOCAL_SPACE; | |
646 | |
647 const ResourceEntry& entry = it->second; | |
648 // Skip if the parent resource ID does not match. This is needed to | |
649 // handle entries with multiple parents. For such entries, the first | |
650 // parent is picked and other parents are ignored, hence some entries may | |
651 // have a parent resource ID which does not match the target directory's. | |
652 // | |
653 // TODO(satorux): Move the filtering logic to somewhere more appropriate. | |
654 // crbug.com/193525. | |
655 if (entry.parent_local_id() != directory_fetch_info.resource_id()) { | |
656 DVLOG(1) << "Wrong-parent entry rejected: " << entry.resource_id(); | |
657 continue; | |
658 } | |
659 | |
660 if (!PutEntryUnderDirectory(entry)) | |
661 return FILE_ERROR_FAILED; | |
662 } | |
663 | |
664 directory.mutable_directory_specific_info()->set_changestamp( | |
665 directory_fetch_info.changestamp()); | |
666 if (!storage_->PutEntry(directory.resource_id(), directory)) | |
667 return FILE_ERROR_FAILED; | |
668 | |
669 if (out_file_path) | |
670 *out_file_path = GetFilePath(directory.resource_id()); | |
671 | |
672 return FILE_ERROR_OK; | |
673 } | |
674 | |
675 void ResourceMetadata::GetResourceEntryPairByPathsOnUIThreadAfterGetFirst( | 604 void ResourceMetadata::GetResourceEntryPairByPathsOnUIThreadAfterGetFirst( |
676 const base::FilePath& first_path, | 605 const base::FilePath& first_path, |
677 const base::FilePath& second_path, | 606 const base::FilePath& second_path, |
678 const GetResourceEntryPairCallback& callback, | 607 const GetResourceEntryPairCallback& callback, |
679 FileError error, | 608 FileError error, |
680 scoped_ptr<ResourceEntry> entry) { | 609 scoped_ptr<ResourceEntry> entry) { |
681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
682 DCHECK(!callback.is_null()); | 611 DCHECK(!callback.is_null()); |
683 | 612 |
684 scoped_ptr<EntryInfoPairResult> result(new EntryInfoPairResult); | 613 scoped_ptr<EntryInfoPairResult> result(new EntryInfoPairResult); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 for (size_t i = 0; i < children.size(); ++i) { | 699 for (size_t i = 0; i < children.size(); ++i) { |
771 if (!RemoveEntryRecursively(children[i])) | 700 if (!RemoveEntryRecursively(children[i])) |
772 return false; | 701 return false; |
773 } | 702 } |
774 } | 703 } |
775 return storage_->RemoveEntry(resource_id); | 704 return storage_->RemoveEntry(resource_id); |
776 } | 705 } |
777 | 706 |
778 } // namespace internal | 707 } // namespace internal |
779 } // namespace drive | 708 } // namespace drive |
OLD | NEW |