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

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

Issue 2951003002: SavedFilesService interface in //extensions (Closed)
Patch Set: cleanup Created 3 years, 6 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
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_impl.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/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
23 #include "base/strings/sys_string_conversions.h" 23 #include "base/strings/sys_string_conversions.h"
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "base/task_scheduler/post_task.h" 25 #include "base/task_scheduler/post_task.h"
26 #include "base/value_conversions.h" 26 #include "base/value_conversions.h"
27 #include "base/values.h" 27 #include "base/values.h"
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "chrome/browser/platform_util.h" 29 #include "chrome/browser/platform_util.h"
30 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ui/apps/directory_access_confirmation_dialog.h" 31 #include "chrome/browser/ui/apps/directory_access_confirmation_dialog.h"
32 #include "chrome/browser/ui/chrome_select_file_policy.h" 32 #include "chrome/browser/ui/chrome_select_file_policy.h"
33 #include "chrome/common/chrome_paths.h" 33 #include "chrome/common/chrome_paths.h"
34 #include "chrome/common/extensions/api/file_system.h" 34 #include "chrome/common/extensions/api/file_system.h"
35 #include "chrome/grit/generated_resources.h" 35 #include "chrome/grit/generated_resources.h"
36 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/child_process_security_policy.h" 37 #include "content/public/browser/child_process_security_policy.h"
38 #include "content/public/browser/render_frame_host.h" 38 #include "content/public/browser/render_frame_host.h"
39 #include "content/public/browser/render_process_host.h" 39 #include "content/public/browser/render_process_host.h"
40 #include "content/public/browser/storage_partition.h" 40 #include "content/public/browser/storage_partition.h"
41 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
42 #include "extensions/browser/api/file_handlers/app_file_handler_util.h" 42 #include "extensions/browser/api/file_handlers/app_file_handler_util.h"
43 #include "extensions/browser/api/file_system/saved_files_service.h"
43 #include "extensions/browser/app_window/app_window.h" 44 #include "extensions/browser/app_window/app_window.h"
44 #include "extensions/browser/app_window/app_window_registry.h" 45 #include "extensions/browser/app_window/app_window_registry.h"
45 #include "extensions/browser/extension_prefs.h" 46 #include "extensions/browser/extension_prefs.h"
46 #include "extensions/browser/extension_system.h" 47 #include "extensions/browser/extension_system.h"
47 #include "extensions/browser/extension_util.h" 48 #include "extensions/browser/extension_util.h"
48 #include "extensions/browser/granted_file_entry.h" 49 #include "extensions/browser/granted_file_entry.h"
49 #include "extensions/browser/path_util.h" 50 #include "extensions/browser/path_util.h"
50 #include "extensions/common/permissions/api_permission.h" 51 #include "extensions/common/permissions/api_permission.h"
51 #include "extensions/common/permissions/permissions_data.h" 52 #include "extensions/common/permissions/permissions_data.h"
52 #include "net/base/mime_util.h" 53 #include "net/base/mime_util.h"
(...skipping 15 matching lines...) Expand all
68 #if defined(OS_CHROMEOS) 69 #if defined(OS_CHROMEOS)
69 #include "base/strings/string16.h" 70 #include "base/strings/string16.h"
70 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" 71 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
71 #include "chrome/browser/chromeos/file_manager/volume_manager.h" 72 #include "chrome/browser/chromeos/file_manager/volume_manager.h"
72 #include "extensions/browser/event_router.h" 73 #include "extensions/browser/event_router.h"
73 #include "extensions/browser/extension_registry.h" 74 #include "extensions/browser/extension_registry.h"
74 #include "extensions/common/constants.h" 75 #include "extensions/common/constants.h"
75 #include "url/url_constants.h" 76 #include "url/url_constants.h"
76 #endif 77 #endif
77 78
78 using apps::SavedFileEntry; 79 using apps::SavedFilesServiceImpl;
79 using apps::SavedFilesService;
80 using storage::IsolatedContext; 80 using storage::IsolatedContext;
81 81
82 const char kInvalidCallingPage[] = 82 const char kInvalidCallingPage[] =
83 "Invalid calling page. " 83 "Invalid calling page. "
84 "This function can't be called from a background page."; 84 "This function can't be called from a background page.";
85 const char kUserCancelled[] = "User cancelled"; 85 const char kUserCancelled[] = "User cancelled";
86 const char kWritableFileErrorFormat[] = "Error opening %s"; 86 const char kWritableFileErrorFormat[] = "Error opening %s";
87 const char kRequiresFileSystemWriteError[] = 87 const char kRequiresFileSystemWriteError[] =
88 "Operation requires fileSystem.write permission"; 88 "Operation requires fileSystem.write permission";
89 const char kRequiresFileSystemDirectoryError[] = 89 const char kRequiresFileSystemDirectoryError[] =
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, 916 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
917 base::Bind(&base::DirectoryExists, previous_path), 917 base::Bind(&base::DirectoryExists, previous_path),
918 set_initial_path_callback); 918 set_initial_path_callback);
919 919
920 return true; 920 return true;
921 } 921 }
922 922
923 bool FileSystemRetainEntryFunction::RunAsync() { 923 bool FileSystemRetainEntryFunction::RunAsync() {
924 std::string entry_id; 924 std::string entry_id;
925 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); 925 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id));
926 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); 926 SavedFilesServiceImpl* saved_files_service =
927 SavedFilesServiceImpl::Get(GetProfile());
927 // Add the file to the retain list if it is not already on there. 928 // Add the file to the retain list if it is not already on there.
928 if (!saved_files_service->IsRegistered(extension_->id(), entry_id)) { 929 if (!saved_files_service->IsRegistered(extension_->id(), entry_id)) {
929 std::string filesystem_name; 930 std::string filesystem_name;
930 std::string filesystem_path; 931 std::string filesystem_path;
931 base::FilePath path; 932 base::FilePath path;
932 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_name)); 933 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_name));
933 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &filesystem_path)); 934 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &filesystem_path));
934 if (!app_file_handler_util::ValidateFileEntryAndGetPath( 935 if (!app_file_handler_util::ValidateFileEntryAndGetPath(
935 filesystem_name, filesystem_path, 936 filesystem_name, filesystem_path,
936 render_frame_host()->GetProcess()->GetID(), &path, &error_)) { 937 render_frame_host()->GetProcess()->GetID(), &path, &error_)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 973
973 void FileSystemRetainEntryFunction::RetainFileEntry( 974 void FileSystemRetainEntryFunction::RetainFileEntry(
974 const std::string& entry_id, 975 const std::string& entry_id,
975 const base::FilePath& path, 976 const base::FilePath& path,
976 std::unique_ptr<base::File::Info> file_info) { 977 std::unique_ptr<base::File::Info> file_info) {
977 if (!file_info) { 978 if (!file_info) {
978 SendResponse(false); 979 SendResponse(false);
979 return; 980 return;
980 } 981 }
981 982
982 SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); 983 SavedFilesServiceImpl* saved_files_service =
984 SavedFilesServiceImpl::Get(GetProfile());
985
983 saved_files_service->RegisterFileEntry(extension_->id(), entry_id, path, 986 saved_files_service->RegisterFileEntry(extension_->id(), entry_id, path,
984 file_info->is_directory); 987 file_info->is_directory);
985 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id); 988 saved_files_service->EnqueueFileEntry(extension_->id(), entry_id);
986 SendResponse(true); 989 SendResponse(true);
987 } 990 }
988 991
989 ExtensionFunction::ResponseAction FileSystemIsRestorableFunction::Run() { 992 ExtensionFunction::ResponseAction FileSystemIsRestorableFunction::Run() {
990 std::string entry_id; 993 std::string entry_id;
991 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); 994 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id));
992 return RespondNow(OneArgument(base::MakeUnique<base::Value>( 995 return RespondNow(OneArgument(base::MakeUnique<base::Value>(
993 SavedFilesService::Get(Profile::FromBrowserContext(browser_context())) 996 SavedFilesServiceImpl::Get(Profile::FromBrowserContext(browser_context()))
994 ->IsRegistered(extension_->id(), entry_id)))); 997 ->IsRegistered(extension_->id(), entry_id))));
995 } 998 }
996 999
997 bool FileSystemRestoreEntryFunction::RunAsync() { 1000 bool FileSystemRestoreEntryFunction::RunAsync() {
998 std::string entry_id; 1001 std::string entry_id;
999 bool needs_new_entry; 1002 bool needs_new_entry;
1000 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id)); 1003 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &entry_id));
1001 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &needs_new_entry)); 1004 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &needs_new_entry));
1002 const SavedFileEntry* file_entry = 1005 const SavedFilesService::Entry* file_entry =
1003 SavedFilesService::Get(GetProfile()) 1006 SavedFilesServiceImpl::Get(GetProfile())
1004 ->GetFileEntry(extension_->id(), entry_id); 1007 ->GetFileEntry(extension_->id(), entry_id);
1005 if (!file_entry) { 1008 if (!file_entry) {
1006 error_ = kUnknownIdError; 1009 error_ = kUnknownIdError;
1007 return false; 1010 return false;
1008 } 1011 }
1009 1012
1010 SavedFilesService::Get(GetProfile()) 1013 SavedFilesServiceImpl::Get(GetProfile())
1011 ->EnqueueFileEntry(extension_->id(), entry_id); 1014 ->EnqueueFileEntry(extension_->id(), entry_id);
1012 1015
1013 // Only create a new file entry if the renderer requests one. 1016 // Only create a new file entry if the renderer requests one.
1014 // |needs_new_entry| will be false if the renderer already has an Entry for 1017 // |needs_new_entry| will be false if the renderer already has an Entry for
1015 // |entry_id|. 1018 // |entry_id|.
1016 if (needs_new_entry) { 1019 if (needs_new_entry) {
1017 is_directory_ = file_entry->is_directory; 1020 is_directory_ = file_entry->is_directory;
1018 std::unique_ptr<base::DictionaryValue> result = CreateResult(); 1021 std::unique_ptr<base::DictionaryValue> result = CreateResult();
1019 AddEntryToResult(file_entry->path, file_entry->id, result.get()); 1022 AddEntryToResult(file_entry->path, file_entry->id, result.get());
1020 SetResult(std::move(result)); 1023 SetResult(std::move(result));
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); 1238 return RespondNow(Error(kNotSupportedOnNonKioskSessionError));
1236 std::vector<api::file_system::Volume> result_volume_list; 1239 std::vector<api::file_system::Volume> result_volume_list;
1237 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); 1240 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list);
1238 1241
1239 return RespondNow(ArgumentList( 1242 return RespondNow(ArgumentList(
1240 api::file_system::GetVolumeList::Results::Create(result_volume_list))); 1243 api::file_system::GetVolumeList::Results::Create(result_volume_list)));
1241 } 1244 }
1242 #endif 1245 #endif
1243 1246
1244 } // namespace extensions 1247 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698