blob: 4fb761f3480eeab7af05b941646a0f27df18369a [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"
avi5caf646e2015-12-21 21:21:5013#include "base/macros.h"
DongJun Kimd6930ea2019-10-24 08:49:2514#include "storage/common/file_system/file_system_util.h"
pilgrim4af8c212014-09-05 17:30:1515
16class GURL;
Erik Anderson1606ab82019-02-04 22:15:2517namespace url {
18class Origin;
19}
pilgrim4af8c212014-09-05 17:30:1520
21namespace storage {
22class FileSystemMountOption;
23class FileSystemURL;
pilgrim4af8c212014-09-05 17:30:1524
25// Represents a set of mount points for File API.
Victor Costanfeaee8cf72018-12-28 00:39:1526class COMPONENT_EXPORT(STORAGE_BROWSER) MountPoints {
pilgrim4af8c212014-09-05 17:30:1527 public:
Victor Costanfeaee8cf72018-12-28 00:39:1528 struct COMPONENT_EXPORT(STORAGE_BROWSER) MountPointInfo {
pilgrim4af8c212014-09-05 17:30:1529 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
46 MountPoints() {}
47 virtual ~MountPoints() {}
48
49 // Revokes a mount point identified by |mount_name|.
50 // Returns false if the |mount_name| is not (no longer) registered.
51 // TODO(kinuko): Probably this should be rather named RevokeMountPoint.
52 virtual bool RevokeFileSystem(const std::string& mount_name) = 0;
53
54 // Returns true if the MountPoints implementation handles filesystems with
55 // the given mount type.
56 virtual bool HandlesFileSystemMountType(FileSystemType type) const = 0;
57
58 // Same as CreateCrackedFileSystemURL, but cracks FileSystemURL created
59 // from |url|.
60 virtual FileSystemURL CrackURL(const GURL& url) const = 0;
61
62 // Creates a FileSystemURL with the given origin, type and path and tries to
63 // crack it as a part of one of the registered mount points.
64 // If the the URL is not valid or does not belong to any of the mount points
65 // registered in this context, returns empty, invalid FileSystemURL.
66 virtual FileSystemURL CreateCrackedFileSystemURL(
Erik Anderson1606ab82019-02-04 22:15:2567 const url::Origin& origin,
Victor Costanb410d1a2020-02-12 05:03:2268 FileSystemType type,
pilgrim4af8c212014-09-05 17:30:1569 const base::FilePath& path) const = 0;
70
71 // Returns the mount point root path registered for a given |mount_name|.
72 // Returns false if the given |mount_name| is not valid.
73 virtual bool GetRegisteredPath(const std::string& mount_name,
74 base::FilePath* path) const = 0;
75
76 // Cracks the given |virtual_path| (which is the path part of a filesystem URL
77 // without '/external' or '/isolated' prefix part) and populates the
78 // |mount_name|, |type|, and |path| if the <mount_name> part embedded in
79 // the |virtual_path| (i.e. the first component of the |virtual_path|) is a
80 // valid registered filesystem ID or mount name for an existing mount point.
81 //
82 // Returns false if the given virtual_path cannot be cracked.
83 //
84 // Note that |path| is set to empty paths if the filesystem type is isolated
85 // and |virtual_path| has no <relative_path> part (i.e. pointing to the
86 // virtual root).
87 virtual bool CrackVirtualPath(const base::FilePath& virtual_path,
88 std::string* mount_name,
89 FileSystemType* type,
90 std::string* cracked_id,
91 base::FilePath* path,
92 FileSystemMountOption* mount_option) const = 0;
93
94 protected:
95 friend class FileSystemContext;
96
97 // Same as CrackURL and CreateCrackedFileSystemURL, but cracks the url already
98 // instantiated as the FileSystemURL class. This is internally used for nested
99 // URL cracking in FileSystemContext.
100 virtual FileSystemURL CrackFileSystemURL(const FileSystemURL& url) const = 0;
101
102 private:
103 DISALLOW_COPY_AND_ASSIGN(MountPoints);
104};
105
106} // namespace storage
107
DongJun Kimfebb3c22019-10-21 02:08:06108#endif // STORAGE_BROWSER_FILE_SYSTEM_MOUNT_POINTS_H_