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 "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/sys_info.h" |
10 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
11 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 12 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
12 #include "chrome/browser/chromeos/drive/drive_resource_metadata_storage.h" | 13 #include "chrome/browser/chromeos/drive/drive_resource_metadata_storage.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 | 15 |
15 using content::BrowserThread; | 16 using content::BrowserThread; |
16 | 17 |
17 namespace drive { | 18 namespace drive { |
18 namespace { | 19 namespace { |
19 | 20 |
(...skipping 15 matching lines...) Expand all Loading... |
35 } | 36 } |
36 | 37 |
37 // Runs |callback| with |result|. Used to implement GetChildDirectories(). | 38 // Runs |callback| with |result|. Used to implement GetChildDirectories(). |
38 void RunGetChildDirectoriesCallbackWithResult( | 39 void RunGetChildDirectoriesCallbackWithResult( |
39 const GetChildDirectoriesCallback& callback, | 40 const GetChildDirectoriesCallback& callback, |
40 scoped_ptr<std::set<base::FilePath> > result) { | 41 scoped_ptr<std::set<base::FilePath> > result) { |
41 DCHECK(!callback.is_null()); | 42 DCHECK(!callback.is_null()); |
42 callback.Run(*result); | 43 callback.Run(*result); |
43 } | 44 } |
44 | 45 |
| 46 // Returns true if enough disk space is avilable for DB operation. |
| 47 // TODO(hashimoto): Merge this with DriveCache's FreeDiskSpaceGetterInterface. |
| 48 bool EnoughDiskSpaceIsAvailableForDBOperation(const base::FilePath& path) { |
| 49 const int64 kRequiredDiskSpaceInMB = 128; // 128 MB seems to be large enough. |
| 50 return base::SysInfo::AmountOfFreeDiskSpace(path) >= |
| 51 kRequiredDiskSpaceInMB * (1 << 20); |
| 52 } |
| 53 |
45 } // namespace | 54 } // namespace |
46 | 55 |
47 std::string DirectoryFetchInfo::ToString() const { | 56 std::string DirectoryFetchInfo::ToString() const { |
48 return ("resource_id: " + resource_id_ + | 57 return ("resource_id: " + resource_id_ + |
49 ", changestamp: " + base::Int64ToString(changestamp_)); | 58 ", changestamp: " + base::Int64ToString(changestamp_)); |
50 } | 59 } |
51 | 60 |
52 EntryInfoResult::EntryInfoResult() : error(DRIVE_FILE_ERROR_FAILED) { | 61 EntryInfoResult::EntryInfoResult() : error(DRIVE_FILE_ERROR_FAILED) { |
53 } | 62 } |
54 | 63 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 callback); | 203 callback); |
195 } | 204 } |
196 | 205 |
197 DriveResourceMetadata::~DriveResourceMetadata() { | 206 DriveResourceMetadata::~DriveResourceMetadata() { |
198 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 207 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
199 } | 208 } |
200 | 209 |
201 DriveFileError DriveResourceMetadata::InitializeOnBlockingPool() { | 210 DriveFileError DriveResourceMetadata::InitializeOnBlockingPool() { |
202 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 211 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
203 | 212 |
| 213 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) |
| 214 return DRIVE_FILE_ERROR_NO_SPACE; |
| 215 |
204 // Initialize the storage. | 216 // Initialize the storage. |
205 if (!storage_->Initialize()) | 217 if (!storage_->Initialize()) |
206 return DRIVE_FILE_ERROR_FAILED; | 218 return DRIVE_FILE_ERROR_FAILED; |
207 | 219 |
208 SetUpDefaultEntries(); | 220 SetUpDefaultEntries(); |
209 | 221 |
210 return DRIVE_FILE_OK; | 222 return DRIVE_FILE_OK; |
211 } | 223 } |
212 | 224 |
213 void DriveResourceMetadata::SetUpDefaultEntries() { | 225 void DriveResourceMetadata::SetUpDefaultEntries() { |
(...skipping 14 matching lines...) Expand all Loading... |
228 } | 240 } |
229 | 241 |
230 void DriveResourceMetadata::DestroyOnBlockingPool() { | 242 void DriveResourceMetadata::DestroyOnBlockingPool() { |
231 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 243 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
232 delete this; | 244 delete this; |
233 } | 245 } |
234 | 246 |
235 void DriveResourceMetadata::ResetOnBlockingPool() { | 247 void DriveResourceMetadata::ResetOnBlockingPool() { |
236 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 248 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
237 | 249 |
| 250 // TODO(hashimoto): Return DRIVE_FILE_ERROR_NO_SPACE here. |
| 251 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) { |
| 252 LOG(ERROR) << "Required disk space not available."; |
| 253 return; |
| 254 } |
| 255 |
238 RemoveAllOnBlockingPool(); | 256 RemoveAllOnBlockingPool(); |
239 storage_->SetLargestChangestamp(0); | 257 storage_->SetLargestChangestamp(0); |
240 } | 258 } |
241 | 259 |
242 void DriveResourceMetadata::GetLargestChangestamp( | 260 void DriveResourceMetadata::GetLargestChangestamp( |
243 const GetChangestampCallback& callback) { | 261 const GetChangestampCallback& callback) { |
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
245 DCHECK(!callback.is_null()); | 263 DCHECK(!callback.is_null()); |
246 base::PostTaskAndReplyWithResult( | 264 base::PostTaskAndReplyWithResult( |
247 blocking_task_runner_, | 265 blocking_task_runner_, |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 } | 462 } |
445 | 463 |
446 int64 DriveResourceMetadata::GetLargestChangestampOnBlockingPool() { | 464 int64 DriveResourceMetadata::GetLargestChangestampOnBlockingPool() { |
447 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 465 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
448 return storage_->GetLargestChangestamp(); | 466 return storage_->GetLargestChangestamp(); |
449 } | 467 } |
450 | 468 |
451 DriveFileError DriveResourceMetadata::SetLargestChangestampOnBlockingPool( | 469 DriveFileError DriveResourceMetadata::SetLargestChangestampOnBlockingPool( |
452 int64 value) { | 470 int64 value) { |
453 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 471 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
| 472 |
| 473 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) |
| 474 return DRIVE_FILE_ERROR_NO_SPACE; |
| 475 |
454 storage_->SetLargestChangestamp(value); | 476 storage_->SetLargestChangestamp(value); |
455 return DRIVE_FILE_OK; | 477 return DRIVE_FILE_OK; |
456 } | 478 } |
457 | 479 |
458 DriveResourceMetadata::FileMoveResult | 480 DriveResourceMetadata::FileMoveResult |
459 DriveResourceMetadata::MoveEntryToDirectoryOnBlockingPool( | 481 DriveResourceMetadata::MoveEntryToDirectoryOnBlockingPool( |
460 const base::FilePath& file_path, | 482 const base::FilePath& file_path, |
461 const base::FilePath& directory_path) { | 483 const base::FilePath& directory_path) { |
462 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 484 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
463 DCHECK(!directory_path.empty()); | 485 DCHECK(!directory_path.empty()); |
464 DCHECK(!file_path.empty()); | 486 DCHECK(!file_path.empty()); |
465 | 487 |
| 488 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) |
| 489 return FileMoveResult(DRIVE_FILE_ERROR_NO_SPACE); |
| 490 |
466 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(file_path); | 491 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(file_path); |
467 if (!entry) | 492 if (!entry) |
468 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); | 493 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); |
469 | 494 |
470 // Cannot move an entry without its parent. (i.e. the root) | 495 // Cannot move an entry without its parent. (i.e. the root) |
471 if (entry->parent_resource_id().empty()) | 496 if (entry->parent_resource_id().empty()) |
472 return FileMoveResult(DRIVE_FILE_ERROR_INVALID_OPERATION); | 497 return FileMoveResult(DRIVE_FILE_ERROR_INVALID_OPERATION); |
473 | 498 |
474 scoped_ptr<DriveEntryProto> destination = FindEntryByPathSync(directory_path); | 499 scoped_ptr<DriveEntryProto> destination = FindEntryByPathSync(directory_path); |
475 base::FilePath moved_file_path; | 500 base::FilePath moved_file_path; |
(...skipping 15 matching lines...) Expand all Loading... |
491 | 516 |
492 DriveResourceMetadata::FileMoveResult | 517 DriveResourceMetadata::FileMoveResult |
493 DriveResourceMetadata::RenameEntryOnBlockingPool( | 518 DriveResourceMetadata::RenameEntryOnBlockingPool( |
494 const base::FilePath& file_path, | 519 const base::FilePath& file_path, |
495 const std::string& new_name) { | 520 const std::string& new_name) { |
496 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 521 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
497 DCHECK(!file_path.empty()); | 522 DCHECK(!file_path.empty()); |
498 DCHECK(!new_name.empty()); | 523 DCHECK(!new_name.empty()); |
499 | 524 |
500 DVLOG(1) << "RenameEntry " << file_path.value() << " to " << new_name; | 525 DVLOG(1) << "RenameEntry " << file_path.value() << " to " << new_name; |
| 526 |
| 527 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) |
| 528 return FileMoveResult(DRIVE_FILE_ERROR_NO_SPACE); |
| 529 |
501 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(file_path); | 530 scoped_ptr<DriveEntryProto> entry = FindEntryByPathSync(file_path); |
502 if (!entry) | 531 if (!entry) |
503 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); | 532 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); |
504 | 533 |
505 if (base::FilePath::FromUTF8Unsafe(new_name) == file_path.BaseName()) | 534 if (base::FilePath::FromUTF8Unsafe(new_name) == file_path.BaseName()) |
506 return FileMoveResult(DRIVE_FILE_ERROR_EXISTS); | 535 return FileMoveResult(DRIVE_FILE_ERROR_EXISTS); |
507 | 536 |
508 entry->set_title(new_name); | 537 entry->set_title(new_name); |
509 scoped_ptr<GetEntryInfoWithFilePathResult> result = | 538 scoped_ptr<GetEntryInfoWithFilePathResult> result = |
510 RefreshEntryOnBlockingPool(*entry); | 539 RefreshEntryOnBlockingPool(*entry); |
511 return FileMoveResult(result->error, result->path); | 540 return FileMoveResult(result->error, result->path); |
512 } | 541 } |
513 | 542 |
514 DriveResourceMetadata::FileMoveResult | 543 DriveResourceMetadata::FileMoveResult |
515 DriveResourceMetadata::RemoveEntryOnBlockingPool( | 544 DriveResourceMetadata::RemoveEntryOnBlockingPool( |
516 const std::string& resource_id) { | 545 const std::string& resource_id) { |
517 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 546 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
518 | 547 |
| 548 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) |
| 549 return FileMoveResult(DRIVE_FILE_ERROR_NO_SPACE); |
| 550 |
519 // Disallow deletion of special entries "/drive" and "/drive/other". | 551 // Disallow deletion of special entries "/drive" and "/drive/other". |
520 if (util::IsSpecialResourceId(resource_id)) | 552 if (util::IsSpecialResourceId(resource_id)) |
521 return FileMoveResult(DRIVE_FILE_ERROR_ACCESS_DENIED); | 553 return FileMoveResult(DRIVE_FILE_ERROR_ACCESS_DENIED); |
522 | 554 |
523 scoped_ptr<DriveEntryProto> entry = storage_->GetEntry(resource_id); | 555 scoped_ptr<DriveEntryProto> entry = storage_->GetEntry(resource_id); |
524 if (!entry) | 556 if (!entry) |
525 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); | 557 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); |
526 | 558 |
527 RemoveDirectoryChild(entry->resource_id()); | 559 RemoveDirectoryChild(entry->resource_id()); |
528 return FileMoveResult(DRIVE_FILE_OK, | 560 return FileMoveResult(DRIVE_FILE_OK, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 first_path, | 660 first_path, |
629 second_path, | 661 second_path, |
630 callback)); | 662 callback)); |
631 } | 663 } |
632 | 664 |
633 scoped_ptr<DriveResourceMetadata::GetEntryInfoWithFilePathResult> | 665 scoped_ptr<DriveResourceMetadata::GetEntryInfoWithFilePathResult> |
634 DriveResourceMetadata::RefreshEntryOnBlockingPool( | 666 DriveResourceMetadata::RefreshEntryOnBlockingPool( |
635 const DriveEntryProto& entry_proto) { | 667 const DriveEntryProto& entry_proto) { |
636 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 668 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
637 | 669 |
| 670 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) { |
| 671 return make_scoped_ptr( |
| 672 new GetEntryInfoWithFilePathResult(DRIVE_FILE_ERROR_NO_SPACE)); |
| 673 } |
| 674 |
638 scoped_ptr<DriveEntryProto> entry = | 675 scoped_ptr<DriveEntryProto> entry = |
639 storage_->GetEntry(entry_proto.resource_id()); | 676 storage_->GetEntry(entry_proto.resource_id()); |
640 if (!entry) { | 677 if (!entry) { |
641 return make_scoped_ptr( | 678 return make_scoped_ptr( |
642 new GetEntryInfoWithFilePathResult(DRIVE_FILE_ERROR_NOT_FOUND)); | 679 new GetEntryInfoWithFilePathResult(DRIVE_FILE_ERROR_NOT_FOUND)); |
643 } | 680 } |
644 | 681 |
645 if (entry->parent_resource_id().empty() || // Rejct root. | 682 if (entry->parent_resource_id().empty() || // Rejct root. |
646 entry->file_info().is_directory() != // Reject incompatible input. | 683 entry->file_info().is_directory() != // Reject incompatible input. |
647 entry_proto.file_info().is_directory()) { | 684 entry_proto.file_info().is_directory()) { |
(...skipping 23 matching lines...) Expand all Loading... |
671 result_entry_proto.Pass())); | 708 result_entry_proto.Pass())); |
672 } | 709 } |
673 | 710 |
674 DriveResourceMetadata::FileMoveResult | 711 DriveResourceMetadata::FileMoveResult |
675 DriveResourceMetadata::RefreshDirectoryOnBlockingPool( | 712 DriveResourceMetadata::RefreshDirectoryOnBlockingPool( |
676 const DirectoryFetchInfo& directory_fetch_info, | 713 const DirectoryFetchInfo& directory_fetch_info, |
677 const DriveEntryProtoMap& entry_proto_map) { | 714 const DriveEntryProtoMap& entry_proto_map) { |
678 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 715 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
679 DCHECK(!directory_fetch_info.empty()); | 716 DCHECK(!directory_fetch_info.empty()); |
680 | 717 |
| 718 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) |
| 719 return FileMoveResult(DRIVE_FILE_ERROR_NO_SPACE); |
| 720 |
681 scoped_ptr<DriveEntryProto> directory = storage_->GetEntry( | 721 scoped_ptr<DriveEntryProto> directory = storage_->GetEntry( |
682 directory_fetch_info.resource_id()); | 722 directory_fetch_info.resource_id()); |
683 | 723 |
684 if (!directory) | 724 if (!directory) |
685 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); | 725 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); |
686 | 726 |
687 if (!directory->file_info().is_directory()) | 727 if (!directory->file_info().is_directory()) |
688 return FileMoveResult(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); | 728 return FileMoveResult(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
689 | 729 |
690 directory->mutable_directory_specific_info()->set_changestamp( | 730 directory->mutable_directory_specific_info()->set_changestamp( |
691 directory_fetch_info.changestamp()); | 731 directory_fetch_info.changestamp()); |
692 storage_->PutEntry(*directory); | 732 storage_->PutEntry(*directory); |
693 | 733 |
694 // First, go through the entry map. We'll handle existing entries and new | 734 // First, go through the entry map. We'll handle existing entries and new |
695 // entries in the loop. We'll process deleted entries afterwards. | 735 // entries in the loop. We'll process deleted entries afterwards. |
696 for (DriveEntryProtoMap::const_iterator it = entry_proto_map.begin(); | 736 for (DriveEntryProtoMap::const_iterator it = entry_proto_map.begin(); |
697 it != entry_proto_map.end(); ++it) { | 737 it != entry_proto_map.end(); ++it) { |
| 738 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) |
| 739 return FileMoveResult(DRIVE_FILE_ERROR_NO_SPACE); |
| 740 |
698 const DriveEntryProto& entry_proto = it->second; | 741 const DriveEntryProto& entry_proto = it->second; |
699 // Skip if the parent resource ID does not match. This is needed to | 742 // Skip if the parent resource ID does not match. This is needed to |
700 // handle entries with multiple parents. For such entries, the first | 743 // handle entries with multiple parents. For such entries, the first |
701 // parent is picked and other parents are ignored, hence some entries may | 744 // parent is picked and other parents are ignored, hence some entries may |
702 // have a parent resource ID which does not match the target directory's. | 745 // have a parent resource ID which does not match the target directory's. |
703 // | 746 // |
704 // TODO(satorux): Move the filtering logic to somewhere more appropriate. | 747 // TODO(satorux): Move the filtering logic to somewhere more appropriate. |
705 // crbug.com/193525. | 748 // crbug.com/193525. |
706 if (entry_proto.parent_resource_id() != | 749 if (entry_proto.parent_resource_id() != |
707 directory_fetch_info.resource_id()) { | 750 directory_fetch_info.resource_id()) { |
708 DVLOG(1) << "Wrong-parent entry rejected: " << entry_proto.resource_id(); | 751 DVLOG(1) << "Wrong-parent entry rejected: " << entry_proto.resource_id(); |
709 continue; | 752 continue; |
710 } | 753 } |
711 | 754 |
712 scoped_ptr<DriveEntryProto> existing_entry = | 755 scoped_ptr<DriveEntryProto> existing_entry = |
713 storage_->GetEntry(entry_proto.resource_id()); | 756 storage_->GetEntry(entry_proto.resource_id()); |
714 if (existing_entry) | 757 if (existing_entry) |
715 DetachEntryFromDirectory(entry_proto.resource_id()); | 758 DetachEntryFromDirectory(entry_proto.resource_id()); |
716 | 759 |
717 AddEntryToDirectory(CreateEntryWithProperBaseName(entry_proto)); | 760 AddEntryToDirectory(CreateEntryWithProperBaseName(entry_proto)); |
718 } | 761 } |
719 | 762 |
720 // Go through the existing entries and remove deleted entries. | 763 // Go through the existing entries and remove deleted entries. |
721 scoped_ptr<DriveEntryProtoVector> entries = | 764 scoped_ptr<DriveEntryProtoVector> entries = |
722 DirectoryChildrenToProtoVector(directory->resource_id()); | 765 DirectoryChildrenToProtoVector(directory->resource_id()); |
723 for (size_t i = 0; i < entries->size(); ++i) { | 766 for (size_t i = 0; i < entries->size(); ++i) { |
| 767 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) |
| 768 return FileMoveResult(DRIVE_FILE_ERROR_NO_SPACE); |
| 769 |
724 const DriveEntryProto& entry_proto = entries->at(i); | 770 const DriveEntryProto& entry_proto = entries->at(i); |
725 if (entry_proto_map.count(entry_proto.resource_id()) == 0) | 771 if (entry_proto_map.count(entry_proto.resource_id()) == 0) |
726 RemoveDirectoryChild(entry_proto.resource_id()); | 772 RemoveDirectoryChild(entry_proto.resource_id()); |
727 } | 773 } |
728 | 774 |
729 return FileMoveResult(DRIVE_FILE_OK, GetFilePath(directory->resource_id())); | 775 return FileMoveResult(DRIVE_FILE_OK, GetFilePath(directory->resource_id())); |
730 } | 776 } |
731 | 777 |
732 DriveResourceMetadata::FileMoveResult | 778 DriveResourceMetadata::FileMoveResult |
733 DriveResourceMetadata::AddEntryOnBlockingPool( | 779 DriveResourceMetadata::AddEntryOnBlockingPool( |
734 const DriveEntryProto& entry_proto) { | 780 const DriveEntryProto& entry_proto) { |
735 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 781 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
736 | 782 |
| 783 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) |
| 784 return FileMoveResult(DRIVE_FILE_ERROR_NO_SPACE); |
| 785 |
737 scoped_ptr<DriveEntryProto> existing_entry = | 786 scoped_ptr<DriveEntryProto> existing_entry = |
738 storage_->GetEntry(entry_proto.resource_id()); | 787 storage_->GetEntry(entry_proto.resource_id()); |
739 if (existing_entry) | 788 if (existing_entry) |
740 return FileMoveResult(DRIVE_FILE_ERROR_EXISTS); | 789 return FileMoveResult(DRIVE_FILE_ERROR_EXISTS); |
741 | 790 |
742 scoped_ptr<DriveEntryProto> parent = | 791 scoped_ptr<DriveEntryProto> parent = |
743 GetDirectory(entry_proto.parent_resource_id()); | 792 GetDirectory(entry_proto.parent_resource_id()); |
744 if (!parent) | 793 if (!parent) |
745 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); | 794 return FileMoveResult(DRIVE_FILE_ERROR_NOT_FOUND); |
746 | 795 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 if (entry->file_info().is_directory()) { | 847 if (entry->file_info().is_directory()) { |
799 child_directories->insert(GetFilePath(entry->resource_id())); | 848 child_directories->insert(GetFilePath(entry->resource_id())); |
800 GetDescendantDirectoryPaths(entry->resource_id(), child_directories); | 849 GetDescendantDirectoryPaths(entry->resource_id(), child_directories); |
801 } | 850 } |
802 } | 851 } |
803 } | 852 } |
804 | 853 |
805 void DriveResourceMetadata::RemoveAllOnBlockingPool() { | 854 void DriveResourceMetadata::RemoveAllOnBlockingPool() { |
806 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 855 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
807 | 856 |
| 857 // TODO(hashimoto): Return DRIVE_FILE_ERROR_NO_SPACE here. |
| 858 if (!EnoughDiskSpaceIsAvailableForDBOperation(data_directory_path_)) { |
| 859 LOG(ERROR) << "Required disk space not available."; |
| 860 return; |
| 861 } |
| 862 |
808 RemoveDirectoryChildren(util::kDriveGrandRootSpecialResourceId); | 863 RemoveDirectoryChildren(util::kDriveGrandRootSpecialResourceId); |
809 SetUpDefaultEntries(); | 864 SetUpDefaultEntries(); |
810 } | 865 } |
811 | 866 |
812 void DriveResourceMetadata::IterateEntriesOnBlockingPool( | 867 void DriveResourceMetadata::IterateEntriesOnBlockingPool( |
813 const IterateCallback& callback) { | 868 const IterateCallback& callback) { |
814 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 869 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
815 DCHECK(!callback.is_null()); | 870 DCHECK(!callback.is_null()); |
816 | 871 |
817 storage_->Iterate(callback); | 872 storage_->Iterate(callback); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 storage_->GetChildren(directory_resource_id, &children); | 999 storage_->GetChildren(directory_resource_id, &children); |
945 for (size_t i = 0; i < children.size(); ++i) { | 1000 for (size_t i = 0; i < children.size(); ++i) { |
946 scoped_ptr<DriveEntryProto> child = storage_->GetEntry(children[i]); | 1001 scoped_ptr<DriveEntryProto> child = storage_->GetEntry(children[i]); |
947 DCHECK(child); | 1002 DCHECK(child); |
948 entries->push_back(*child); | 1003 entries->push_back(*child); |
949 } | 1004 } |
950 return entries.Pass(); | 1005 return entries.Pass(); |
951 } | 1006 } |
952 | 1007 |
953 } // namespace drive | 1008 } // namespace drive |
OLD | NEW |