Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 2877343003: Switch browser/extensions/api/file_system/file_system_api.[h|cc] to the TaskScheduler API (Closed)
Patch Set: Address Francois' comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/api/file_system/file_system_api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "apps/saved_files_service.h" 14 #include "apps/saved_files_service.h"
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/path_service.h" 21 #include "base/path_service.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/strings/sys_string_conversions.h" 24 #include "base/strings/sys_string_conversions.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
26 #include "base/task_scheduler/post_task.h"
26 #include "base/value_conversions.h" 27 #include "base/value_conversions.h"
27 #include "base/values.h" 28 #include "base/values.h"
28 #include "build/build_config.h" 29 #include "build/build_config.h"
29 #include "chrome/browser/extensions/extension_service.h" 30 #include "chrome/browser/extensions/extension_service.h"
30 #include "chrome/browser/extensions/extension_util.h" 31 #include "chrome/browser/extensions/extension_util.h"
31 #include "chrome/browser/extensions/path_util.h" 32 #include "chrome/browser/extensions/path_util.h"
32 #include "chrome/browser/platform_util.h" 33 #include "chrome/browser/platform_util.h"
33 #include "chrome/browser/profiles/profile.h" 34 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/ui/apps/directory_access_confirmation_dialog.h" 35 #include "chrome/browser/ui/apps/directory_access_confirmation_dialog.h"
35 #include "chrome/browser/ui/chrome_select_file_policy.h" 36 #include "chrome/browser/ui/chrome_select_file_policy.h"
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 if (!app_file_handler_util::HasFileSystemWritePermission(extension_.get())) { 585 if (!app_file_handler_util::HasFileSystemWritePermission(extension_.get())) {
585 error_ = kRequiresFileSystemWriteError; 586 error_ = kRequiresFileSystemWriteError;
586 return false; 587 return false;
587 } 588 }
588 589
589 if (!app_file_handler_util::ValidateFileEntryAndGetPath( 590 if (!app_file_handler_util::ValidateFileEntryAndGetPath(
590 filesystem_name, filesystem_path, 591 filesystem_name, filesystem_path,
591 render_frame_host()->GetProcess()->GetID(), &path_, &error_)) 592 render_frame_host()->GetProcess()->GetID(), &path_, &error_))
592 return false; 593 return false;
593 594
594 content::BrowserThread::PostTaskAndReply( 595 base::PostTaskWithTraitsAndReply(
595 content::BrowserThread::FILE, FROM_HERE, 596 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
596 base::BindOnce( 597 base::BindOnce(&FileSystemGetWritableEntryFunction::SetIsDirectoryAsync,
597 &FileSystemGetWritableEntryFunction::SetIsDirectoryOnFileThread, 598 this),
598 this),
599 base::BindOnce( 599 base::BindOnce(
600 &FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse, 600 &FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse,
601 this)); 601 this));
602 return true; 602 return true;
603 } 603 }
604 604
605 void FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse() { 605 void FileSystemGetWritableEntryFunction::CheckPermissionAndSendResponse() {
606 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 606 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
607 if (is_directory_ && 607 if (is_directory_ &&
608 !extension_->permissions_data()->HasAPIPermission( 608 !extension_->permissions_data()->HasAPIPermission(
609 APIPermission::kFileSystemDirectory)) { 609 APIPermission::kFileSystemDirectory)) {
610 error_ = kRequiresFileSystemDirectoryError; 610 error_ = kRequiresFileSystemDirectoryError;
611 SendResponse(false); 611 SendResponse(false);
612 } 612 }
613 std::vector<base::FilePath> paths; 613 std::vector<base::FilePath> paths;
614 paths.push_back(path_); 614 paths.push_back(path_);
615 PrepareFilesForWritableApp(paths); 615 PrepareFilesForWritableApp(paths);
616 } 616 }
617 617
618 void FileSystemGetWritableEntryFunction::SetIsDirectoryOnFileThread() { 618 void FileSystemGetWritableEntryFunction::SetIsDirectoryAsync() {
619 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
620 if (base::DirectoryExists(path_)) { 619 if (base::DirectoryExists(path_)) {
621 is_directory_ = true; 620 is_directory_ = true;
622 } 621 }
623 } 622 }
624 623
625 ExtensionFunction::ResponseAction FileSystemIsWritableEntryFunction::Run() { 624 ExtensionFunction::ResponseAction FileSystemIsWritableEntryFunction::Run() {
626 std::string filesystem_name; 625 std::string filesystem_name;
627 std::string filesystem_path; 626 std::string filesystem_path;
628 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); 627 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name));
629 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); 628 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path));
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 return; 870 return;
872 } 871 }
873 872
874 DCHECK_EQ(paths.size(), 1u); 873 DCHECK_EQ(paths.size(), 1u);
875 bool non_native_path = false; 874 bool non_native_path = false;
876 #if defined(OS_CHROMEOS) 875 #if defined(OS_CHROMEOS)
877 non_native_path = 876 non_native_path =
878 file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), paths[0]); 877 file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), paths[0]);
879 #endif 878 #endif
880 879
881 content::BrowserThread::PostTask( 880 base::PostTaskWithTraits(
882 content::BrowserThread::FILE, FROM_HERE, 881 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
883 base::BindOnce( 882 base::BindOnce(
884 &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread, 883 &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread,
benwells 2017/05/17 01:03:52 Could you rename ConfirmDirectoryAccessOnFileThrea
Sébastien Marchand 2017/05/17 18:43:00 Done.
885 this, non_native_path, paths, web_contents)); 884 this, non_native_path, paths, web_contents));
886 return; 885 return;
887 } 886 }
888 887
889 OnDirectoryAccessConfirmed(paths); 888 OnDirectoryAccessConfirmed(paths);
890 } 889 }
891 890
892 void FileSystemChooseEntryFunction::FileSelectionCanceled() { 891 void FileSystemChooseEntryFunction::FileSelectionCanceled() {
893 error_ = kUserCancelled; 892 error_ = kUserCancelled;
894 SendResponse(false); 893 SendResponse(false);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 1106
1108 // Check whether the |previous_path| is a non-native directory. 1107 // Check whether the |previous_path| is a non-native directory.
1109 #if defined(OS_CHROMEOS) 1108 #if defined(OS_CHROMEOS)
1110 if (file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), 1109 if (file_manager::util::IsUnderNonNativeLocalPath(GetProfile(),
1111 previous_path)) { 1110 previous_path)) {
1112 file_manager::util::IsNonNativeLocalPathDirectory( 1111 file_manager::util::IsNonNativeLocalPathDirectory(
1113 GetProfile(), previous_path, set_initial_path_callback); 1112 GetProfile(), previous_path, set_initial_path_callback);
1114 return true; 1113 return true;
1115 } 1114 }
1116 #endif 1115 #endif
1117 content::BrowserThread::PostTaskAndReplyWithResult( 1116 base::PostTaskWithTraitsAndReplyWithResult(
1118 content::BrowserThread::FILE, FROM_HERE, 1117 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
1119 base::Bind(&base::DirectoryExists, previous_path), 1118 base::Bind(&base::DirectoryExists, previous_path),
1120 set_initial_path_callback); 1119 set_initial_path_callback);
1121 1120
1122 return true; 1121 return true;
1123 } 1122 }
1124 1123
1125 bool FileSystemRetainEntryFunction::RunAsync() { 1124 bool FileSystemRetainEntryFunction::RunAsync() {
1126 std::string entry_id; 1125 std::string entry_id;
1127 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); 1126 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id));
1128 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); 1127 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile());
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); 1432 return RespondNow(Error(kNotSupportedOnNonKioskSessionError));
1434 std::vector<api::file_system::Volume> result_volume_list; 1433 std::vector<api::file_system::Volume> result_volume_list;
1435 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); 1434 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list);
1436 1435
1437 return RespondNow(ArgumentList( 1436 return RespondNow(ArgumentList(
1438 api::file_system::GetVolumeList::Results::Create(result_volume_list))); 1437 api::file_system::GetVolumeList::Results::Create(result_volume_list)));
1439 } 1438 }
1440 #endif 1439 #endif
1441 1440
1442 } // namespace extensions 1441 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/file_system/file_system_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698