pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
DongJun Kim | febb3c2 | 2019-10-21 02:08:06 | [diff] [blame] | 5 | #ifndef STORAGE_BROWSER_FILE_SYSTEM_MOUNT_POINTS_H_ |
| 6 | #define STORAGE_BROWSER_FILE_SYSTEM_MOUNT_POINTS_H_ |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Victor Costan | feaee8cf7 | 2018-12-28 00:39:15 | [diff] [blame] | 11 | #include "base/component_export.h" |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
DongJun Kim | d6930ea | 2019-10-24 08:49:25 | [diff] [blame] | 13 | #include "storage/common/file_system/file_system_util.h" |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 14 | |
| 15 | class GURL; |
Kyra Seevers | 01164488 | 2021-08-17 21:21:47 | [diff] [blame] | 16 | |
| 17 | namespace blink { |
| 18 | class StorageKey; |
Kyra Seevers | c5cba52c | 2021-08-20 16:31:27 | [diff] [blame] | 19 | } // namespace blink |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 20 | |
| 21 | namespace storage { |
| 22 | class FileSystemMountOption; |
| 23 | class FileSystemURL; |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 24 | |
| 25 | // Represents a set of mount points for File API. |
Victor Costan | feaee8cf7 | 2018-12-28 00:39:15 | [diff] [blame] | 26 | class COMPONENT_EXPORT(STORAGE_BROWSER) MountPoints { |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 27 | public: |
Victor Costan | feaee8cf7 | 2018-12-28 00:39:15 | [diff] [blame] | 28 | struct COMPONENT_EXPORT(STORAGE_BROWSER) MountPointInfo { |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 29 | MountPointInfo(); |
| 30 | MountPointInfo(const std::string& name, const base::FilePath& path); |
| 31 | |
| 32 | // The name to be used to register the path. The registered file can |
| 33 | // be referred by a virtual path /<filesystem_id>/<name>. |
| 34 | // The name should NOT contain a path separator '/'. |
| 35 | std::string name; |
| 36 | |
| 37 | // The path of the file. |
| 38 | base::FilePath path; |
| 39 | |
| 40 | // For STL operation. |
| 41 | bool operator<(const MountPointInfo& that) const { |
| 42 | return name < that.name; |
| 43 | } |
| 44 | }; |
| 45 | |
Austin Sullivan | 9de3358 | 2021-06-15 06:05:31 | [diff] [blame] | 46 | MountPoints() = default; |
| 47 | MountPoints(const MountPoints&) = delete; |
| 48 | MountPoints& operator=(const MountPoints&) = delete; |
| 49 | virtual ~MountPoints() = default; |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 50 | |
| 51 | // Revokes a mount point identified by |mount_name|. |
| 52 | // Returns false if the |mount_name| is not (no longer) registered. |
| 53 | // TODO(kinuko): Probably this should be rather named RevokeMountPoint. |
| 54 | virtual bool RevokeFileSystem(const std::string& mount_name) = 0; |
| 55 | |
| 56 | // Returns true if the MountPoints implementation handles filesystems with |
| 57 | // the given mount type. |
| 58 | virtual bool HandlesFileSystemMountType(FileSystemType type) const = 0; |
| 59 | |
Kyra Seevers | 01164488 | 2021-08-17 21:21:47 | [diff] [blame] | 60 | // TODO(https://crbug.com/1240603): Determine if MountPoints::CrackURL() |
| 61 | // and its overrides in child classes should be removed and replaced with |
| 62 | // FileSystemContext::CrackURL(). |
| 63 | // |
| 64 | // Same as CreateCrackedFileSystemURL, but cracks a FileSystemURL created |
| 65 | // from `url` and `storage_key`. |
| 66 | virtual FileSystemURL CrackURL( |
| 67 | const GURL& url, |
| 68 | const blink::StorageKey& storage_key) const = 0; |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 69 | |
Kyra Seevers | c5cba52c | 2021-08-20 16:31:27 | [diff] [blame] | 70 | // Creates a FileSystemURL with the given `storage_key`, `type`, and |
| 71 | // `virtual_path` and tries to crack it as a part of one of the registered |
| 72 | // mount points. If the the URL is not valid or does not belong to any of the |
| 73 | // mount points registered in this context, returns empty, invalid |
| 74 | // FileSystemURL. |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 75 | virtual FileSystemURL CreateCrackedFileSystemURL( |
Kyra Seevers | c5cba52c | 2021-08-20 16:31:27 | [diff] [blame] | 76 | const blink::StorageKey& storage_key, |
Victor Costan | b410d1a | 2020-02-12 05:03:22 | [diff] [blame] | 77 | FileSystemType type, |
Joel Hockey | de49adac | 2020-11-03 20:34:24 | [diff] [blame] | 78 | const base::FilePath& virtual_path) const = 0; |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 79 | |
| 80 | // Returns the mount point root path registered for a given |mount_name|. |
| 81 | // Returns false if the given |mount_name| is not valid. |
| 82 | virtual bool GetRegisteredPath(const std::string& mount_name, |
| 83 | base::FilePath* path) const = 0; |
| 84 | |
| 85 | // Cracks the given |virtual_path| (which is the path part of a filesystem URL |
| 86 | // without '/external' or '/isolated' prefix part) and populates the |
| 87 | // |mount_name|, |type|, and |path| if the <mount_name> part embedded in |
| 88 | // the |virtual_path| (i.e. the first component of the |virtual_path|) is a |
| 89 | // valid registered filesystem ID or mount name for an existing mount point. |
| 90 | // |
| 91 | // Returns false if the given virtual_path cannot be cracked. |
| 92 | // |
| 93 | // Note that |path| is set to empty paths if the filesystem type is isolated |
| 94 | // and |virtual_path| has no <relative_path> part (i.e. pointing to the |
| 95 | // virtual root). |
| 96 | virtual bool CrackVirtualPath(const base::FilePath& virtual_path, |
| 97 | std::string* mount_name, |
| 98 | FileSystemType* type, |
| 99 | std::string* cracked_id, |
| 100 | base::FilePath* path, |
| 101 | FileSystemMountOption* mount_option) const = 0; |
| 102 | |
| 103 | protected: |
| 104 | friend class FileSystemContext; |
| 105 | |
| 106 | // Same as CrackURL and CreateCrackedFileSystemURL, but cracks the url already |
| 107 | // instantiated as the FileSystemURL class. This is internally used for nested |
| 108 | // URL cracking in FileSystemContext. |
| 109 | virtual FileSystemURL CrackFileSystemURL(const FileSystemURL& url) const = 0; |
pilgrim | 4af8c21 | 2014-09-05 17:30:15 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } // namespace storage |
| 113 | |
DongJun Kim | febb3c2 | 2019-10-21 02:08:06 | [diff] [blame] | 114 | #endif // STORAGE_BROWSER_FILE_SYSTEM_MOUNT_POINTS_H_ |