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 |
538 | |
539 // GDataFileSystem class implementatsion. | 537 // GDataFileSystem class implementatsion. |
540 | 538 |
541 GDataFileSystem::GDataFileSystem(Profile* profile, | 539 GDataFileSystem::GDataFileSystem(Profile* profile, |
542 DocumentsServiceInterface* documents_service) | 540 DocumentsServiceInterface* documents_service) |
543 : profile_(profile), | 541 : profile_(profile), |
544 documents_service_(documents_service), | 542 documents_service_(documents_service), |
545 gdata_uploader_(new GDataUploader(ALLOW_THIS_IN_INITIALIZER_LIST(this))), | 543 gdata_uploader_(new GDataUploader(ALLOW_THIS_IN_INITIALIZER_LIST(this))), |
546 gdata_download_observer_(new GDataDownloadObserver()), | 544 gdata_download_observer_(new GDataDownloadObserver()), |
547 cache_initialized_(false), | 545 cache_initialized_(false), |
548 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 546 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 void GDataFileSystem::RefreshDirectoryAndContinueSearch( | 599 void GDataFileSystem::RefreshDirectoryAndContinueSearch( |
602 const FindFileParams& params) { | 600 const FindFileParams& params) { |
603 scoped_ptr<base::ListValue> feed_list(new base::ListValue()); | 601 scoped_ptr<base::ListValue> feed_list(new base::ListValue()); |
604 // Kick off document feed fetching here if we don't have complete data | 602 // Kick off document feed fetching here if we don't have complete data |
605 // to finish this call. | 603 // to finish this call. |
606 // |feed_list| will contain the list of all collected feed updates that | 604 // |feed_list| will contain the list of all collected feed updates that |
607 // we will receive through calls of DocumentsService::GetDocuments(). | 605 // we will receive through calls of DocumentsService::GetDocuments(). |
608 ContinueDirectoryRefresh(params, feed_list.Pass()); | 606 ContinueDirectoryRefresh(params, feed_list.Pass()); |
609 } | 607 } |
610 | 608 |
| 609 void GDataFileSystem::Copy(const FilePath& src_file_path, |
| 610 const FilePath& dest_file_path, |
| 611 const FileOperationCallback& callback) { |
| 612 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 613 FilePath dest_parent_path = dest_file_path.DirName(); |
| 614 |
| 615 base::AutoLock lock(lock_); |
| 616 GDataFileBase* src_file = GetGDataFileInfoFromPath(src_file_path); |
| 617 GDataFileBase* dest_parent = GetGDataFileInfoFromPath(dest_parent_path); |
| 618 if (!src_file || !dest_parent) { |
| 619 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 620 } else { |
| 621 // TODO(benchan): Implement copy for regular files and directories. |
| 622 // To copy a regular file, we need to first download the file and |
| 623 // then upload it, which is not yet implemented. Also, in the interim, |
| 624 // we handle recursive directory copy in the file manager. |
| 625 if (!src_file->AsGDataFile() || |
| 626 !src_file->AsGDataFile()->is_hosted_document()) { |
| 627 error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 628 } else if (!dest_parent->AsGDataDirectory()) { |
| 629 error = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 630 } |
| 631 } |
| 632 |
| 633 if (error != base::PLATFORM_FILE_OK) { |
| 634 if (!callback.is_null()) |
| 635 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error)); |
| 636 |
| 637 return; |
| 638 } |
| 639 |
| 640 FilePathUpdateCallback add_file_to_directory_callback = |
| 641 base::Bind(&GDataFileSystem::AddFileToDirectory, |
| 642 weak_ptr_factory_.GetWeakPtr(), |
| 643 dest_parent_path, |
| 644 callback); |
| 645 |
| 646 documents_service_->CopyDocument( |
| 647 src_file->self_url(), |
| 648 // Drop the document extension, which should not be in the document title. |
| 649 dest_file_path.BaseName().RemoveExtension().value(), |
| 650 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted, |
| 651 weak_ptr_factory_.GetWeakPtr(), |
| 652 add_file_to_directory_callback)); |
| 653 } |
| 654 |
| 655 void GDataFileSystem::Rename(const FilePath& file_path, |
| 656 const FilePath::StringType& new_name, |
| 657 const FilePathUpdateCallback& callback) { |
| 658 // It is a no-op if the file is renamed to the same name. |
| 659 if (file_path.BaseName().value() == new_name) { |
| 660 if (!callback.is_null()) { |
| 661 MessageLoop::current()->PostTask( |
| 662 FROM_HERE, base::Bind(callback, base::PLATFORM_FILE_OK, file_path)); |
| 663 } |
| 664 return; |
| 665 } |
| 666 |
| 667 base::AutoLock lock(lock_); |
| 668 GDataFileBase* file = GetGDataFileInfoFromPath(file_path); |
| 669 if (!file) { |
| 670 if (!callback.is_null()) { |
| 671 MessageLoop::current()->PostTask(FROM_HERE, |
| 672 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND, file_path)); |
| 673 } |
| 674 return; |
| 675 } |
| 676 |
| 677 // Drop the .g<something> extension from |new_name| if the file being |
| 678 // renamed is a hosted document and |new_name| has the same .g<something> |
| 679 // extension as the file. |
| 680 FilePath::StringType file_name = new_name; |
| 681 if (file->AsGDataFile() && file->AsGDataFile()->is_hosted_document()) { |
| 682 FilePath new_file(file_name); |
| 683 if (new_file.Extension() == file->AsGDataFile()->document_extension()) { |
| 684 file_name = new_file.RemoveExtension().value(); |
| 685 } |
| 686 } |
| 687 |
| 688 documents_service_->RenameResource( |
| 689 file->self_url(), |
| 690 file_name, |
| 691 base::Bind(&GDataFileSystem::OnRenameResourceCompleted, |
| 692 weak_ptr_factory_.GetWeakPtr(), |
| 693 file_path, |
| 694 file_name, |
| 695 callback)); |
| 696 } |
| 697 |
| 698 void GDataFileSystem::Move(const FilePath& src_file_path, |
| 699 const FilePath& dest_file_path, |
| 700 const FileOperationCallback& callback) { |
| 701 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 702 FilePath dest_parent_path = dest_file_path.DirName(); |
| 703 |
| 704 { |
| 705 // This scoped lock needs to be released before calling Rename() below. |
| 706 base::AutoLock lock(lock_); |
| 707 GDataFileBase* src_file = GetGDataFileInfoFromPath(src_file_path); |
| 708 GDataFileBase* dest_parent = GetGDataFileInfoFromPath(dest_parent_path); |
| 709 if (!src_file || !dest_parent) { |
| 710 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 711 } else { |
| 712 if (!dest_parent->AsGDataDirectory()) |
| 713 error = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 714 } |
| 715 |
| 716 if (error != base::PLATFORM_FILE_OK) { |
| 717 if (!callback.is_null()) { |
| 718 MessageLoop::current()->PostTask(FROM_HERE, |
| 719 base::Bind(callback, error)); |
| 720 } |
| 721 return; |
| 722 } |
| 723 } |
| 724 |
| 725 // If the file/directory is moved to the same directory, just rename it. |
| 726 if (src_file_path.DirName() == dest_parent_path) { |
| 727 FilePathUpdateCallback final_file_path_update_callback = |
| 728 base::Bind(&GDataFileSystem::OnFilePathUpdated, |
| 729 weak_ptr_factory_.GetWeakPtr(), |
| 730 callback); |
| 731 |
| 732 Rename(src_file_path, dest_file_path.BaseName().value(), |
| 733 final_file_path_update_callback); |
| 734 return; |
| 735 } |
| 736 |
| 737 // Otherwise, the move operation involves three steps: |
| 738 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) |
| 739 // within the same directory. The rename operation is a no-op if |
| 740 // basename(|src_file_path|) equals to basename(|dest_file_path|). |
| 741 // 2. Removes the file from its parent directory (the file is not deleted), |
| 742 // which effectively moves the file to the root directory. |
| 743 // 3. Adds the file to the parent directory of |dest_file_path|, which |
| 744 // effectively moves the file from the root directory to the parent |
| 745 // directory of |dest_file_path|. |
| 746 FilePathUpdateCallback add_file_to_directory_callback = |
| 747 base::Bind(&GDataFileSystem::AddFileToDirectory, |
| 748 weak_ptr_factory_.GetWeakPtr(), |
| 749 dest_file_path.DirName(), |
| 750 callback); |
| 751 |
| 752 FilePathUpdateCallback remove_file_from_directory_callback = |
| 753 base::Bind(&GDataFileSystem::RemoveFileFromDirectory, |
| 754 weak_ptr_factory_.GetWeakPtr(), |
| 755 src_file_path.DirName(), |
| 756 add_file_to_directory_callback); |
| 757 |
| 758 Rename(src_file_path, dest_file_path.BaseName().value(), |
| 759 remove_file_from_directory_callback); |
| 760 } |
| 761 |
| 762 void GDataFileSystem::AddFileToDirectory(const FilePath& dir_path, |
| 763 const FileOperationCallback& callback, |
| 764 base::PlatformFileError error, |
| 765 const FilePath& file_path) { |
| 766 base::AutoLock lock(lock_); |
| 767 GDataFileBase* file = GetGDataFileInfoFromPath(file_path); |
| 768 GDataFileBase* dir = GetGDataFileInfoFromPath(dir_path); |
| 769 if (error == base::PLATFORM_FILE_OK) { |
| 770 if (!file || !dir) { |
| 771 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 772 } else { |
| 773 if (!dir->AsGDataDirectory()) |
| 774 error = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 775 } |
| 776 } |
| 777 |
| 778 // Returns if there is an error or |dir_path| is the root directory. |
| 779 if (error != base::PLATFORM_FILE_OK || dir->AsGDataRootDirectory()) { |
| 780 if (!callback.is_null()) |
| 781 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error)); |
| 782 |
| 783 return; |
| 784 } |
| 785 |
| 786 documents_service_->AddResourceToDirectory( |
| 787 dir->content_url(), |
| 788 file->self_url(), |
| 789 base::Bind(&GDataFileSystem::OnAddFileToDirectoryCompleted, |
| 790 weak_ptr_factory_.GetWeakPtr(), |
| 791 callback, |
| 792 file_path, |
| 793 dir_path)); |
| 794 } |
| 795 |
| 796 void GDataFileSystem::RemoveFileFromDirectory( |
| 797 const FilePath& dir_path, |
| 798 const FilePathUpdateCallback& callback, |
| 799 base::PlatformFileError error, |
| 800 const FilePath& file_path) { |
| 801 base::AutoLock lock(lock_); |
| 802 GDataFileBase* file = GetGDataFileInfoFromPath(file_path); |
| 803 GDataFileBase* dir = GetGDataFileInfoFromPath(dir_path); |
| 804 if (error == base::PLATFORM_FILE_OK) { |
| 805 if (!file || !dir) { |
| 806 error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 807 } else { |
| 808 if (!dir->AsGDataDirectory()) |
| 809 error = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 810 } |
| 811 } |
| 812 |
| 813 // Returns if there is an error or |dir_path| is the root directory. |
| 814 if (error != base::PLATFORM_FILE_OK || dir->AsGDataRootDirectory()) { |
| 815 if (!callback.is_null()) { |
| 816 MessageLoop::current()->PostTask(FROM_HERE, |
| 817 base::Bind(callback, error, file_path)); |
| 818 } |
| 819 return; |
| 820 } |
| 821 |
| 822 documents_service_->RemoveResourceFromDirectory( |
| 823 dir->content_url(), |
| 824 file->self_url(), |
| 825 file->resource_id(), |
| 826 base::Bind(&GDataFileSystem::OnRemoveFileFromDirectoryCompleted, |
| 827 weak_ptr_factory_.GetWeakPtr(), |
| 828 callback, |
| 829 file_path, |
| 830 dir_path)); |
| 831 } |
| 832 |
611 void GDataFileSystem::Remove(const FilePath& file_path, | 833 void GDataFileSystem::Remove(const FilePath& file_path, |
612 bool is_recursive, | 834 bool is_recursive, |
613 const FileOperationCallback& callback) { | 835 const FileOperationCallback& callback) { |
614 base::AutoLock lock(lock_); | 836 base::AutoLock lock(lock_); |
615 GDataFileBase* file_info = GetGDataFileInfoFromPath(file_path); | 837 GDataFileBase* file_info = GetGDataFileInfoFromPath(file_path); |
616 if (!file_info) { | 838 if (!file_info) { |
617 if (!callback.is_null()) { | 839 if (!callback.is_null()) { |
618 MessageLoop::current()->PostTask( | 840 MessageLoop::current()->PostTask( |
619 FROM_HERE, | 841 FROM_HERE, |
620 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); | 842 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 | 1214 |
993 // If this was the root feed, cache its content. | 1215 // If this was the root feed, cache its content. |
994 if (params.directory_path == FilePath(kGDataRootDirectory)) | 1216 if (params.directory_path == FilePath(kGDataRootDirectory)) |
995 SaveRootFeeds(feed_list.Pass()); | 1217 SaveRootFeeds(feed_list.Pass()); |
996 | 1218 |
997 // Continue file content search operation. | 1219 // Continue file content search operation. |
998 FindFileByPath(params.file_path, | 1220 FindFileByPath(params.file_path, |
999 params.delegate); | 1221 params.delegate); |
1000 } | 1222 } |
1001 | 1223 |
| 1224 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, |
| 1225 base::PlatformFileError error, |
| 1226 const FilePath& file_path) { |
| 1227 if (!callback.is_null()) |
| 1228 callback.Run(error); |
| 1229 } |
| 1230 |
| 1231 void GDataFileSystem::OnRenameResourceCompleted( |
| 1232 const FilePath& file_path, |
| 1233 const FilePath::StringType& new_name, |
| 1234 const FilePathUpdateCallback& callback, |
| 1235 GDataErrorCode status, |
| 1236 const GURL& document_url) { |
| 1237 FilePath updated_file_path; |
| 1238 base::PlatformFileError error = GDataToPlatformError(status); |
| 1239 if (error == base::PLATFORM_FILE_OK) |
| 1240 error = RenameFileOnFilesystem(file_path, new_name, &updated_file_path); |
| 1241 |
| 1242 if (!callback.is_null()) |
| 1243 callback.Run(error, updated_file_path); |
| 1244 } |
| 1245 |
| 1246 void GDataFileSystem::OnCopyDocumentCompleted( |
| 1247 const FilePathUpdateCallback& callback, |
| 1248 GDataErrorCode status, |
| 1249 scoped_ptr<base::Value> data) { |
| 1250 base::PlatformFileError error = GDataToPlatformError(status); |
| 1251 if (error != base::PLATFORM_FILE_OK) { |
| 1252 if (!callback.is_null()) |
| 1253 callback.Run(error, FilePath()); |
| 1254 |
| 1255 return; |
| 1256 } |
| 1257 |
| 1258 base::DictionaryValue* dict_value = NULL; |
| 1259 base::Value* entry_value = NULL; |
| 1260 if (data.get() && data->GetAsDictionary(&dict_value) && dict_value) |
| 1261 dict_value->Get("entry", &entry_value); |
| 1262 |
| 1263 if (!entry_value) { |
| 1264 if (!callback.is_null()) |
| 1265 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, FilePath()); |
| 1266 |
| 1267 return; |
| 1268 } |
| 1269 |
| 1270 scoped_ptr<DocumentEntry> entry(DocumentEntry::CreateFrom(entry_value)); |
| 1271 if (!entry.get()) { |
| 1272 if (!callback.is_null()) |
| 1273 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, FilePath()); |
| 1274 |
| 1275 return; |
| 1276 } |
| 1277 |
| 1278 FilePath file_path; |
| 1279 { |
| 1280 base::AutoLock lock(lock_); |
| 1281 GDataFileBase* file = |
| 1282 GDataFileBase::FromDocumentEntry(root_.get(), entry.get()); |
| 1283 if (!file) { |
| 1284 if (!callback.is_null()) |
| 1285 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, FilePath()); |
| 1286 |
| 1287 return; |
| 1288 } |
| 1289 root_->AddFile(file); |
| 1290 file_path = file->GetFilePath(); |
| 1291 } |
| 1292 |
| 1293 if (!callback.is_null()) |
| 1294 callback.Run(error, file_path); |
| 1295 } |
| 1296 |
| 1297 void GDataFileSystem::OnAddFileToDirectoryCompleted( |
| 1298 const FileOperationCallback& callback, |
| 1299 const FilePath& file_path, |
| 1300 const FilePath& dir_path, |
| 1301 GDataErrorCode status, |
| 1302 const GURL& document_url) { |
| 1303 base::PlatformFileError error = GDataToPlatformError(status); |
| 1304 if (error == base::PLATFORM_FILE_OK) |
| 1305 error = AddFileToDirectoryOnFilesystem(file_path, dir_path); |
| 1306 |
| 1307 if (!callback.is_null()) |
| 1308 callback.Run(error); |
| 1309 } |
| 1310 |
| 1311 void GDataFileSystem::OnRemoveFileFromDirectoryCompleted( |
| 1312 const FilePathUpdateCallback& callback, |
| 1313 const FilePath& file_path, |
| 1314 const FilePath& dir_path, |
| 1315 GDataErrorCode status, |
| 1316 const GURL& document_url) { |
| 1317 FilePath updated_file_path = file_path; |
| 1318 base::PlatformFileError error = GDataToPlatformError(status); |
| 1319 if (error == base::PLATFORM_FILE_OK) |
| 1320 error = RemoveFileFromDirectoryOnFilesystem(file_path, dir_path, |
| 1321 &updated_file_path); |
| 1322 |
| 1323 if (!callback.is_null()) |
| 1324 callback.Run(error, updated_file_path); |
| 1325 } |
| 1326 |
1002 void GDataFileSystem::SaveRootFeeds(scoped_ptr<base::ListValue> feed_vector) { | 1327 void GDataFileSystem::SaveRootFeeds(scoped_ptr<base::ListValue> feed_vector) { |
1003 BrowserThread::PostBlockingPoolTask(FROM_HERE, | 1328 BrowserThread::PostBlockingPoolTask(FROM_HERE, |
1004 base::Bind(&GDataFileSystem::SaveRootFeedsOnIOThreadPool, | 1329 base::Bind(&GDataFileSystem::SaveRootFeedsOnIOThreadPool, |
1005 cache_paths_[CACHE_TYPE_META], | 1330 cache_paths_[CACHE_TYPE_META], |
1006 base::Passed(&feed_vector))); | 1331 base::Passed(&feed_vector))); |
1007 } | 1332 } |
1008 | 1333 |
1009 // Static. | 1334 // Static. |
1010 void GDataFileSystem::SaveRootFeedsOnIOThreadPool( | 1335 void GDataFileSystem::SaveRootFeedsOnIOThreadPool( |
1011 const FilePath& meta_cache_path, | 1336 const FilePath& meta_cache_path, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 GDataErrorCode status, | 1381 GDataErrorCode status, |
1057 const GURL& content_url, | 1382 const GURL& content_url, |
1058 const FilePath& file_path) { | 1383 const FilePath& file_path) { |
1059 base::PlatformFileError error = GDataToPlatformError(status); | 1384 base::PlatformFileError error = GDataToPlatformError(status); |
1060 | 1385 |
1061 if (!callback.is_null()) { | 1386 if (!callback.is_null()) { |
1062 callback.Run(error, file_path); | 1387 callback.Run(error, file_path); |
1063 } | 1388 } |
1064 } | 1389 } |
1065 | 1390 |
| 1391 base::PlatformFileError GDataFileSystem::RenameFileOnFilesystem( |
| 1392 const FilePath& file_path, |
| 1393 const FilePath::StringType& new_name, |
| 1394 FilePath* updated_file_path) { |
| 1395 DCHECK(updated_file_path); |
| 1396 |
| 1397 base::AutoLock lock(lock_); |
| 1398 |
| 1399 scoped_refptr<ReadOnlyFindFileDelegate> find_file_delegate( |
| 1400 new ReadOnlyFindFileDelegate()); |
| 1401 UnsafeFindFileByPath(file_path, find_file_delegate); |
| 1402 |
| 1403 GDataFileBase* file = find_file_delegate->file(); |
| 1404 if (!file) |
| 1405 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1406 |
| 1407 DCHECK(file->parent()); |
| 1408 file->set_title(new_name); |
| 1409 // After changing the title of the file, call TakeFile() to remove the |
| 1410 // file from its parent directory and then add it back in order to go |
| 1411 // through the file name de-duplication. |
| 1412 if (!file->parent()->TakeFile(file)) |
| 1413 return base::PLATFORM_FILE_ERROR_FAILED; |
| 1414 |
| 1415 *updated_file_path = file->GetFilePath(); |
| 1416 return base::PLATFORM_FILE_OK; |
| 1417 } |
| 1418 |
| 1419 base::PlatformFileError GDataFileSystem::AddFileToDirectoryOnFilesystem( |
| 1420 const FilePath& file_path, const FilePath& dir_path) { |
| 1421 base::AutoLock lock(lock_); |
| 1422 |
| 1423 scoped_refptr<ReadOnlyFindFileDelegate> find_file_delegate( |
| 1424 new ReadOnlyFindFileDelegate()); |
| 1425 UnsafeFindFileByPath(file_path, find_file_delegate); |
| 1426 |
| 1427 GDataFileBase* file = find_file_delegate->file(); |
| 1428 if (!file) |
| 1429 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1430 |
| 1431 DCHECK_EQ(root_.get(), file->parent()); |
| 1432 |
| 1433 scoped_refptr<ReadOnlyFindFileDelegate> find_dir_delegate( |
| 1434 new ReadOnlyFindFileDelegate()); |
| 1435 UnsafeFindFileByPath(dir_path, find_dir_delegate); |
| 1436 GDataFileBase* dir = find_dir_delegate->file(); |
| 1437 if (!dir) |
| 1438 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1439 |
| 1440 if (!dir->AsGDataDirectory()) |
| 1441 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 1442 |
| 1443 if (!dir->AsGDataDirectory()->TakeFile(file)) |
| 1444 return base::PLATFORM_FILE_ERROR_FAILED; |
| 1445 |
| 1446 return base::PLATFORM_FILE_OK; |
| 1447 } |
| 1448 |
| 1449 base::PlatformFileError GDataFileSystem::RemoveFileFromDirectoryOnFilesystem( |
| 1450 const FilePath& file_path, const FilePath& dir_path, |
| 1451 FilePath* updated_file_path) { |
| 1452 DCHECK(updated_file_path); |
| 1453 |
| 1454 base::AutoLock lock(lock_); |
| 1455 |
| 1456 scoped_refptr<ReadOnlyFindFileDelegate> find_file_delegate( |
| 1457 new ReadOnlyFindFileDelegate()); |
| 1458 UnsafeFindFileByPath(file_path, find_file_delegate); |
| 1459 |
| 1460 GDataFileBase* file = find_file_delegate->file(); |
| 1461 if (!file) |
| 1462 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1463 |
| 1464 scoped_refptr<ReadOnlyFindFileDelegate> find_dir_delegate( |
| 1465 new ReadOnlyFindFileDelegate()); |
| 1466 UnsafeFindFileByPath(dir_path, find_dir_delegate); |
| 1467 GDataFileBase* dir = find_dir_delegate->file(); |
| 1468 if (!dir) |
| 1469 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1470 |
| 1471 if (!dir->AsGDataDirectory()) |
| 1472 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 1473 |
| 1474 DCHECK_EQ(dir->AsGDataDirectory(), file->parent()); |
| 1475 |
| 1476 if (!root_->TakeFile(file)) |
| 1477 return base::PLATFORM_FILE_ERROR_FAILED; |
| 1478 |
| 1479 *updated_file_path = file->GetFilePath(); |
| 1480 return base::PLATFORM_FILE_OK; |
| 1481 } |
| 1482 |
1066 base::PlatformFileError GDataFileSystem::RemoveFileFromFileSystem( | 1483 base::PlatformFileError GDataFileSystem::RemoveFileFromFileSystem( |
1067 const FilePath& file_path) { | 1484 const FilePath& file_path) { |
1068 // We need to lock here as well (despite FindFileByPath lock) since directory | 1485 // We need to lock here as well (despite FindFileByPath lock) since directory |
1069 // instance below is a 'live' object. | 1486 // instance below is a 'live' object. |
1070 base::AutoLock lock(lock_); | 1487 base::AutoLock lock(lock_); |
1071 | 1488 |
1072 // Find directory element within the cached file system snapshot. | 1489 // Find directory element within the cached file system snapshot. |
1073 scoped_refptr<ReadOnlyFindFileDelegate> update_delegate( | 1490 scoped_refptr<ReadOnlyFindFileDelegate> update_delegate( |
1074 new ReadOnlyFindFileDelegate()); | 1491 new ReadOnlyFindFileDelegate()); |
1075 UnsafeFindFileByPath(file_path, update_delegate); | 1492 UnsafeFindFileByPath(file_path, update_delegate); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 | 1915 |
1499 GDataFileSystemFactory::~GDataFileSystemFactory() { | 1916 GDataFileSystemFactory::~GDataFileSystemFactory() { |
1500 } | 1917 } |
1501 | 1918 |
1502 ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor( | 1919 ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor( |
1503 Profile* profile) const { | 1920 Profile* profile) const { |
1504 return new GDataFileSystem(profile, new DocumentsService); | 1921 return new GDataFileSystem(profile, new DocumentsService); |
1505 } | 1922 } |
1506 | 1923 |
1507 } // namespace gdata | 1924 } // namespace gdata |
OLD | NEW |