blob: 11b65bd1d04020923f78ee8f9350dd443276e6ea [file] [log] [blame]
pilgrim4af8c212014-09-05 17:30:151// 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 Kimfebb3c22019-10-21 02:08:065#ifndef STORAGE_BROWSER_FILE_SYSTEM_MOUNT_POINTS_H_
6#define STORAGE_BROWSER_FILE_SYSTEM_MOUNT_POINTS_H_
pilgrim4af8c212014-09-05 17:30:157
8#include <string>
9#include <vector>
10
Victor Costanfeaee8cf72018-12-28 00:39:1511#include "base/component_export.h"
pilgrim4af8c212014-09-05 17:30:1512#include "base/files/file_path.h"
DongJun Kimd6930ea2019-10-24 08:49:2513#include "storage/common/file_system/file_system_util.h"
pilgrim4af8c212014-09-05 17:30:1514
15class GURL;
Kyra Seevers011644882021-08-17 21:21:4716
17namespace blink {
18class StorageKey;
19}
20
Erik Anderson1606ab82019-02-04 22:15:2521namespace url {
22class Origin;
23}
pilgrim4af8c212014-09-05 17:30:1524
25namespace storage {
26class FileSystemMountOption;
27class FileSystemURL;
pilgrim4af8c212014-09-05 17:30:1528
29// Represents a set of mount points for File API.
Victor Costanfeaee8cf72018-12-28 00:39:1530class COMPONENT_EXPORT(STORAGE_BROWSER) MountPoints {
pilgrim4af8c212014-09-05 17:30:1531 public:
Victor Costanfeaee8cf72018-12-28 00:39:1532 struct COMPONENT_EXPORT(STORAGE_BROWSER) MountPointInfo {
pilgrim4af8c212014-09-05 17:30:1533 MountPointInfo();
34 MountPointInfo(const std::string& name, const base::FilePath& path);
35
36 // The name to be used to register the path. The registered file can
37 // be referred by a virtual path /<filesystem_id>/<name>.
38 // The name should NOT contain a path separator '/'.
39 std::string name;
40
41 // The path of the file.
42 base::FilePath path;
43
44 // For STL operation.
45 bool operator<(const MountPointInfo& that) const {
46 return name < that.name;
47 }
48 };
49
Austin Sullivan9de33582021-06-15 06:05:3150 MountPoints() = default;
51 MountPoints(const MountPoints&) = delete;
52 MountPoints& operator=(const MountPoints&) = delete;
53 virtual ~MountPoints() = default;
pilgrim4af8c212014-09-05 17:30:1554
55 // Revokes a mount point identified by |mount_name|.
56 // Returns false if the |mount_name| is not (no longer) registered.
57 // TODO(kinuko): Probably this should be rather named RevokeMountPoint.
58 virtual bool RevokeFileSystem(const std::string& mount_name) = 0;
59
60 // Returns true if the MountPoints implementation handles filesystems with
61 // the given mount type.
62 virtual bool HandlesFileSystemMountType(FileSystemType type) const = 0;
63
Kyra Seevers011644882021-08-17 21:21:4764 // TODO(https://crbug.com/1240603): Determine if MountPoints::CrackURL()
65 // and its overrides in child classes should be removed and replaced with
66 // FileSystemContext::CrackURL().
67 //
68 // Same as CreateCrackedFileSystemURL, but cracks a FileSystemURL created
69 // from `url` and `storage_key`.
70 virtual FileSystemURL CrackURL(
71 const GURL& url,
72 const blink::StorageKey& storage_key) const = 0;
pilgrim4af8c212014-09-05 17:30:1573
Joel Hockeyde49adac2020-11-03 20:34:2474 // Creates a FileSystemURL with the given origin, type and virtual path and
75 // tries to crack it as a part of one of the registered mount points. If the
76 // the URL is not valid or does not belong to any of the mount points
pilgrim4af8c212014-09-05 17:30:1577 // registered in this context, returns empty, invalid FileSystemURL.
78 virtual FileSystemURL CreateCrackedFileSystemURL(
Erik Anderson1606ab82019-02-04 22:15:2579 const url::Origin& origin,
Victor Costanb410d1a2020-02-12 05:03:2280 FileSystemType type,
Joel Hockeyde49adac2020-11-03 20:34:2481 const base::FilePath& virtual_path) const = 0;
pilgrim4af8c212014-09-05 17:30:1582
83 // Returns the mount point root path registered for a given |mount_name|.
84 // Returns false if the given |mount_name| is not valid.
85 virtual bool GetRegisteredPath(const std::string& mount_name,
86 base::FilePath* path) const = 0;
87
88 // Cracks the given |virtual_path| (which is the path part of a filesystem URL
89 // without '/external' or '/isolated' prefix part) and populates the
90 // |mount_name|, |type|, and |path| if the <mount_name> part embedded in
91 // the |virtual_path| (i.e. the first component of the |virtual_path|) is a
92 // valid registered filesystem ID or mount name for an existing mount point.
93 //
94 // Returns false if the given virtual_path cannot be cracked.
95 //
96 // Note that |path| is set to empty paths if the filesystem type is isolated
97 // and |virtual_path| has no <relative_path> part (i.e. pointing to the
98 // virtual root).
99 virtual bool CrackVirtualPath(const base::FilePath& virtual_path,
100 std::string* mount_name,
101 FileSystemType* type,
102 std::string* cracked_id,
103 base::FilePath* path,
104 FileSystemMountOption* mount_option) const = 0;
105
106 protected:
107 friend class FileSystemContext;
108
109 // Same as CrackURL and CreateCrackedFileSystemURL, but cracks the url already
110 // instantiated as the FileSystemURL class. This is internally used for nested
111 // URL cracking in FileSystemContext.
112 virtual FileSystemURL CrackFileSystemURL(const FileSystemURL& url) const = 0;
pilgrim4af8c212014-09-05 17:30:15113};
114
115} // namespace storage
116
DongJun Kimfebb3c22019-10-21 02:08:06117#endif // STORAGE_BROWSER_FILE_SYSTEM_MOUNT_POINTS_H_