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/extensions/api/file_system/file_system_api.h" | 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 } | 499 } |
500 | 500 |
501 file_path = path_util::PrettifyPath(file_path); | 501 file_path = path_util::PrettifyPath(file_path); |
502 return RespondNow( | 502 return RespondNow( |
503 OneArgument(base::MakeUnique<base::Value>(file_path.value()))); | 503 OneArgument(base::MakeUnique<base::Value>(file_path.value()))); |
504 } | 504 } |
505 | 505 |
506 FileSystemEntryFunction::FileSystemEntryFunction() | 506 FileSystemEntryFunction::FileSystemEntryFunction() |
507 : multiple_(false), is_directory_(false) {} | 507 : multiple_(false), is_directory_(false) {} |
508 | 508 |
509 FileSystemEntryFunction::~FileSystemEntryFunction() {} | |
510 | |
509 void FileSystemEntryFunction::PrepareFilesForWritableApp( | 511 void FileSystemEntryFunction::PrepareFilesForWritableApp( |
510 const std::vector<base::FilePath>& paths) { | 512 const std::vector<base::FilePath>& paths) { |
511 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 513 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
512 // TODO(cmihail): Path directory set should be initialized only with the | 514 // TODO(cmihail): Path directory set should be initialized only with the |
513 // paths that are actually directories, but for now we will consider | 515 // paths that are actually directories, but for now we will consider |
514 // all paths directories in case is_directory_ is true, otherwise | 516 // all paths directories in case is_directory_ is true, otherwise |
515 // all paths files, as this was the previous logic. | 517 // all paths files, as this was the previous logic. |
516 std::set<base::FilePath> path_directory_set_ = | 518 std::set<base::FilePath> path_directory_set_ = |
517 is_directory_ ? std::set<base::FilePath>(paths.begin(), paths.end()) | 519 is_directory_ ? std::set<base::FilePath>(paths.begin(), paths.end()) |
518 : std::set<base::FilePath>{}; | 520 : std::set<base::FilePath>{}; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 if (!app_file_handler_util::HasFileSystemWritePermission(extension_.get())) { | 586 if (!app_file_handler_util::HasFileSystemWritePermission(extension_.get())) { |
585 error_ = kRequiresFileSystemWriteError; | 587 error_ = kRequiresFileSystemWriteError; |
586 return false; | 588 return false; |
587 } | 589 } |
588 | 590 |
589 if (!app_file_handler_util::ValidateFileEntryAndGetPath( | 591 if (!app_file_handler_util::ValidateFileEntryAndGetPath( |
590 filesystem_name, filesystem_path, | 592 filesystem_name, filesystem_path, |
591 render_frame_host()->GetProcess()->GetID(), &path_, &error_)) | 593 render_frame_host()->GetProcess()->GetID(), &path_, &error_)) |
592 return false; | 594 return false; |
593 | 595 |
594 content::BrowserThread::PostTaskAndReply( | 596 task_runner_->PostTaskAndReply( |
fdoray
2017/05/16 15:23:26
Unless RunAsync() is invoked multiple times on the
Sébastien Marchand
2017/05/16 15:53:09
SGTM, I'll check with the owner to make sure that
| |
595 content::BrowserThread::FILE, FROM_HERE, | 597 FROM_HERE, |
596 base::BindOnce( | 598 base::BindOnce( |
597 &FileSystemGetWritableEntryFunction::SetIsDirectoryOnFileThread, | 599 &FileSystemGetWritableEntryFunction::SetIsDirectoryOnFileThread, |
fdoray
2017/05/16 15:23:26
s/OnFileThread/Async/
Sébastien Marchand
2017/05/16 15:53:09
Done.
| |
598 this), | 600 this), |
599 base::BindOnce( | 601 base::BindOnce( |
600 &FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse, | 602 &FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse, |
601 this)); | 603 this)); |
602 return true; | 604 return true; |
603 } | 605 } |
604 | 606 |
605 void FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse() { | 607 void FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse() { |
606 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 608 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
607 if (is_directory_ && | 609 if (is_directory_ && |
608 !extension_->permissions_data()->HasAPIPermission( | 610 !extension_->permissions_data()->HasAPIPermission( |
609 APIPermission::kFileSystemDirectory)) { | 611 APIPermission::kFileSystemDirectory)) { |
610 error_ = kRequiresFileSystemDirectoryError; | 612 error_ = kRequiresFileSystemDirectoryError; |
611 SendResponse(false); | 613 SendResponse(false); |
612 } | 614 } |
613 std::vector<base::FilePath> paths; | 615 std::vector<base::FilePath> paths; |
614 paths.push_back(path_); | 616 paths.push_back(path_); |
615 PrepareFilesForWritableApp(paths); | 617 PrepareFilesForWritableApp(paths); |
616 } | 618 } |
617 | 619 |
618 void FileSystemGetWritableEntryFunction::SetIsDirectoryOnFileThread() { | 620 void FileSystemGetWritableEntryFunction::SetIsDirectoryOnFileThread() { |
619 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 621 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
620 if (base::DirectoryExists(path_)) { | 622 if (base::DirectoryExists(path_)) { |
621 is_directory_ = true; | 623 is_directory_ = true; |
622 } | 624 } |
623 } | 625 } |
624 | 626 |
625 ExtensionFunction::ResponseAction FileSystemIsWritableEntryFunction::Run() { | 627 ExtensionFunction::ResponseAction FileSystemIsWritableEntryFunction::Run() { |
626 std::string filesystem_name; | 628 std::string filesystem_name; |
627 std::string filesystem_path; | 629 std::string filesystem_path; |
628 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); | 630 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
629 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); | 631 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 return; | 873 return; |
872 } | 874 } |
873 | 875 |
874 DCHECK_EQ(paths.size(), 1u); | 876 DCHECK_EQ(paths.size(), 1u); |
875 bool non_native_path = false; | 877 bool non_native_path = false; |
876 #if defined(OS_CHROMEOS) | 878 #if defined(OS_CHROMEOS) |
877 non_native_path = | 879 non_native_path = |
878 file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), paths[0]); | 880 file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), paths[0]); |
879 #endif | 881 #endif |
880 | 882 |
881 content::BrowserThread::PostTask( | 883 task_runner_->PostTask( |
fdoray
2017/05/16 15:23:26
ditto (a sequence may not be required)
Sébastien Marchand
2017/05/16 15:53:09
Done.
| |
882 content::BrowserThread::FILE, FROM_HERE, | 884 FROM_HERE, |
883 base::BindOnce( | 885 base::BindOnce( |
884 &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread, | 886 &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread, |
885 this, non_native_path, paths, web_contents)); | 887 this, non_native_path, paths, web_contents)); |
886 return; | 888 return; |
887 } | 889 } |
888 | 890 |
889 OnDirectoryAccessConfirmed(paths); | 891 OnDirectoryAccessConfirmed(paths); |
890 } | 892 } |
891 | 893 |
892 void FileSystemChooseEntryFunction::FileSelectionCanceled() { | 894 void FileSystemChooseEntryFunction::FileSelectionCanceled() { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 | 1109 |
1108 // Check whether the |previous_path| is a non-native directory. | 1110 // Check whether the |previous_path| is a non-native directory. |
1109 #if defined(OS_CHROMEOS) | 1111 #if defined(OS_CHROMEOS) |
1110 if (file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), | 1112 if (file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), |
1111 previous_path)) { | 1113 previous_path)) { |
1112 file_manager::util::IsNonNativeLocalPathDirectory( | 1114 file_manager::util::IsNonNativeLocalPathDirectory( |
1113 GetProfile(), previous_path, set_initial_path_callback); | 1115 GetProfile(), previous_path, set_initial_path_callback); |
1114 return true; | 1116 return true; |
1115 } | 1117 } |
1116 #endif | 1118 #endif |
1117 content::BrowserThread::PostTaskAndReplyWithResult( | 1119 base::PostTaskAndReplyWithResult( |
1118 content::BrowserThread::FILE, FROM_HERE, | 1120 task_runner_.get(), FROM_HERE, |
1119 base::Bind(&base::DirectoryExists, previous_path), | 1121 base::Bind(&base::DirectoryExists, previous_path), |
1120 set_initial_path_callback); | 1122 set_initial_path_callback); |
1121 | 1123 |
1122 return true; | 1124 return true; |
1123 } | 1125 } |
1124 | 1126 |
1125 bool FileSystemRetainEntryFunction::RunAsync() { | 1127 bool FileSystemRetainEntryFunction::RunAsync() { |
1126 std::string entry_id; | 1128 std::string entry_id; |
1127 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); | 1129 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); |
1128 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); | 1130 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1433 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); | 1435 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); |
1434 std::vector<api::file_system::Volume> result_volume_list; | 1436 std::vector<api::file_system::Volume> result_volume_list; |
1435 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); | 1437 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); |
1436 | 1438 |
1437 return RespondNow(ArgumentList( | 1439 return RespondNow(ArgumentList( |
1438 api::file_system::GetVolumeList::Results::Create(result_volume_list))); | 1440 api::file_system::GetVolumeList::Results::Create(result_volume_list))); |
1439 } | 1441 } |
1440 #endif | 1442 #endif |
1441 | 1443 |
1442 } // namespace extensions | 1444 } // namespace extensions |
OLD | NEW |