Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 55d9bed | 2011-03-25 20:37:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Yeunjoo Choi | ef8a4a4 | 2022-11-08 04:21:05 | [diff] [blame] | 5 | #include "chrome/browser/ash/fileapi/file_system_backend.h" |
[email protected] | 55d9bed | 2011-03-25 20:37:59 | [diff] [blame] | 6 | |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 9 | #include <memory> |
nya | 7b44260 | 2017-03-03 16:56:11 | [diff] [blame] | 10 | #include <utility> |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 11 | |
Yeunjoo Choi | 9b62f1a | 2021-06-23 13:17:00 | [diff] [blame] | 12 | #include "ash/webui/file_manager/url_constants.h" |
Hans Wennborg | 1790e6b | 2020-04-24 19:10:33 | [diff] [blame] | 13 | #include "base/check_op.h" |
yawano | e3893dbb | 2015-04-14 02:26:02 | [diff] [blame] | 14 | #include "base/command_line.h" |
Daniel Brinkers | 9dacf9e1 | 2023-03-09 07:39:05 | [diff] [blame] | 15 | #include "base/functional/callback_helpers.h" |
Hans Wennborg | 1790e6b | 2020-04-24 19:10:33 | [diff] [blame] | 16 | #include "base/notreached.h" |
Ryan Hamilton | 7f3bd3d | 2022-04-23 00:07:39 | [diff] [blame] | 17 | #include "base/strings/escape.h" |
Sam McNally | f41b98e | 2019-03-21 06:15:23 | [diff] [blame] | 18 | #include "base/task/task_traits.h" |
Gabriel Charette | 05503913 | 2020-02-26 23:02:06 | [diff] [blame] | 19 | #include "base/task/thread_pool.h" |
Henrique Ferreiro | e828b7b0 | 2021-03-23 23:00:59 | [diff] [blame] | 20 | #include "chrome/browser/ash/arc/fileapi/arc_documents_provider_util.h" |
Yeunjoo Choi | ef8a4a4 | 2022-11-08 04:21:05 | [diff] [blame] | 21 | #include "chrome/browser/ash/fileapi/file_access_permissions.h" |
Joel Hockey | d096e54 | 2023-08-07 06:01:24 | [diff] [blame] | 22 | #include "chrome/browser/ash/fileapi/file_system_backend.h" |
Yeunjoo Choi | ef8a4a4 | 2022-11-08 04:21:05 | [diff] [blame] | 23 | #include "chrome/browser/ash/fileapi/file_system_backend_delegate.h" |
| 24 | #include "chrome/browser/ash/fileapi/observable_file_system_operation_impl.h" |
Yeunjoo Choi | 15ab1ac | 2021-02-04 17:15:07 | [diff] [blame] | 25 | #include "chrome/browser/ash/profiles/profile_helper.h" |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 26 | #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
hirono | 10020e18 | 2014-09-24 05:31:59 | [diff] [blame] | 27 | #include "chrome/common/url_constants.h" |
Yeunjoo Choi | f8f9bc7 | 2022-07-20 02:55:39 | [diff] [blame] | 28 | #include "chromeos/ash/components/dbus/cros_disks/cros_disks_client.h" |
Eriko Kurimoto | dd765d1 | 2024-09-25 02:10:39 | [diff] [blame] | 29 | #include "chromeos/ash/components/file_manager/app_id.h" |
Daniel Brinkers | 9dacf9e1 | 2023-03-09 07:39:05 | [diff] [blame] | 30 | #include "components/file_access/scoped_file_access_delegate.h" |
Hidehiko Abe | d67cabd | 2023-01-17 18:34:50 | [diff] [blame] | 31 | #include "components/user_manager/user.h" |
Joel Hockey | 9d202494 | 2023-08-09 03:23:56 | [diff] [blame] | 32 | #include "extensions/common/extension.h" |
DongJun Kim | febb3c2 | 2019-10-21 02:08:06 | [diff] [blame] | 33 | #include "storage/browser/file_system/async_file_util.h" |
| 34 | #include "storage/browser/file_system/external_mount_points.h" |
| 35 | #include "storage/browser/file_system/file_stream_reader.h" |
| 36 | #include "storage/browser/file_system/file_stream_writer.h" |
| 37 | #include "storage/browser/file_system/file_system_context.h" |
| 38 | #include "storage/browser/file_system/file_system_operation.h" |
| 39 | #include "storage/browser/file_system/file_system_operation_context.h" |
| 40 | #include "storage/browser/file_system/file_system_url.h" |
DongJun Kim | d6930ea | 2019-10-24 08:49:25 | [diff] [blame] | 41 | #include "storage/common/file_system/file_system_mount_option.h" |
| 42 | #include "storage/common/file_system/file_system_types.h" |
| 43 | #include "storage/common/file_system/file_system_util.h" |
Kyra Seevers | 104537e | 2021-08-11 16:22:44 | [diff] [blame] | 44 | #include "third_party/blink/public/common/storage_key/storage_key.h" |
| 45 | #include "url/gurl.h" |
| 46 | #include "url/origin.h" |
[email protected] | c6c3f93 | 2012-03-16 07:45:27 | [diff] [blame] | 47 | |
Yeunjoo Choi | 3d9ed38a | 2022-11-10 02:51:24 | [diff] [blame] | 48 | namespace ash { |
hirono | 431103fc | 2016-09-01 08:33:42 | [diff] [blame] | 49 | namespace { |
| 50 | |
David Black | 8f8c1eb | 2020-12-09 04:02:23 | [diff] [blame] | 51 | // Returns the `AccountId` associated with the specified `profile`. |
| 52 | AccountId GetAccountId(Profile* profile) { |
| 53 | user_manager::User* user = |
| 54 | profile ? ProfileHelper::Get()->GetUserByProfile(profile) : nullptr; |
| 55 | return user ? user->GetAccountId() : AccountId(); |
| 56 | } |
| 57 | |
Joel Hockey | 9d202494 | 2023-08-09 03:23:56 | [diff] [blame] | 58 | // Returns true if the BackendFunction and OperationType correspond to the |
| 59 | // GetMetadata() and CreateFileStreamReader() calls used when loading a |
| 60 | // filesystem: URL via FileSystemUrlLoaderFactory. |
| 61 | bool IsReadOperation(BackendFunction backend_function, |
| 62 | storage::OperationType operation_type) { |
| 63 | if (backend_function == BackendFunction::kCreateFileSystemOperation && |
| 64 | operation_type == storage::OperationType::kGetMetadata) { |
| 65 | return true; |
| 66 | } |
| 67 | if (backend_function == BackendFunction::kCreateFileStreamReader) { |
| 68 | return true; |
| 69 | } |
| 70 | return false; |
| 71 | } |
| 72 | |
hirono | 431103fc | 2016-09-01 08:33:42 | [diff] [blame] | 73 | } // namespace |
[email protected] | bf48bed | 2012-02-24 20:49:07 | [diff] [blame] | 74 | |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 75 | // static |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 76 | bool FileSystemBackend::CanHandleURL(const storage::FileSystemURL& url) { |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 77 | if (!url.is_valid()) |
| 78 | return false; |
Austin Sullivan | 9233851 | 2021-01-28 23:32:59 | [diff] [blame] | 79 | return url.type() == storage::kFileSystemTypeLocal || |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 80 | url.type() == storage::kFileSystemTypeProvided || |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 81 | url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage || |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 82 | url.type() == storage::kFileSystemTypeArcContent || |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 83 | url.type() == storage::kFileSystemTypeArcDocumentsProvider || |
Anand K. Mistry | 5b28d1bc | 2019-10-30 06:53:59 | [diff] [blame] | 84 | url.type() == storage::kFileSystemTypeDriveFs || |
Noel Gordon | f927748 | 2022-02-04 01:13:50 | [diff] [blame] | 85 | url.type() == storage::kFileSystemTypeSmbFs || |
| 86 | url.type() == storage::kFileSystemTypeFuseBox; |
[email protected] | bf48bed | 2012-02-24 20:49:07 | [diff] [blame] | 87 | } |
| 88 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 89 | FileSystemBackend::FileSystemBackend( |
David Black | 8f8c1eb | 2020-12-09 04:02:23 | [diff] [blame] | 90 | Profile* profile, |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 91 | std::unique_ptr<FileSystemBackendDelegate> file_system_provider_delegate, |
| 92 | std::unique_ptr<FileSystemBackendDelegate> mtp_delegate, |
| 93 | std::unique_ptr<FileSystemBackendDelegate> arc_content_delegate, |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 94 | std::unique_ptr<FileSystemBackendDelegate> arc_documents_provider_delegate, |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 95 | std::unique_ptr<FileSystemBackendDelegate> drivefs_delegate, |
Anand K. Mistry | 7694c36 | 2020-03-17 23:33:34 | [diff] [blame] | 96 | std::unique_ptr<FileSystemBackendDelegate> smbfs_delegate, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 97 | scoped_refptr<storage::ExternalMountPoints> mount_points, |
| 98 | storage::ExternalMountPoints* system_mount_points) |
David Black | 8f8c1eb | 2020-12-09 04:02:23 | [diff] [blame] | 99 | : account_id_(GetAccountId(profile)), |
| 100 | file_access_permissions_(new FileAccessPermissions()), |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 101 | local_file_util_(storage::AsyncFileUtil::CreateForLocalFileSystem()), |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 102 | file_system_provider_delegate_(std::move(file_system_provider_delegate)), |
| 103 | mtp_delegate_(std::move(mtp_delegate)), |
| 104 | arc_content_delegate_(std::move(arc_content_delegate)), |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 105 | arc_documents_provider_delegate_( |
| 106 | std::move(arc_documents_provider_delegate)), |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 107 | drivefs_delegate_(std::move(drivefs_delegate)), |
Anand K. Mistry | 7694c36 | 2020-03-17 23:33:34 | [diff] [blame] | 108 | smbfs_delegate_(std::move(smbfs_delegate)), |
[email protected] | 9d5d698 | 2013-01-18 03:12:54 | [diff] [blame] | 109 | mount_points_(mount_points), |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 110 | system_mount_points_(system_mount_points) {} |
[email protected] | 3c3621b | 2013-06-07 06:12:34 | [diff] [blame] | 111 | |
Sorin Jianu | 091a41a | 2024-12-03 00:51:44 | [diff] [blame] | 112 | FileSystemBackend::~FileSystemBackend() = default; |
[email protected] | 3c3621b | 2013-06-07 06:12:34 | [diff] [blame] | 113 | |
Joel Hockey | d096e54 | 2023-08-07 06:01:24 | [diff] [blame] | 114 | // static |
| 115 | FileSystemBackend* FileSystemBackend::Get( |
| 116 | const storage::FileSystemContext& context) { |
| 117 | return static_cast<FileSystemBackend*>( |
| 118 | context.GetFileSystemBackend(storage::kFileSystemTypeExternal)); |
| 119 | } |
| 120 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 121 | void FileSystemBackend::AddSystemMountPoints() { |
[email protected] | 3c3621b | 2013-06-07 06:12:34 | [diff] [blame] | 122 | // RegisterFileSystem() is no-op if the mount point with the same name |
| 123 | // already exists, hence it's safe to call without checking if a mount |
| 124 | // point already exists or not. |
[email protected] | a5a8b41 | 2013-03-04 15:03:11 | [diff] [blame] | 125 | system_mount_points_->RegisterFileSystem( |
Austin Sullivan | 9233851 | 2021-01-28 23:32:59 | [diff] [blame] | 126 | kSystemMountNameArchive, storage::kFileSystemTypeLocal, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 127 | storage::FileSystemMountOption(), |
Yeunjoo Choi | 3d9ed38a | 2022-11-10 02:51:24 | [diff] [blame] | 128 | CrosDisksClient::GetArchiveMountPoint()); |
[email protected] | a5a8b41 | 2013-03-04 15:03:11 | [diff] [blame] | 129 | system_mount_points_->RegisterFileSystem( |
Austin Sullivan | 9233851 | 2021-01-28 23:32:59 | [diff] [blame] | 130 | kSystemMountNameRemovable, storage::kFileSystemTypeLocal, |
mtomasz | 92252d5 | 2014-12-11 01:49:47 | [diff] [blame] | 131 | storage::FileSystemMountOption(storage::FlushPolicy::FLUSH_ON_COMPLETION), |
Yeunjoo Choi | 3d9ed38a | 2022-11-10 02:51:24 | [diff] [blame] | 132 | CrosDisksClient::GetRemovableDiskMountPoint()); |
[email protected] | 55d9bed | 2011-03-25 20:37:59 | [diff] [blame] | 133 | } |
| 134 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 135 | bool FileSystemBackend::CanHandleType(storage::FileSystemType type) const { |
[email protected] | 420fb56 | 2013-04-18 01:46:34 | [diff] [blame] | 136 | switch (type) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 137 | case storage::kFileSystemTypeExternal: |
Austin Sullivan | 9233851 | 2021-01-28 23:32:59 | [diff] [blame] | 138 | case storage::kFileSystemTypeLocal: |
| 139 | case storage::kFileSystemTypeLocalForPlatformApp: |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 140 | case storage::kFileSystemTypeDeviceMediaAsFileStorage: |
| 141 | case storage::kFileSystemTypeProvided: |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 142 | case storage::kFileSystemTypeArcContent: |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 143 | case storage::kFileSystemTypeArcDocumentsProvider: |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 144 | case storage::kFileSystemTypeDriveFs: |
Anand K. Mistry | 5b28d1bc | 2019-10-30 06:53:59 | [diff] [blame] | 145 | case storage::kFileSystemTypeSmbFs: |
Noel Gordon | f927748 | 2022-02-04 01:13:50 | [diff] [blame] | 146 | case storage::kFileSystemTypeFuseBox: |
[email protected] | 420fb56 | 2013-04-18 01:46:34 | [diff] [blame] | 147 | return true; |
| 148 | default: |
| 149 | return false; |
| 150 | } |
| 151 | } |
| 152 | |
Bo Majewski | a382a37 | 2021-01-29 04:48:17 | [diff] [blame] | 153 | void FileSystemBackend::Initialize(storage::FileSystemContext* context) {} |
[email protected] | 3fc17aed | 2013-07-24 10:01:50 | [diff] [blame] | 154 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 155 | void FileSystemBackend::ResolveURL(const storage::FileSystemURL& url, |
| 156 | storage::OpenFileSystemMode mode, |
Nathan Eliason | bca1174c | 2022-05-12 16:00:57 | [diff] [blame] | 157 | ResolveURLCallback callback) { |
[email protected] | 0fa422a | 2014-02-26 04:56:40 | [diff] [blame] | 158 | std::string id; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 159 | storage::FileSystemType type; |
[email protected] | 7896ddc | 2014-06-20 10:40:16 | [diff] [blame] | 160 | std::string cracked_id; |
[email protected] | 0fa422a | 2014-02-26 04:56:40 | [diff] [blame] | 161 | base::FilePath path; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 162 | storage::FileSystemMountOption option; |
Bo Majewski | a382a37 | 2021-01-29 04:48:17 | [diff] [blame] | 163 | if (!mount_points_->CrackVirtualPath(url.virtual_path(), &id, &type, |
| 164 | &cracked_id, &path, &option) && |
| 165 | !system_mount_points_->CrackVirtualPath(url.virtual_path(), &id, &type, |
| 166 | &cracked_id, &path, &option)) { |
[email protected] | 0fa422a | 2014-02-26 04:56:40 | [diff] [blame] | 167 | // Not under a mount point, so return an error, since the root is not |
| 168 | // accessible. |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 169 | GURL root_url = GURL(storage::GetExternalFileSystemRootURIString( |
Erik Anderson | 1606ab8 | 2019-02-04 22:15:25 | [diff] [blame] | 170 | url.origin().GetURL(), std::string())); |
tzik | 3abe87e | 2017-08-23 03:23:11 | [diff] [blame] | 171 | std::move(callback).Run(root_url, std::string(), |
| 172 | base::File::FILE_ERROR_SECURITY); |
[email protected] | 0fa422a | 2014-02-26 04:56:40 | [diff] [blame] | 173 | return; |
| 174 | } |
| 175 | |
| 176 | std::string name; |
| 177 | // Construct a URL restricted to the found mount point. |
| 178 | std::string root_url = |
Erik Anderson | 1606ab8 | 2019-02-04 22:15:25 | [diff] [blame] | 179 | storage::GetExternalFileSystemRootURIString(url.origin().GetURL(), id); |
[email protected] | 0fa422a | 2014-02-26 04:56:40 | [diff] [blame] | 180 | |
| 181 | // For removable and archives, the file system root is the external mount |
| 182 | // point plus the inner mount point. |
| 183 | if (id == "archive" || id == "removable") { |
Jeremy Roman | 9ec5db9 | 2022-02-14 19:46:34 | [diff] [blame] | 184 | std::vector<std::string> components = url.virtual_path().GetComponents(); |
[email protected] | 0fa422a | 2014-02-26 04:56:40 | [diff] [blame] | 185 | DCHECK_EQ(id, components.at(0)); |
| 186 | if (components.size() < 2) { |
| 187 | // Unable to access /archive and /removable directories directly. The |
| 188 | // inner mount name must be specified. |
tzik | 3abe87e | 2017-08-23 03:23:11 | [diff] [blame] | 189 | std::move(callback).Run(GURL(root_url), std::string(), |
| 190 | base::File::FILE_ERROR_SECURITY); |
[email protected] | 0fa422a | 2014-02-26 04:56:40 | [diff] [blame] | 191 | return; |
| 192 | } |
Peter Marshall | 58d4c13 | 2022-08-17 06:17:34 | [diff] [blame] | 193 | std::string inner_mount_name = base::EscapePath(components[1]); |
[email protected] | 0fa422a | 2014-02-26 04:56:40 | [diff] [blame] | 194 | root_url += inner_mount_name + "/"; |
| 195 | name = inner_mount_name; |
nya | 4b8fa62 | 2017-01-12 10:57:26 | [diff] [blame] | 196 | } else if (id == arc::kDocumentsProviderMountPointName) { |
| 197 | // For ARC documents provider file system, volumes are mounted per document |
| 198 | // provider root, so we need to fix up |root_url| to point to an individual |
| 199 | // root. |
| 200 | std::string authority; |
Momoko Hattori | 416709e | 2024-02-13 15:43:18 | [diff] [blame] | 201 | std::string root_id; |
nya | 4b8fa62 | 2017-01-12 10:57:26 | [diff] [blame] | 202 | base::FilePath unused_path; |
Momoko Hattori | 416709e | 2024-02-13 15:43:18 | [diff] [blame] | 203 | if (!arc::ParseDocumentsProviderUrl(url, &authority, &root_id, |
nya | 4b8fa62 | 2017-01-12 10:57:26 | [diff] [blame] | 204 | &unused_path)) { |
tzik | 3abe87e | 2017-08-23 03:23:11 | [diff] [blame] | 205 | std::move(callback).Run(GURL(root_url), std::string(), |
| 206 | base::File::FILE_ERROR_SECURITY); |
nya | 4b8fa62 | 2017-01-12 10:57:26 | [diff] [blame] | 207 | return; |
| 208 | } |
| 209 | base::FilePath mount_path = |
Momoko Hattori | 416709e | 2024-02-13 15:43:18 | [diff] [blame] | 210 | arc::GetDocumentsProviderMountPath(authority, root_id); |
nya | 4b8fa62 | 2017-01-12 10:57:26 | [diff] [blame] | 211 | base::FilePath relative_mount_path; |
| 212 | base::FilePath(arc::kDocumentsProviderMountPointPath) |
| 213 | .AppendRelativePath(mount_path, &relative_mount_path); |
| 214 | root_url += |
Ryan Hamilton | 7f3bd3d | 2022-04-23 00:07:39 | [diff] [blame] | 215 | base::EscapePath(storage::FilePathToString(relative_mount_path)) + "/"; |
Momoko Hattori | 416709e | 2024-02-13 15:43:18 | [diff] [blame] | 216 | name = authority + ":" + root_id; |
[email protected] | 0fa422a | 2014-02-26 04:56:40 | [diff] [blame] | 217 | } else { |
| 218 | name = id; |
| 219 | } |
| 220 | |
tzik | 3abe87e | 2017-08-23 03:23:11 | [diff] [blame] | 221 | std::move(callback).Run(GURL(root_url), name, base::File::FILE_OK); |
[email protected] | 55d9bed | 2011-03-25 20:37:59 | [diff] [blame] | 222 | } |
| 223 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 224 | storage::FileSystemQuotaUtil* FileSystemBackend::GetQuotaUtil() { |
[email protected] | 4d03859 | 2013-02-18 16:50:23 | [diff] [blame] | 225 | // No quota support. |
Claudio DeSouza | 03dd2212 | 2022-09-02 23:47:21 | [diff] [blame] | 226 | return nullptr; |
[email protected] | 4d03859 | 2013-02-18 16:50:23 | [diff] [blame] | 227 | } |
| 228 | |
mtomasz | 110ffbe9 | 2014-09-11 10:35:40 | [diff] [blame] | 229 | const storage::UpdateObserverList* FileSystemBackend::GetUpdateObservers( |
| 230 | storage::FileSystemType type) const { |
Claudio DeSouza | 03dd2212 | 2022-09-02 23:47:21 | [diff] [blame] | 231 | return nullptr; |
mtomasz | 110ffbe9 | 2014-09-11 10:35:40 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | const storage::ChangeObserverList* FileSystemBackend::GetChangeObservers( |
| 235 | storage::FileSystemType type) const { |
Claudio DeSouza | 03dd2212 | 2022-09-02 23:47:21 | [diff] [blame] | 236 | return nullptr; |
mtomasz | 110ffbe9 | 2014-09-11 10:35:40 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | const storage::AccessObserverList* FileSystemBackend::GetAccessObservers( |
| 240 | storage::FileSystemType type) const { |
Claudio DeSouza | 03dd2212 | 2022-09-02 23:47:21 | [diff] [blame] | 241 | return nullptr; |
mtomasz | 110ffbe9 | 2014-09-11 10:35:40 | [diff] [blame] | 242 | } |
| 243 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 244 | bool FileSystemBackend::IsAccessAllowed( |
Joel Hockey | 9d202494 | 2023-08-09 03:23:56 | [diff] [blame] | 245 | BackendFunction backend_function, |
| 246 | storage::OperationType operation_type, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 247 | const storage::FileSystemURL& url) const { |
[email protected] | 5b7e42e6 | 2013-01-24 22:01:51 | [diff] [blame] | 248 | if (!url.is_valid()) |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 249 | return false; |
[email protected] | 24dceaf | 2011-04-20 09:05:52 | [diff] [blame] | 250 | |
[email protected] | 5b7e42e6 | 2013-01-24 22:01:51 | [diff] [blame] | 251 | // No extra check is needed for isolated file systems. |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 252 | if (url.mount_type() == storage::kFileSystemTypeIsolated) |
[email protected] | 5b7e42e6 | 2013-01-24 22:01:51 | [diff] [blame] | 253 | return true; |
| 254 | |
| 255 | if (!CanHandleURL(url)) |
| 256 | return false; |
| 257 | |
Bo Majewski | 762d913a | 2021-06-30 03:54:25 | [diff] [blame] | 258 | const url::Origin origin = url.origin(); |
mtomasz | a6775be | 2015-03-18 06:45:27 | [diff] [blame] | 259 | // If there is no origin set, then it's an internal access. |
Bo Majewski | 762d913a | 2021-06-30 03:54:25 | [diff] [blame] | 260 | if (origin.opaque()) |
mtomasz | a6775be | 2015-03-18 06:45:27 | [diff] [blame] | 261 | return true; |
| 262 | |
Alex Danilo | cf0eff8 | 2021-02-17 03:07:01 | [diff] [blame] | 263 | // The chrome://file-manager can access its filesystem origin. |
Yeunjoo Choi | 3d9ed38a | 2022-11-10 02:51:24 | [diff] [blame] | 264 | if (origin.GetURL() == file_manager::kChromeUIFileManagerURL) { |
Alex Danilo | cf0eff8 | 2021-02-17 03:07:01 | [diff] [blame] | 265 | return true; |
| 266 | } |
Alex Danilo | cf0eff8 | 2021-02-17 03:07:01 | [diff] [blame] | 267 | |
Joel Hockey | 9d202494 | 2023-08-09 03:23:56 | [diff] [blame] | 268 | // ImageLoader extension has read-only access via FileSystemUrlLoaderFactory. |
| 269 | if (origin.GetURL() == extensions::Extension::GetBaseURLFromExtensionId( |
| 270 | ::file_manager::kImageLoaderExtensionId) && |
| 271 | IsReadOperation(backend_function, operation_type)) { |
| 272 | return true; |
| 273 | } |
| 274 | |
Bo Majewski | 762d913a | 2021-06-30 03:54:25 | [diff] [blame] | 275 | return file_access_permissions_->HasAccessPermission(origin, |
[email protected] | 5aeeb7c6 | 2012-08-27 11:34:13 | [diff] [blame] | 276 | url.virtual_path()); |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 277 | } |
| 278 | |
Bo Majewski | 762d913a | 2021-06-30 03:54:25 | [diff] [blame] | 279 | void FileSystemBackend::GrantFileAccessToOrigin( |
| 280 | const url::Origin& origin, |
Bo Majewski | a382a37 | 2021-01-29 04:48:17 | [diff] [blame] | 281 | const base::FilePath& virtual_path) { |
[email protected] | f037de8 | 2012-10-03 06:07:57 | [diff] [blame] | 282 | std::string id; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 283 | storage::FileSystemType type; |
[email protected] | 7896ddc | 2014-06-20 10:40:16 | [diff] [blame] | 284 | std::string cracked_id; |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 285 | base::FilePath path; |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 286 | storage::FileSystemMountOption option; |
[email protected] | 7896ddc | 2014-06-20 10:40:16 | [diff] [blame] | 287 | if (!mount_points_->CrackVirtualPath(virtual_path, &id, &type, &cracked_id, |
| 288 | &path, &option) && |
| 289 | !system_mount_points_->CrackVirtualPath(virtual_path, &id, &type, |
| 290 | &cracked_id, &path, &option)) { |
[email protected] | 9d5d698 | 2013-01-18 03:12:54 | [diff] [blame] | 291 | return; |
| 292 | } |
[email protected] | f037de8 | 2012-10-03 06:07:57 | [diff] [blame] | 293 | |
Bo Majewski | 762d913a | 2021-06-30 03:54:25 | [diff] [blame] | 294 | file_access_permissions_->GrantAccessPermission(origin, virtual_path); |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 295 | } |
| 296 | |
Bo Majewski | 762d913a | 2021-06-30 03:54:25 | [diff] [blame] | 297 | void FileSystemBackend::RevokeAccessForOrigin(const url::Origin& origin) { |
| 298 | file_access_permissions_->RevokePermissions(origin); |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 299 | } |
| 300 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 301 | std::vector<base::FilePath> FileSystemBackend::GetRootDirectories() const { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 302 | std::vector<storage::MountPoints::MountPointInfo> mount_points; |
[email protected] | 9d5d698 | 2013-01-18 03:12:54 | [diff] [blame] | 303 | mount_points_->AddMountPointInfosTo(&mount_points); |
| 304 | system_mount_points_->AddMountPointInfosTo(&mount_points); |
| 305 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 306 | std::vector<base::FilePath> root_dirs; |
[email protected] | 9d5d698 | 2013-01-18 03:12:54 | [diff] [blame] | 307 | for (size_t i = 0; i < mount_points.size(); ++i) |
| 308 | root_dirs.push_back(mount_points[i].path); |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 309 | return root_dirs; |
[email protected] | 55d9bed | 2011-03-25 20:37:59 | [diff] [blame] | 310 | } |
| 311 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 312 | storage::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil( |
| 313 | storage::FileSystemType type) { |
[email protected] | d1bd77e | 2014-04-22 10:13:29 | [diff] [blame] | 314 | switch (type) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 315 | case storage::kFileSystemTypeProvided: |
[email protected] | d1bd77e | 2014-04-22 10:13:29 | [diff] [blame] | 316 | return file_system_provider_delegate_->GetAsyncFileUtil(type); |
Austin Sullivan | 9233851 | 2021-01-28 23:32:59 | [diff] [blame] | 317 | case storage::kFileSystemTypeLocal: |
Noel Gordon | f927748 | 2022-02-04 01:13:50 | [diff] [blame] | 318 | case storage::kFileSystemTypeFuseBox: |
[email protected] | d1bd77e | 2014-04-22 10:13:29 | [diff] [blame] | 319 | return local_file_util_.get(); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 320 | case storage::kFileSystemTypeDeviceMediaAsFileStorage: |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 321 | return mtp_delegate_->GetAsyncFileUtil(type); |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 322 | case storage::kFileSystemTypeArcContent: |
| 323 | return arc_content_delegate_->GetAsyncFileUtil(type); |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 324 | case storage::kFileSystemTypeArcDocumentsProvider: |
| 325 | return arc_documents_provider_delegate_->GetAsyncFileUtil(type); |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 326 | case storage::kFileSystemTypeDriveFs: |
| 327 | return drivefs_delegate_->GetAsyncFileUtil(type); |
Anand K. Mistry | 7694c36 | 2020-03-17 23:33:34 | [diff] [blame] | 328 | case storage::kFileSystemTypeSmbFs: |
| 329 | return smbfs_delegate_->GetAsyncFileUtil(type); |
[email protected] | d1bd77e | 2014-04-22 10:13:29 | [diff] [blame] | 330 | default: |
Peter Boström | 9503e9a | 2024-11-04 18:54:21 | [diff] [blame] | 331 | NOTREACHED(); |
[email protected] | d1bd77e | 2014-04-22 10:13:29 | [diff] [blame] | 332 | } |
[email protected] | ccb14ed | 2011-07-06 10:50:50 | [diff] [blame] | 333 | } |
| 334 | |
mtomasz | b75244fd | 2014-08-28 05:37:34 | [diff] [blame] | 335 | storage::WatcherManager* FileSystemBackend::GetWatcherManager( |
| 336 | storage::FileSystemType type) { |
mtomasz | acaff081 | 2014-11-06 09:50:57 | [diff] [blame] | 337 | if (type == storage::kFileSystemTypeProvided) |
| 338 | return file_system_provider_delegate_->GetWatcherManager(type); |
| 339 | |
Anand K. Mistry | 0bfd71e | 2019-04-24 01:45:04 | [diff] [blame] | 340 | if (type == storage::kFileSystemTypeDeviceMediaAsFileStorage) { |
yawano | e3893dbb | 2015-04-14 02:26:02 | [diff] [blame] | 341 | return mtp_delegate_->GetWatcherManager(type); |
| 342 | } |
| 343 | |
nya | 7b44260 | 2017-03-03 16:56:11 | [diff] [blame] | 344 | if (type == storage::kFileSystemTypeArcDocumentsProvider) |
| 345 | return arc_documents_provider_delegate_->GetWatcherManager(type); |
| 346 | |
mtomasz | acaff081 | 2014-11-06 09:50:57 | [diff] [blame] | 347 | // TODO(mtomasz): Add support for other backends. |
Claudio DeSouza | 03dd2212 | 2022-09-02 23:47:21 | [diff] [blame] | 348 | return nullptr; |
mtomasz | b75244fd | 2014-08-28 05:37:34 | [diff] [blame] | 349 | } |
| 350 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 351 | storage::CopyOrMoveFileValidatorFactory* |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 352 | FileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 353 | storage::FileSystemType type, |
| 354 | base::File::Error* error_code) { |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 355 | DCHECK(error_code); |
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame] | 356 | *error_code = base::File::FILE_OK; |
Claudio DeSouza | 03dd2212 | 2022-09-02 23:47:21 | [diff] [blame] | 357 | return nullptr; |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 358 | } |
| 359 | |
Victor Costan | c49feb7 | 2021-08-16 19:19:20 | [diff] [blame] | 360 | std::unique_ptr<storage::FileSystemOperation> |
| 361 | FileSystemBackend::CreateFileSystemOperation( |
Joel Hockey | 75a1058 | 2023-08-09 02:58:29 | [diff] [blame] | 362 | storage::OperationType type, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 363 | const storage::FileSystemURL& url, |
| 364 | storage::FileSystemContext* context, |
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame] | 365 | base::File::Error* error_code) const { |
[email protected] | 9d5d698 | 2013-01-18 03:12:54 | [diff] [blame] | 366 | DCHECK(url.is_valid()); |
| 367 | |
Joel Hockey | 9d202494 | 2023-08-09 03:23:56 | [diff] [blame] | 368 | if (!IsAccessAllowed(BackendFunction::kCreateFileSystemOperation, type, |
| 369 | url)) { |
[email protected] | 141bcc5 | 2014-01-27 21:36:00 | [diff] [blame] | 370 | *error_code = base::File::FILE_ERROR_SECURITY; |
Claudio DeSouza | 03dd2212 | 2022-09-02 23:47:21 | [diff] [blame] | 371 | return nullptr; |
[email protected] | ce5cbed8 | 2013-07-01 11:52:31 | [diff] [blame] | 372 | } |
| 373 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 374 | if (url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage) { |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 375 | // MTP file operations run on MediaTaskRunner. |
Victor Costan | c49feb7 | 2021-08-16 19:19:20 | [diff] [blame] | 376 | return std::make_unique<ObservableFileSystemOperationImpl>( |
Joel Hockey | 75a1058 | 2023-08-09 02:58:29 | [diff] [blame] | 377 | account_id_, type, url, context, |
Jinho Bang | 341ce5b0 | 2018-01-17 22:46:03 | [diff] [blame] | 378 | std::make_unique<storage::FileSystemOperationContext>( |
ricea | 46ad5f4 | 2016-08-24 02:44:55 | [diff] [blame] | 379 | context, MediaFileSystemBackend::MediaTaskRunner().get())); |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 380 | } |
Austin Sullivan | 9233851 | 2021-01-28 23:32:59 | [diff] [blame] | 381 | if (url.type() == storage::kFileSystemTypeLocal || |
Anand K. Mistry | 5b28d1bc | 2019-10-30 06:53:59 | [diff] [blame] | 382 | url.type() == storage::kFileSystemTypeDriveFs || |
Noel Gordon | f927748 | 2022-02-04 01:13:50 | [diff] [blame] | 383 | url.type() == storage::kFileSystemTypeSmbFs || |
| 384 | url.type() == storage::kFileSystemTypeFuseBox) { |
Victor Costan | c49feb7 | 2021-08-16 19:19:20 | [diff] [blame] | 385 | return std::make_unique<ObservableFileSystemOperationImpl>( |
Joel Hockey | 75a1058 | 2023-08-09 02:58:29 | [diff] [blame] | 386 | account_id_, type, url, context, |
Sam McNally | f41b98e | 2019-03-21 06:15:23 | [diff] [blame] | 387 | std::make_unique<storage::FileSystemOperationContext>( |
Gabriel Charette | 05503913 | 2020-02-26 23:02:06 | [diff] [blame] | 388 | context, base::ThreadPool::CreateSequencedTaskRunner( |
| 389 | {base::MayBlock(), base::TaskPriority::USER_VISIBLE}) |
Sam McNally | f41b98e | 2019-03-21 06:15:23 | [diff] [blame] | 390 | .get())); |
| 391 | } |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 392 | |
Austin Tankiang | 0bf0252 | 2019-12-03 04:17:28 | [diff] [blame] | 393 | DCHECK(url.type() == storage::kFileSystemTypeProvided || |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 394 | url.type() == storage::kFileSystemTypeArcContent || |
Sam McNally | f41b98e | 2019-03-21 06:15:23 | [diff] [blame] | 395 | url.type() == storage::kFileSystemTypeArcDocumentsProvider); |
Victor Costan | c49feb7 | 2021-08-16 19:19:20 | [diff] [blame] | 396 | return std::make_unique<ObservableFileSystemOperationImpl>( |
Joel Hockey | 75a1058 | 2023-08-09 02:58:29 | [diff] [blame] | 397 | account_id_, type, url, context, |
Jinho Bang | 341ce5b0 | 2018-01-17 22:46:03 | [diff] [blame] | 398 | std::make_unique<storage::FileSystemOperationContext>(context)); |
[email protected] | 3eb080d | 2012-01-16 04:20:06 | [diff] [blame] | 399 | } |
| 400 | |
[email protected] | 8ed6b69 | 2014-02-24 18:30:59 | [diff] [blame] | 401 | bool FileSystemBackend::SupportsStreaming( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 402 | const storage::FileSystemURL& url) const { |
Austin Tankiang | 0bf0252 | 2019-12-03 04:17:28 | [diff] [blame] | 403 | return url.type() == storage::kFileSystemTypeProvided || |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 404 | url.type() == storage::kFileSystemTypeDeviceMediaAsFileStorage || |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 405 | url.type() == storage::kFileSystemTypeArcContent || |
Shuhei Takahashi | da9d3dd | 2017-08-09 07:21:29 | [diff] [blame] | 406 | url.type() == storage::kFileSystemTypeArcDocumentsProvider; |
[email protected] | 8ed6b69 | 2014-02-24 18:30:59 | [diff] [blame] | 407 | } |
| 408 | |
[email protected] | c83c919 | 2014-08-19 08:44:55 | [diff] [blame] | 409 | bool FileSystemBackend::HasInplaceCopyImplementation( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 410 | storage::FileSystemType type) const { |
[email protected] | c83c919 | 2014-08-19 08:44:55 | [diff] [blame] | 411 | switch (type) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 412 | case storage::kFileSystemTypeProvided: |
| 413 | case storage::kFileSystemTypeDeviceMediaAsFileStorage: |
Sam McNally | 47f2eac | 2018-08-28 06:45:05 | [diff] [blame] | 414 | case storage::kFileSystemTypeDriveFs: |
[email protected] | c83c919 | 2014-08-19 08:44:55 | [diff] [blame] | 415 | return true; |
Naoki Fukino | 419a639 | 2019-04-17 07:24:14 | [diff] [blame] | 416 | // TODO(fukino): Support in-place copy for DocumentsProvider. |
| 417 | // crbug.com/953603. |
| 418 | case storage::kFileSystemTypeArcDocumentsProvider: |
Austin Sullivan | 9233851 | 2021-01-28 23:32:59 | [diff] [blame] | 419 | case storage::kFileSystemTypeLocal: |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 420 | case storage::kFileSystemTypeArcContent: |
Alison Gale | 9f64b0ccd | 2024-04-16 00:04:06 | [diff] [blame] | 421 | // TODO(crbug.com/41445433): Implement in-place copy in SmbFs. |
Anand K. Mistry | 5b28d1bc | 2019-10-30 06:53:59 | [diff] [blame] | 422 | case storage::kFileSystemTypeSmbFs: |
Noel Gordon | f927748 | 2022-02-04 01:13:50 | [diff] [blame] | 423 | case storage::kFileSystemTypeFuseBox: |
[email protected] | c83c919 | 2014-08-19 08:44:55 | [diff] [blame] | 424 | return false; |
| 425 | default: |
Peter Boström | 9503e9a | 2024-11-04 18:54:21 | [diff] [blame] | 426 | NOTREACHED(); |
[email protected] | c83c919 | 2014-08-19 08:44:55 | [diff] [blame] | 427 | } |
[email protected] | c83c919 | 2014-08-19 08:44:55 | [diff] [blame] | 428 | } |
| 429 | |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 430 | std::unique_ptr<storage::FileStreamReader> |
| 431 | FileSystemBackend::CreateFileStreamReader( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 432 | const storage::FileSystemURL& url, |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 433 | int64_t offset, |
| 434 | int64_t max_bytes_to_read, |
[email protected] | a105783 | 2012-10-15 13:28:06 | [diff] [blame] | 435 | const base::Time& expected_modification_time, |
Daniel Brinkers | 9dacf9e1 | 2023-03-09 07:39:05 | [diff] [blame] | 436 | storage::FileSystemContext* context, |
| 437 | file_access::ScopedFileAccessDelegate::RequestFilesAccessIOCallback |
| 438 | file_access) const { |
[email protected] | ebb4bcea | 2013-05-13 11:17:38 | [diff] [blame] | 439 | DCHECK(url.is_valid()); |
| 440 | |
Joel Hockey | 9d202494 | 2023-08-09 03:23:56 | [diff] [blame] | 441 | if (!IsAccessAllowed(BackendFunction::kCreateFileStreamReader, |
| 442 | storage::OperationType::kNone, url)) { |
Lei Zhang | 70a27680 | 2021-04-08 03:36:46 | [diff] [blame] | 443 | return nullptr; |
Joel Hockey | 9d202494 | 2023-08-09 03:23:56 | [diff] [blame] | 444 | } |
[email protected] | ce5cbed8 | 2013-07-01 11:52:31 | [diff] [blame] | 445 | |
[email protected] | d1bd77e | 2014-04-22 10:13:29 | [diff] [blame] | 446 | switch (url.type()) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 447 | case storage::kFileSystemTypeProvided: |
[email protected] | d1bd77e | 2014-04-22 10:13:29 | [diff] [blame] | 448 | return file_system_provider_delegate_->CreateFileStreamReader( |
mtomasz | 85aa9d7 | 2014-09-16 23:40:38 | [diff] [blame] | 449 | url, offset, max_bytes_to_read, expected_modification_time, context); |
Daniel Brinkers | 9dacf9e1 | 2023-03-09 07:39:05 | [diff] [blame] | 450 | // The dlp file_access callback is needed for the local filesystem only. |
Austin Sullivan | 9233851 | 2021-01-28 23:32:59 | [diff] [blame] | 451 | case storage::kFileSystemTypeLocal: |
Daniel Brinkers | 9dacf9e1 | 2023-03-09 07:39:05 | [diff] [blame] | 452 | return storage::FileStreamReader::CreateForLocalFile( |
| 453 | base::ThreadPool::CreateTaskRunner( |
| 454 | {base::MayBlock(), base::TaskPriority::USER_VISIBLE}) |
| 455 | .get(), |
| 456 | url.path(), offset, expected_modification_time, |
| 457 | std::move(file_access)); |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 458 | case storage::kFileSystemTypeDriveFs: |
Anand K. Mistry | 5b28d1bc | 2019-10-30 06:53:59 | [diff] [blame] | 459 | case storage::kFileSystemTypeSmbFs: |
Noel Gordon | f927748 | 2022-02-04 01:13:50 | [diff] [blame] | 460 | case storage::kFileSystemTypeFuseBox: |
Yeunjoo Choi | ef8a4a4 | 2022-11-08 04:21:05 | [diff] [blame] | 461 | return storage::FileStreamReader::CreateForLocalFile( |
| 462 | base::ThreadPool::CreateTaskRunner( |
| 463 | {base::MayBlock(), base::TaskPriority::USER_VISIBLE}) |
| 464 | .get(), |
| 465 | url.path(), offset, expected_modification_time); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 466 | case storage::kFileSystemTypeDeviceMediaAsFileStorage: |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 467 | return mtp_delegate_->CreateFileStreamReader( |
mtomasz | 85aa9d7 | 2014-09-16 23:40:38 | [diff] [blame] | 468 | url, offset, max_bytes_to_read, expected_modification_time, context); |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 469 | case storage::kFileSystemTypeArcContent: |
| 470 | return arc_content_delegate_->CreateFileStreamReader( |
| 471 | url, offset, max_bytes_to_read, expected_modification_time, context); |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 472 | case storage::kFileSystemTypeArcDocumentsProvider: |
| 473 | return arc_documents_provider_delegate_->CreateFileStreamReader( |
| 474 | url, offset, max_bytes_to_read, expected_modification_time, context); |
[email protected] | d1bd77e | 2014-04-22 10:13:29 | [diff] [blame] | 475 | default: |
Peter Boström | 9503e9a | 2024-11-04 18:54:21 | [diff] [blame] | 476 | NOTREACHED(); |
[email protected] | ebb4bcea | 2013-05-13 11:17:38 | [diff] [blame] | 477 | } |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 478 | } |
| 479 | |
dcheng | 24002d0 | 2016-04-08 02:42:40 | [diff] [blame] | 480 | std::unique_ptr<storage::FileStreamWriter> |
| 481 | FileSystemBackend::CreateFileStreamWriter( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 482 | const storage::FileSystemURL& url, |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 483 | int64_t offset, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 484 | storage::FileSystemContext* context) const { |
[email protected] | 9d5d698 | 2013-01-18 03:12:54 | [diff] [blame] | 485 | DCHECK(url.is_valid()); |
| 486 | |
Joel Hockey | 9d202494 | 2023-08-09 03:23:56 | [diff] [blame] | 487 | if (!IsAccessAllowed(BackendFunction::kCreateFileStreamWriter, |
| 488 | storage::OperationType::kNone, url)) { |
Lei Zhang | 70a27680 | 2021-04-08 03:36:46 | [diff] [blame] | 489 | return nullptr; |
Joel Hockey | 9d202494 | 2023-08-09 03:23:56 | [diff] [blame] | 490 | } |
[email protected] | ce5cbed8 | 2013-07-01 11:52:31 | [diff] [blame] | 491 | |
[email protected] | d1bd77e | 2014-04-22 10:13:29 | [diff] [blame] | 492 | switch (url.type()) { |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 493 | case storage::kFileSystemTypeProvided: |
Bo Majewski | a382a37 | 2021-01-29 04:48:17 | [diff] [blame] | 494 | return file_system_provider_delegate_->CreateFileStreamWriter(url, offset, |
| 495 | context); |
Austin Sullivan | 9233851 | 2021-01-28 23:32:59 | [diff] [blame] | 496 | case storage::kFileSystemTypeLocal: |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 497 | case storage::kFileSystemTypeDriveFs: |
Anand K. Mistry | 5b28d1bc | 2019-10-30 06:53:59 | [diff] [blame] | 498 | case storage::kFileSystemTypeSmbFs: |
Noel Gordon | f927748 | 2022-02-04 01:13:50 | [diff] [blame] | 499 | case storage::kFileSystemTypeFuseBox: |
Ayu Ishii | 360d62d | 2019-02-15 22:50:09 | [diff] [blame] | 500 | return storage::FileStreamWriter::CreateForLocalFile( |
Gabriel Charette | 05503913 | 2020-02-26 23:02:06 | [diff] [blame] | 501 | base::ThreadPool::CreateTaskRunner( |
| 502 | {base::MayBlock(), base::TaskPriority::USER_VISIBLE}) |
Sam McNally | f41b98e | 2019-03-21 06:15:23 | [diff] [blame] | 503 | .get(), |
| 504 | url.path(), offset, storage::FileStreamWriter::OPEN_EXISTING_FILE); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 505 | case storage::kFileSystemTypeDeviceMediaAsFileStorage: |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 506 | return mtp_delegate_->CreateFileStreamWriter(url, offset, context); |
Naoki Fukino | b244b10 | 2019-04-04 05:59:17 | [diff] [blame] | 507 | case storage::kFileSystemTypeArcDocumentsProvider: |
| 508 | return arc_documents_provider_delegate_->CreateFileStreamWriter( |
| 509 | url, offset, context); |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 510 | // Read only file systems. |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 511 | case storage::kFileSystemTypeArcContent: |
Lei Zhang | 70a27680 | 2021-04-08 03:36:46 | [diff] [blame] | 512 | return nullptr; |
[email protected] | d1bd77e | 2014-04-22 10:13:29 | [diff] [blame] | 513 | default: |
Peter Boström | 9503e9a | 2024-11-04 18:54:21 | [diff] [blame] | 514 | NOTREACHED(); |
[email protected] | 43420a1 | 2014-04-21 03:20:48 | [diff] [blame] | 515 | } |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 516 | } |
| 517 | |
mtomasz | a6775be | 2015-03-18 06:45:27 | [diff] [blame] | 518 | bool FileSystemBackend::GetVirtualPath(const base::FilePath& filesystem_path, |
| 519 | base::FilePath* virtual_path) const { |
[email protected] | 9d5d698 | 2013-01-18 03:12:54 | [diff] [blame] | 520 | return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
| 521 | system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 522 | } |
| 523 | |
mtomasz | a6775be | 2015-03-18 06:45:27 | [diff] [blame] | 524 | storage::FileSystemURL FileSystemBackend::CreateInternalURL( |
| 525 | storage::FileSystemContext* context, |
| 526 | const base::FilePath& entry_path) const { |
| 527 | base::FilePath virtual_path; |
| 528 | if (!GetVirtualPath(entry_path, &virtual_path)) |
| 529 | return storage::FileSystemURL(); |
| 530 | |
| 531 | return context->CreateCrackedFileSystemURL( |
Kyra Seevers | 104537e | 2021-08-11 16:22:44 | [diff] [blame] | 532 | blink::StorageKey(), storage::kFileSystemTypeExternal, virtual_path); |
mtomasz | a6775be | 2015-03-18 06:45:27 | [diff] [blame] | 533 | } |
| 534 | |
Yeunjoo Choi | 3d9ed38a | 2022-11-10 02:51:24 | [diff] [blame] | 535 | } // namespace ash |