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 <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/profiles/profile.h" | |
18 #include "chrome/browser/profiles/profile_dependency_manager.h" | |
19 #include "chrome/browser/chromeos/gdata/gdata.h" | 17 #include "chrome/browser/chromeos/gdata/gdata.h" |
20 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" | 18 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" |
21 #include "chrome/browser/chromeos/gdata/gdata_parser.h" | 19 #include "chrome/browser/chromeos/gdata/gdata_parser.h" |
20 #include "chrome/browser/download/download_service.h" | |
21 #include "chrome/browser/download/download_service_factory.h" | |
22 #include "chrome/browser/profiles/profile.h" | |
23 #include "chrome/browser/profiles/profile_dependency_manager.h" | |
22 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
23 #include "chrome/common/chrome_paths_internal.h" | 25 #include "chrome/common/chrome_paths_internal.h" |
24 #include "chrome/browser/download/download_service.h" | |
25 #include "chrome/browser/download/download_service_factory.h" | |
26 #include "chrome/browser/profiles/profile_dependency_manager.h" | |
27 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
28 #include "webkit/fileapi/file_system_file_util_proxy.h" | 27 #include "webkit/fileapi/file_system_file_util_proxy.h" |
29 #include "webkit/fileapi/file_system_types.h" | 28 #include "webkit/fileapi/file_system_types.h" |
30 #include "webkit/fileapi/file_system_util.h" | 29 #include "webkit/fileapi/file_system_util.h" |
31 | 30 |
32 using content::BrowserThread; | 31 using content::BrowserThread; |
33 | 32 |
34 namespace { | 33 namespace { |
35 | 34 |
36 const char kGDataRootDirectory[] = "gdata"; | 35 const char kGDataRootDirectory[] = "gdata"; |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 : created_directory_path(created_directory_path), | 527 : created_directory_path(created_directory_path), |
529 target_directory_path(target_directory_path), | 528 target_directory_path(target_directory_path), |
530 is_exclusive(is_exclusive), | 529 is_exclusive(is_exclusive), |
531 is_recursive(is_recursive), | 530 is_recursive(is_recursive), |
532 callback(callback) { | 531 callback(callback) { |
533 } | 532 } |
534 | 533 |
535 GDataFileSystem::CreateDirectoryParams::~CreateDirectoryParams() { | 534 GDataFileSystem::CreateDirectoryParams::~CreateDirectoryParams() { |
536 } | 535 } |
537 | 536 |
537 // GDataFileSystem::CopyMoveFileParams struct implementation. | |
538 | |
539 GDataFileSystem::CopyMoveFileParams::CopyMoveFileParams() | |
540 : is_directory(false), | |
541 is_root_directory(false), | |
542 is_hosted_document(false) { | |
543 } | |
544 | |
545 GDataFileSystem::CopyMoveFileParams::~CopyMoveFileParams() { | |
546 } | |
538 | 547 |
539 // GDataFileSystem class implementatsion. | 548 // GDataFileSystem class implementatsion. |
540 | 549 |
541 GDataFileSystem::GDataFileSystem(Profile* profile, | 550 GDataFileSystem::GDataFileSystem(Profile* profile, |
542 DocumentsServiceInterface* documents_service) | 551 DocumentsServiceInterface* documents_service) |
543 : profile_(profile), | 552 : profile_(profile), |
544 documents_service_(documents_service), | 553 documents_service_(documents_service), |
545 gdata_uploader_(new GDataUploader(ALLOW_THIS_IN_INITIALIZER_LIST(this))), | 554 gdata_uploader_(new GDataUploader(ALLOW_THIS_IN_INITIALIZER_LIST(this))), |
546 gdata_download_observer_(new GDataDownloadObserver()), | 555 gdata_download_observer_(new GDataDownloadObserver()), |
547 cache_initialized_(false), | 556 cache_initialized_(false), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 void GDataFileSystem::RefreshDirectoryAndContinueSearch( | 610 void GDataFileSystem::RefreshDirectoryAndContinueSearch( |
602 const FindFileParams& params) { | 611 const FindFileParams& params) { |
603 scoped_ptr<base::ListValue> feed_list(new base::ListValue()); | 612 scoped_ptr<base::ListValue> feed_list(new base::ListValue()); |
604 // Kick off document feed fetching here if we don't have complete data | 613 // Kick off document feed fetching here if we don't have complete data |
605 // to finish this call. | 614 // to finish this call. |
606 // |feed_list| will contain the list of all collected feed updates that | 615 // |feed_list| will contain the list of all collected feed updates that |
607 // we will receive through calls of DocumentsService::GetDocuments(). | 616 // we will receive through calls of DocumentsService::GetDocuments(). |
608 ContinueDirectoryRefresh(params, feed_list.Pass()); | 617 ContinueDirectoryRefresh(params, feed_list.Pass()); |
609 } | 618 } |
610 | 619 |
620 bool GDataFileSystem::GetCopyMoveFileParams(const FilePath& path, | |
621 CopyMoveFileParams* params) { | |
622 DCHECK(params); | |
623 | |
624 scoped_refptr<ReadOnlyFindFileDelegate> delegate( | |
625 new ReadOnlyFindFileDelegate()); | |
626 | |
627 base::AutoLock lock(lock_); | |
628 | |
629 UnsafeFindFileByPath(path, delegate); | |
630 GDataFileBase* file = delegate->file(); | |
631 if (!file) | |
632 return false; | |
zel
2012/03/12 20:40:40
there is a helper method GetGDataFileInfoFromPath(
Ben Chan
2012/03/13 02:16:36
Done.
| |
633 | |
634 params->resource_id = file->resource(); | |
635 params->self_url = file->self_url(); | |
636 params->content_url = file->content_url(); | |
637 params->is_directory = file->AsGDataDirectory(); | |
638 params->is_root_directory = file->AsGDataRootDirectory(); | |
639 | |
640 GDataFile* gdata_file = file->AsGDataFile(); | |
641 if (gdata_file) { | |
642 params->is_hosted_document = gdata_file->is_hosted_document(); | |
643 params->document_extension = gdata_file->document_extension(); | |
644 } | |
645 | |
646 return true; | |
647 } | |
648 | |
649 void GDataFileSystem::Copy(const FilePath& src_file_path, | |
650 const FilePath& dest_file_path, | |
651 const FileOperationCallback& callback) { | |
652 base::PlatformFileError error = base::PLATFORM_FILE_OK; | |
653 FilePath dest_parent_path = dest_file_path.DirName(); | |
654 CopyMoveFileParams src_file_params, dest_parent_params; | |
655 if (!GetCopyMoveFileParams(src_file_path, &src_file_params) || | |
656 !GetCopyMoveFileParams(dest_parent_path, &dest_parent_params)) { | |
657 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
658 } else { | |
659 // TODO(benchan): Implement copy for regular files and directories. | |
satorux1
2012/03/12 17:48:24
Please document this in the header file too. :) Pl
Ben Chan
2012/03/13 00:29:21
Clarified in the header. I'll keep the bug open un
| |
660 // In the interim, We handle regular file and directory copy in the | |
661 // file manager. | |
satorux1
2012/03/12 17:48:24
How does this work?
Ben Chan
2012/03/13 00:29:21
The file manager recursively traverses the directo
satorux1
2012/03/13 01:12:17
thanks.
| |
662 if (!src_file_params.is_hosted_document) { | |
663 error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | |
664 } else if (!dest_parent_params.is_directory) { | |
665 error = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | |
666 } | |
667 } | |
668 | |
669 if (error != base::PLATFORM_FILE_OK) { | |
670 if (!callback.is_null()) { | |
671 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error)); | |
672 } | |
673 return; | |
674 } | |
675 | |
676 FilePathUpdateCallback add_file_to_directory_callback = | |
677 base::Bind(&GDataFileSystem::AddFileToDirectory, | |
678 weak_ptr_factory_.GetWeakPtr(), | |
679 dest_parent_path, | |
680 callback); | |
satorux1
2012/03/12 17:48:24
Shouldn't we pass MessageLoopProxy::current() so |
Ben Chan
2012/03/13 00:29:21
IIUC, the DocumentsService layer handles the trans
satorux1
2012/03/13 01:12:17
Oh you are right. forget about my comments.
| |
681 | |
682 documents_service_->CopyDocument( | |
683 src_file_params.self_url, | |
684 // Drop the document extension, which should not be in the document title. | |
685 dest_file_path.BaseName().RemoveExtension().value(), | |
686 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted, | |
687 weak_ptr_factory_.GetWeakPtr(), | |
688 add_file_to_directory_callback)); | |
689 } | |
690 | |
691 void GDataFileSystem::Rename(const FilePath& file_path, | |
692 const FilePath::StringType& new_name, | |
693 const FilePathUpdateCallback& callback) { | |
694 // It is a no-op if the file is renamed to the same name. | |
695 if (file_path.BaseName().value() == new_name) { | |
696 if (!callback.is_null()) { | |
697 MessageLoop::current()->PostTask( | |
698 FROM_HERE, base::Bind(callback, base::PLATFORM_FILE_OK, file_path)); | |
699 } | |
700 return; | |
701 } | |
702 | |
703 CopyMoveFileParams file_params; | |
704 if (!GetCopyMoveFileParams(file_path, &file_params)) { | |
705 if (!callback.is_null()) { | |
706 MessageLoop::current()->PostTask(FROM_HERE, | |
707 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND, file_path)); | |
708 } | |
709 return; | |
710 } | |
711 | |
712 // Drop the .g<something> extension from |new_name| if the file being | |
713 // renamed is a hosted document and |new_name| has the same .g<something> | |
714 // extension as the file. | |
715 std::string file_name = new_name; | |
satorux1
2012/03/12 17:48:24
std::string -> FilePath::StringType
Ben Chan
2012/03/13 00:29:21
Done. Good catch!
| |
716 if (file_params.is_hosted_document) { | |
717 FilePath new_file(file_name); | |
718 if (new_file.Extension() == file_params.document_extension) { | |
719 file_name = new_file.RemoveExtension().value(); | |
720 } | |
721 } | |
722 | |
723 documents_service_->RenameResource( | |
724 file_params.self_url, | |
725 file_name, | |
726 base::Bind(&GDataFileSystem::OnRenameResourceCompleted, | |
727 weak_ptr_factory_.GetWeakPtr(), | |
728 file_path, | |
729 file_name, | |
730 callback)); | |
731 } | |
732 | |
733 void GDataFileSystem::Move(const FilePath& src_file_path, | |
734 const FilePath& dest_file_path, | |
735 const FileOperationCallback& callback) { | |
736 base::PlatformFileError error = base::PLATFORM_FILE_OK; | |
737 FilePath dest_parent_path = dest_file_path.DirName(); | |
738 CopyMoveFileParams src_file_params, dest_parent_params; | |
739 if (!GetCopyMoveFileParams(src_file_path, &src_file_params) || | |
740 !GetCopyMoveFileParams(dest_parent_path, &dest_parent_params)) { | |
741 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
742 } else { | |
743 if (!dest_parent_params.is_directory) { | |
744 error = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | |
745 } | |
746 } | |
747 | |
748 if (error != base::PLATFORM_FILE_OK) { | |
749 if (!callback.is_null()) { | |
750 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error)); | |
751 } | |
752 return; | |
753 } | |
754 | |
755 if (src_file_path.DirName() == dest_parent_path) { | |
satorux1
2012/03/12 17:48:24
Having a comment would make it a bit easier to rea
Ben Chan
2012/03/13 00:29:21
Done.
| |
756 FilePathUpdateCallback final_file_path_update_callback = | |
757 base::Bind(&GDataFileSystem::OnFilePathUpdated, | |
758 weak_ptr_factory_.GetWeakPtr(), | |
759 callback); | |
satorux1
2012/03/12 17:48:24
Shouldn't we pass MessageLoopProxy::current() so t
Ben Chan
2012/03/13 00:29:21
Rename(), AddResourceToDirectory(), and RemoveReso
| |
760 | |
761 Rename(src_file_path, dest_file_path.BaseName().value(), | |
762 final_file_path_update_callback); | |
763 return; | |
764 } | |
765 | |
766 FilePathUpdateCallback add_file_to_directory_callback = | |
satorux1
2012/03/12 17:48:24
This logic is a bit hard to follow. If I follow ri
Ben Chan
2012/03/13 00:29:21
Done. Added more details in comments.
| |
767 base::Bind(&GDataFileSystem::AddFileToDirectory, | |
768 weak_ptr_factory_.GetWeakPtr(), | |
769 dest_file_path.DirName(), | |
770 callback); | |
satorux1
2012/03/12 17:48:24
MessageLoopProxy::current() ?
| |
771 | |
772 FilePathUpdateCallback remove_file_from_directory_callback = | |
773 base::Bind(&GDataFileSystem::RemoveFileFromDirectory, | |
774 weak_ptr_factory_.GetWeakPtr(), | |
775 src_file_path.DirName(), | |
776 add_file_to_directory_callback); | |
777 | |
778 Rename(src_file_path, dest_file_path.BaseName().value(), | |
779 remove_file_from_directory_callback); | |
780 } | |
781 | |
782 void GDataFileSystem::AddFileToDirectory(const FilePath& dir_path, | |
783 const FileOperationCallback& callback, | |
784 base::PlatformFileError error, | |
785 const FilePath& file_path) { | |
786 CopyMoveFileParams file_params, dir_params; | |
787 if (error == base::PLATFORM_FILE_OK) { | |
788 if (!GetCopyMoveFileParams(file_path, &file_params) || | |
789 !GetCopyMoveFileParams(dir_path, &dir_params)) { | |
790 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
791 } else { | |
792 if (!dir_params.is_directory) { | |
zel
2012/03/12 20:40:40
nit: remove {}
Ben Chan
2012/03/13 00:29:21
Done.
| |
793 error = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | |
794 } | |
795 } | |
796 } | |
797 | |
798 // Returns if there is an error or |dir_path| is the root directory. | |
799 if (error != base::PLATFORM_FILE_OK || dir_params.is_root_directory) { | |
800 if (!callback.is_null()) { | |
zel
2012/03/12 20:40:40
nit: remove {}
Ben Chan
2012/03/13 00:29:21
Done.
| |
801 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error)); | |
802 } | |
803 return; | |
804 } | |
805 | |
806 documents_service_->AddResourceToDirectory( | |
807 dir_params.content_url, | |
808 file_params.self_url, | |
809 base::Bind(&GDataFileSystem::OnAddFileToDirectoryCompleted, | |
810 weak_ptr_factory_.GetWeakPtr(), | |
811 callback, | |
812 file_path, | |
813 dir_path)); | |
814 } | |
815 | |
816 void GDataFileSystem::RemoveFileFromDirectory( | |
817 const FilePath& dir_path, | |
818 const FilePathUpdateCallback& callback, | |
819 base::PlatformFileError error, | |
820 const FilePath& file_path) { | |
821 CopyMoveFileParams file_params, dir_params; | |
822 if (error == base::PLATFORM_FILE_OK) { | |
823 if (!GetCopyMoveFileParams(file_path, &file_params) || | |
824 !GetCopyMoveFileParams(dir_path, &dir_params)) { | |
825 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
826 } else { | |
827 if (!dir_params.is_directory) { | |
828 error = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | |
829 } | |
830 } | |
831 } | |
832 | |
833 // Returns if there is an error or |dir_path| is the root directory. | |
834 if (error != base::PLATFORM_FILE_OK || dir_params.is_root_directory) { | |
835 if (!callback.is_null()) { | |
836 MessageLoop::current()->PostTask(FROM_HERE, | |
837 base::Bind(callback, error, file_path)); | |
838 } | |
839 return; | |
840 } | |
841 | |
842 documents_service_->RemoveResourceFromDirectory( | |
843 dir_params.content_url, | |
844 file_params.self_url, | |
845 file_params.resource_id, | |
846 base::Bind(&GDataFileSystem::OnRemoveFileFromDirectoryCompleted, | |
847 weak_ptr_factory_.GetWeakPtr(), | |
848 callback, | |
849 file_path, | |
850 dir_path)); | |
851 } | |
852 | |
611 void GDataFileSystem::Remove(const FilePath& file_path, | 853 void GDataFileSystem::Remove(const FilePath& file_path, |
612 bool is_recursive, | 854 bool is_recursive, |
613 const FileOperationCallback& callback) { | 855 const FileOperationCallback& callback) { |
614 GDataFileBase* file_info = GetGDataFileInfoFromPath(file_path); | 856 GDataFileBase* file_info = GetGDataFileInfoFromPath(file_path); |
615 if (!file_info) { | 857 if (!file_info) { |
616 if (!callback.is_null()) { | 858 if (!callback.is_null()) { |
617 MessageLoop::current()->PostTask( | 859 MessageLoop::current()->PostTask( |
618 FROM_HERE, | 860 FROM_HERE, |
619 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); | 861 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); |
620 } | 862 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
966 | 1208 |
967 // If this was the root feed, cache its content. | 1209 // If this was the root feed, cache its content. |
968 if (params.directory_path == FilePath(kGDataRootDirectory)) | 1210 if (params.directory_path == FilePath(kGDataRootDirectory)) |
969 SaveRootFeeds(feed_list.Pass()); | 1211 SaveRootFeeds(feed_list.Pass()); |
970 | 1212 |
971 // Continue file content search operation. | 1213 // Continue file content search operation. |
972 FindFileByPath(params.file_path, | 1214 FindFileByPath(params.file_path, |
973 params.delegate); | 1215 params.delegate); |
974 } | 1216 } |
975 | 1217 |
1218 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, | |
1219 base::PlatformFileError error, | |
1220 const FilePath& file_path) { | |
1221 if (!callback.is_null()) | |
1222 callback.Run(error); | |
1223 } | |
1224 | |
1225 void GDataFileSystem::OnRenameResourceCompleted( | |
1226 const FilePath& file_path, | |
1227 const FilePath::StringType& new_name, | |
1228 const FilePathUpdateCallback& callback, | |
1229 GDataErrorCode status, | |
1230 const GURL& document_url) { | |
1231 FilePath updated_file_path; | |
1232 base::PlatformFileError error = GDataToPlatformError(status); | |
1233 if (error == base::PLATFORM_FILE_OK) | |
1234 error = RenameFileOnFilesystem(file_path, new_name, &updated_file_path); | |
1235 | |
1236 if (!callback.is_null()) | |
1237 callback.Run(error, updated_file_path); | |
1238 } | |
1239 | |
1240 void GDataFileSystem::OnCopyDocumentCompleted( | |
1241 const FilePathUpdateCallback& callback, | |
1242 GDataErrorCode status, | |
1243 scoped_ptr<base::Value> data) { | |
1244 base::PlatformFileError error = GDataToPlatformError(status); | |
1245 if (error != base::PLATFORM_FILE_OK) { | |
1246 if (!callback.is_null()) | |
1247 callback.Run(error, FilePath()); | |
1248 | |
1249 return; | |
1250 } | |
1251 | |
1252 base::DictionaryValue* dict_value = NULL; | |
1253 base::Value* entry_value = NULL; | |
1254 if (data.get() && data->GetAsDictionary(&dict_value) && dict_value) | |
1255 dict_value->Get("entry", &entry_value); | |
1256 | |
1257 if (!entry_value) { | |
1258 if (!callback.is_null()) { | |
1259 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, FilePath()); | |
1260 } | |
1261 return; | |
1262 } | |
1263 | |
1264 scoped_ptr<DocumentEntry> entry(DocumentEntry::CreateFrom(entry_value)); | |
1265 if (!entry.get()) { | |
1266 if (!callback.is_null()) { | |
1267 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, FilePath()); | |
1268 } | |
1269 return; | |
1270 } | |
1271 | |
1272 FilePath file_path; | |
1273 { | |
1274 base::AutoLock lock(lock_); | |
1275 GDataFileBase* file = | |
1276 GDataFileBase::FromDocumentEntry(root_.get(), entry.get()); | |
1277 if (!file) { | |
1278 if (!callback.is_null()) { | |
1279 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, FilePath()); | |
1280 } | |
1281 return; | |
1282 } | |
1283 root_->AddFile(file); | |
1284 file_path = file->GetFilePath(); | |
1285 } | |
1286 | |
1287 if (!callback.is_null()) { | |
1288 callback.Run(error, file_path); | |
1289 } | |
1290 } | |
1291 | |
1292 void GDataFileSystem::OnAddFileToDirectoryCompleted( | |
1293 const FileOperationCallback& callback, | |
1294 const FilePath& file_path, | |
1295 const FilePath& dir_path, | |
1296 GDataErrorCode status, | |
1297 const GURL& document_url) { | |
1298 base::PlatformFileError error = GDataToPlatformError(status); | |
1299 if (error == base::PLATFORM_FILE_OK) | |
1300 error = AddFileToDirectoryOnFilesystem(file_path, dir_path); | |
1301 | |
1302 if (!callback.is_null()) | |
1303 callback.Run(error); | |
1304 } | |
1305 | |
1306 void GDataFileSystem::OnRemoveFileFromDirectoryCompleted( | |
1307 const FilePathUpdateCallback& callback, | |
1308 const FilePath& file_path, | |
1309 const FilePath& dir_path, | |
1310 GDataErrorCode status, | |
1311 const GURL& document_url) { | |
1312 FilePath updated_file_path = file_path; | |
1313 base::PlatformFileError error = GDataToPlatformError(status); | |
1314 if (error == base::PLATFORM_FILE_OK) | |
1315 error = RemoveFileFromDirectoryOnFilesystem(file_path, dir_path, | |
1316 &updated_file_path); | |
1317 | |
1318 if (!callback.is_null()) | |
1319 callback.Run(error, updated_file_path); | |
1320 } | |
1321 | |
976 void GDataFileSystem::SaveRootFeeds(scoped_ptr<base::ListValue> feed_vector) { | 1322 void GDataFileSystem::SaveRootFeeds(scoped_ptr<base::ListValue> feed_vector) { |
977 BrowserThread::PostBlockingPoolTask(FROM_HERE, | 1323 BrowserThread::PostBlockingPoolTask(FROM_HERE, |
978 base::Bind(&GDataFileSystem::SaveRootFeedsOnIOThreadPool, | 1324 base::Bind(&GDataFileSystem::SaveRootFeedsOnIOThreadPool, |
979 cache_paths_[CACHE_TYPE_META], | 1325 cache_paths_[CACHE_TYPE_META], |
980 base::Passed(&feed_vector))); | 1326 base::Passed(&feed_vector))); |
981 } | 1327 } |
982 | 1328 |
983 // Static. | 1329 // Static. |
984 void GDataFileSystem::SaveRootFeedsOnIOThreadPool( | 1330 void GDataFileSystem::SaveRootFeedsOnIOThreadPool( |
985 const FilePath& meta_cache_path, | 1331 const FilePath& meta_cache_path, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1030 GDataErrorCode status, | 1376 GDataErrorCode status, |
1031 const GURL& content_url, | 1377 const GURL& content_url, |
1032 const FilePath& file_path) { | 1378 const FilePath& file_path) { |
1033 base::PlatformFileError error = GDataToPlatformError(status); | 1379 base::PlatformFileError error = GDataToPlatformError(status); |
1034 | 1380 |
1035 if (!callback.is_null()) { | 1381 if (!callback.is_null()) { |
1036 callback.Run(error, file_path); | 1382 callback.Run(error, file_path); |
1037 } | 1383 } |
1038 } | 1384 } |
1039 | 1385 |
1386 base::PlatformFileError GDataFileSystem::RenameFileOnFilesystem( | |
1387 const FilePath& file_path, | |
1388 const FilePath::StringType& new_name, | |
1389 FilePath* updated_file_path) { | |
1390 DCHECK(updated_file_path); | |
1391 | |
1392 base::AutoLock lock(lock_); | |
1393 | |
1394 scoped_refptr<ReadOnlyFindFileDelegate> find_file_delegate( | |
1395 new ReadOnlyFindFileDelegate()); | |
1396 UnsafeFindFileByPath(file_path, find_file_delegate); | |
1397 | |
1398 GDataFileBase* file = find_file_delegate->file(); | |
1399 if (!file) { | |
1400 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
1401 } | |
1402 | |
1403 DCHECK(file->parent()); | |
1404 file->set_original_file_name(new_name); | |
1405 // After changing the original file name, removing the file from its | |
1406 // parent directory and then adding it back to go through the file name | |
1407 // de-duplication. | |
1408 file->parent()->MoveFile(file, file->parent()); | |
1409 | |
1410 *updated_file_path = file->GetFilePath(); | |
1411 return base::PLATFORM_FILE_OK; | |
1412 } | |
1413 | |
1414 base::PlatformFileError GDataFileSystem::AddFileToDirectoryOnFilesystem( | |
1415 const FilePath& file_path, const FilePath& dir_path) { | |
1416 base::AutoLock lock(lock_); | |
1417 | |
1418 scoped_refptr<ReadOnlyFindFileDelegate> find_file_delegate( | |
1419 new ReadOnlyFindFileDelegate()); | |
1420 UnsafeFindFileByPath(file_path, find_file_delegate); | |
1421 | |
1422 GDataFileBase* file = find_file_delegate->file(); | |
1423 if (!file) { | |
1424 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
1425 } | |
1426 | |
1427 scoped_refptr<ReadOnlyFindFileDelegate> find_dir_delegate( | |
1428 new ReadOnlyFindFileDelegate()); | |
1429 UnsafeFindFileByPath(dir_path, find_dir_delegate); | |
1430 GDataFileBase* dir = find_dir_delegate->file(); | |
1431 if (!dir) { | |
1432 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
1433 } | |
1434 if (!dir->AsGDataDirectory()) { | |
1435 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | |
1436 } | |
1437 | |
1438 DCHECK_EQ(root_.get(), file->parent()); | |
1439 file->parent()->MoveFile(file, dir->AsGDataDirectory()); | |
1440 | |
1441 return base::PLATFORM_FILE_OK; | |
1442 } | |
1443 | |
1444 base::PlatformFileError GDataFileSystem::RemoveFileFromDirectoryOnFilesystem( | |
1445 const FilePath& file_path, const FilePath& dir_path, | |
1446 FilePath* updated_file_path) { | |
1447 DCHECK(updated_file_path); | |
1448 | |
1449 base::AutoLock lock(lock_); | |
1450 | |
1451 scoped_refptr<ReadOnlyFindFileDelegate> find_file_delegate( | |
1452 new ReadOnlyFindFileDelegate()); | |
1453 UnsafeFindFileByPath(file_path, find_file_delegate); | |
1454 | |
1455 GDataFileBase* file = find_file_delegate->file(); | |
1456 if (!file) { | |
1457 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
1458 } | |
1459 | |
1460 scoped_refptr<ReadOnlyFindFileDelegate> find_dir_delegate( | |
1461 new ReadOnlyFindFileDelegate()); | |
1462 UnsafeFindFileByPath(dir_path, find_dir_delegate); | |
1463 GDataFileBase* dir = find_dir_delegate->file(); | |
1464 if (!dir) { | |
1465 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
1466 } | |
1467 if (!dir->AsGDataDirectory()) { | |
1468 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | |
1469 } | |
1470 | |
1471 if (!dir->AsGDataDirectory()->MoveFile(file, root_.get())) | |
1472 return base::PLATFORM_FILE_ERROR_FAILED; | |
1473 | |
1474 *updated_file_path = file->GetFilePath(); | |
1475 return base::PLATFORM_FILE_OK; | |
1476 } | |
1477 | |
1040 base::PlatformFileError GDataFileSystem::RemoveFileFromFileSystem( | 1478 base::PlatformFileError GDataFileSystem::RemoveFileFromFileSystem( |
1041 const FilePath& file_path) { | 1479 const FilePath& file_path) { |
1042 // We need to lock here as well (despite FindFileByPath lock) since directory | 1480 // We need to lock here as well (despite FindFileByPath lock) since directory |
1043 // instance below is a 'live' object. | 1481 // instance below is a 'live' object. |
1044 base::AutoLock lock(lock_); | 1482 base::AutoLock lock(lock_); |
1045 | 1483 |
1046 // Find directory element within the cached file system snapshot. | 1484 // Find directory element within the cached file system snapshot. |
1047 scoped_refptr<ReadOnlyFindFileDelegate> update_delegate( | 1485 scoped_refptr<ReadOnlyFindFileDelegate> update_delegate( |
1048 new ReadOnlyFindFileDelegate()); | 1486 new ReadOnlyFindFileDelegate()); |
1049 UnsafeFindFileByPath(file_path, update_delegate); | 1487 UnsafeFindFileByPath(file_path, update_delegate); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 | 1910 |
1473 GDataFileSystemFactory::~GDataFileSystemFactory() { | 1911 GDataFileSystemFactory::~GDataFileSystemFactory() { |
1474 } | 1912 } |
1475 | 1913 |
1476 ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor( | 1914 ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor( |
1477 Profile* profile) const { | 1915 Profile* profile) const { |
1478 return new GDataFileSystem(profile, new DocumentsService); | 1916 return new GDataFileSystem(profile, new DocumentsService); |
1479 } | 1917 } |
1480 | 1918 |
1481 } // namespace gdata | 1919 } // namespace gdata |
OLD | NEW |