| 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/gdata/gdata_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 base::PLATFORM_FILE_OK)); | 451 base::PLATFORM_FILE_OK)); |
| 452 } | 452 } |
| 453 | 453 |
| 454 return; | 454 return; |
| 455 } | 455 } |
| 456 case FOUND_MISSING: { | 456 case FOUND_MISSING: { |
| 457 // There is a missing folder to be created here, move on with the rest of | 457 // There is a missing folder to be created here, move on with the rest of |
| 458 // this function. | 458 // this function. |
| 459 break; | 459 break; |
| 460 } | 460 } |
| 461 default: { |
| 462 NOTREACHED(); |
| 463 break; |
| 464 } |
| 461 } | 465 } |
| 462 | 466 |
| 463 // Do we have a parent directory here as well? We can't then create target | 467 // Do we have a parent directory here as well? We can't then create target |
| 464 // directory if this is not a recursive operation. | 468 // directory if this is not a recursive operation. |
| 465 if (directory_path != first_missing_path && !is_recursive) { | 469 if (directory_path != first_missing_path && !is_recursive) { |
| 466 if (!callback.is_null()) { | 470 if (!callback.is_null()) { |
| 467 reply_proxy->PostTask(FROM_HERE, | 471 reply_proxy->PostTask(FROM_HERE, |
| 468 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); | 472 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); |
| 469 } | 473 } |
| 470 return; | 474 return; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 if (error != base::PLATFORM_FILE_OK) { | 571 if (error != base::PLATFORM_FILE_OK) { |
| 568 if (!params.callback.is_null()) | 572 if (!params.callback.is_null()) |
| 569 params.proxy->PostTask(FROM_HERE, base::Bind(params.callback, error)); | 573 params.proxy->PostTask(FROM_HERE, base::Bind(params.callback, error)); |
| 570 | 574 |
| 571 return; | 575 return; |
| 572 } | 576 } |
| 573 | 577 |
| 574 // Not done yet with recursive directory creation? | 578 // Not done yet with recursive directory creation? |
| 575 if (params.target_directory_path != params.created_directory_path && | 579 if (params.target_directory_path != params.created_directory_path && |
| 576 params.is_recursive) { | 580 params.is_recursive) { |
| 577 CreateDirectory(params.target_directory_path, | 581 CreateDirectoryInternal(params.target_directory_path, |
| 578 params.is_exclusive, | 582 params.is_exclusive, |
| 579 params.is_recursive, | 583 params.is_recursive, |
| 580 params.callback); | 584 params.callback, |
| 585 params.proxy); |
| 581 return; | 586 return; |
| 582 } | 587 } |
| 583 | 588 |
| 584 if (!params.callback.is_null()) { | 589 if (!params.callback.is_null()) { |
| 585 // Finally done with the create request. | 590 // Finally done with the create request. |
| 586 params.proxy->PostTask(FROM_HERE, base::Bind(params.callback, | 591 params.proxy->PostTask(FROM_HERE, base::Bind(params.callback, |
| 587 base::PLATFORM_FILE_OK)); | 592 base::PLATFORM_FILE_OK)); |
| 588 } | 593 } |
| 589 } | 594 } |
| 590 | 595 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 continue; | 739 continue; |
| 735 } | 740 } |
| 736 | 741 |
| 737 GDataFileBase* file = GDataFileBase::FromDocumentEntry(dir, doc); | 742 GDataFileBase* file = GDataFileBase::FromDocumentEntry(dir, doc); |
| 738 if (file) | 743 if (file) |
| 739 dir->AddFile(file); | 744 dir->AddFile(file); |
| 740 } | 745 } |
| 741 return base::PLATFORM_FILE_OK; | 746 return base::PLATFORM_FILE_OK; |
| 742 } | 747 } |
| 743 | 748 |
| 744 | |
| 745 base::PlatformFileError GDataFileSystem::AddNewDirectory( | 749 base::PlatformFileError GDataFileSystem::AddNewDirectory( |
| 746 const FilePath& directory_path, base::Value* entry_value) { | 750 const FilePath& directory_path, base::Value* entry_value) { |
| 747 if (!entry_value) | 751 if (!entry_value) |
| 748 return base::PLATFORM_FILE_ERROR_FAILED; | 752 return base::PLATFORM_FILE_ERROR_FAILED; |
| 749 | 753 |
| 750 scoped_ptr<DocumentEntry> entry(DocumentEntry::CreateFrom(entry_value)); | 754 scoped_ptr<DocumentEntry> entry(DocumentEntry::CreateFrom(entry_value)); |
| 751 | 755 |
| 752 if (!entry.get()) | 756 if (!entry.get()) |
| 753 return base::PLATFORM_FILE_ERROR_FAILED; | 757 return base::PLATFORM_FILE_ERROR_FAILED; |
| 754 | 758 |
| 755 // We need to lock here as well (despite FindFileByPath lock) since directory | 759 // We need to lock here as well (despite FindFileByPath lock) since directory |
| 756 // instance below is a 'live' object. | 760 // instance below is a 'live' object. |
| 757 base::AutoLock lock(lock_); | 761 base::AutoLock lock(lock_); |
| 758 | 762 |
| 759 // Find parent directory element within the cached file system snapshot. | 763 // Find parent directory element within the cached file system snapshot. |
| 760 scoped_refptr<ReadOnlyFindFileDelegate> update_delegate( | 764 scoped_refptr<ReadOnlyFindFileDelegate> update_delegate( |
| 761 new ReadOnlyFindFileDelegate()); | 765 new ReadOnlyFindFileDelegate()); |
| 762 UnsafeFindFileByPath(directory_path.DirName(), update_delegate); | 766 UnsafeFindFileByPath(directory_path.DirName(), update_delegate); |
| 763 | 767 |
| 764 GDataFileBase* file = update_delegate->file(); | 768 GDataFileBase* file = update_delegate->file(); |
| 765 if (!file) | 769 if (!file) |
| 766 return base::PLATFORM_FILE_ERROR_FAILED; | 770 return base::PLATFORM_FILE_ERROR_FAILED; |
| 767 | 771 |
| 772 // Check if parent is a directory since in theory since this is a callback |
| 773 // something could in the meantime have nuked the parent dir and created a |
| 774 // file with the exact same name. |
| 768 GDataDirectory* parent_dir = file->AsGDataDirectory(); | 775 GDataDirectory* parent_dir = file->AsGDataDirectory(); |
| 769 if (!parent_dir) | 776 if (!parent_dir) |
| 770 return base::PLATFORM_FILE_ERROR_FAILED; | 777 return base::PLATFORM_FILE_ERROR_FAILED; |
| 771 | 778 |
| 772 GDataFileBase* new_file = GDataFileBase::FromDocumentEntry(parent_dir, | 779 GDataFileBase* new_file = GDataFileBase::FromDocumentEntry(parent_dir, |
| 773 entry.get()); | 780 entry.get()); |
| 774 if (!new_file) | 781 if (!new_file) |
| 775 return base::PLATFORM_FILE_ERROR_FAILED; | 782 return base::PLATFORM_FILE_ERROR_FAILED; |
| 776 | 783 |
| 777 parent_dir->AddFile(new_file); | 784 parent_dir->AddFile(new_file); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 | 840 |
| 834 GDataFileSystemFactory::~GDataFileSystemFactory() { | 841 GDataFileSystemFactory::~GDataFileSystemFactory() { |
| 835 } | 842 } |
| 836 | 843 |
| 837 ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor( | 844 ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor( |
| 838 Profile* profile) const { | 845 Profile* profile) const { |
| 839 return new GDataFileSystem(profile); | 846 return new GDataFileSystem(profile); |
| 840 } | 847 } |
| 841 | 848 |
| 842 } // namespace gdata | 849 } // namespace gdata |
| OLD | NEW |