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.
5 #ifndef WEBKIT_FILEAPI_MOUNT_POINTS_H_
6 #define WEBKIT_FILEAPI_MOUNT_POINTS_H_
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "webkit/fileapi/file_system_util.h"
14 #include "webkit/storage/webkit_storage_export.h"
24 // Represents a set of mount points for File API.
25 class WEBKIT_STORAGE_EXPORT MountPoints
{
27 struct WEBKIT_STORAGE_EXPORT MountPointInfo
{
29 MountPointInfo(const std::string
& name
, const base::FilePath
& path
);
31 // The name to be used to register the path. The registered file can
32 // be referred by a virtual path /<filesystem_id>/<name>.
33 // The name should NOT contain a path separator '/'.
36 // The path of the file.
40 bool operator<(const MountPointInfo
& that
) const {
41 return name
< that
.name
;
46 virtual ~MountPoints() {}
48 // Revokes a mount point identified by |mount_name|.
49 // Returns false if the |mount_name| is not (no longer) registered.
50 // TODO(kinuko): Probably this should be rather named RevokeMountPoint.
51 virtual bool RevokeFileSystem(const std::string
& mount_name
) = 0;
53 // Returns true if the MountPoints implementation handles filesystems with
54 // the given mount type.
55 virtual bool HandlesFileSystemMountType(FileSystemType type
) const = 0;
57 // Same as CreateCrackedFileSystemURL, but cracks FileSystemURL created
59 virtual FileSystemURL
CrackURL(const GURL
& url
) const = 0;
61 // Creates a FileSystemURL with the given origin, type and path and tries to
62 // crack it as a part of one of the registered mount points.
63 // If the the URL is not valid or does not belong to any of the mount points
64 // registered in this context, returns empty, invalid FileSystemURL.
65 virtual FileSystemURL
CreateCrackedFileSystemURL(
67 fileapi::FileSystemType type
,
68 const base::FilePath
& path
) const = 0;
70 // Returns the mount point root path registered for a given |mount_name|.
71 // Returns false if the given |mount_name| is not valid.
72 virtual bool GetRegisteredPath(const std::string
& mount_name
,
73 base::FilePath
* path
) const = 0;
75 // Cracks the given |virtual_path| (which is the path part of a filesystem URL
76 // without '/external' or '/isolated' prefix part) and populates the
77 // |mount_name|, |type|, and |path| if the <mount_name> part embedded in
78 // the |virtual_path| (i.e. the first component of the |virtual_path|) is a
79 // valid registered filesystem ID or mount name for an existing mount point.
81 // Returns false if the given virtual_path cannot be cracked.
83 // Note that |path| is set to empty paths if the filesystem type is isolated
84 // and |virtual_path| has no <relative_path> part (i.e. pointing to the
86 virtual bool CrackVirtualPath(const base::FilePath
& virtual_path
,
87 std::string
* mount_name
,
89 base::FilePath
* path
) const = 0;
92 friend class FileSystemContext
;
94 // Same as CrackURL and CreateCrackedFileSystemURL, but cracks the url already
95 // instantiated as the FileSystemURL class. This is internally used for nested
96 // URL cracking in FileSystemContext.
97 virtual FileSystemURL
CrackFileSystemURL(const FileSystemURL
& url
) const = 0;
100 DISALLOW_COPY_AND_ASSIGN(MountPoints
);
103 } // namespace fileapi
105 #endif // WEBKIT_FILEAPI_MOUNT_POINTS_H_