1 // Copyright (c) 2012 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_FILE_SYSTEM_MOUNT_POINT_PROVIDER_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_MOUNT_POINT_PROVIDER_H_
11 #include "base/callback_forward.h"
12 #include "base/file_path.h"
13 #include "base/platform_file.h"
14 #include "webkit/fileapi/fileapi_export.h"
15 #include "webkit/fileapi/file_system_types.h"
17 namespace webkit_blob
{
18 class FileStreamReader
;
24 class FileStreamWriter
;
25 class FileSystemContext
;
26 class FileSystemFileUtil
;
27 class FileSystemOperationInterface
;
28 class FileSystemQuotaUtil
;
29 class RemoteFileSystemProxyInterface
;
31 // An interface to provide mount-point-specific path-related utilities
32 // and specialized FileSystemFileUtil instance.
33 class FILEAPI_EXPORT FileSystemMountPointProvider
{
35 // Callback for ValidateFileSystemRoot.
36 typedef base::Callback
<void(base::PlatformFileError error
)>
37 ValidateFileSystemCallback
;
38 virtual ~FileSystemMountPointProvider() {}
40 // Validates the filesystem for the given |origin_url| and |type|.
41 // This verifies if it is allowed to request (or create) the filesystem
42 // and if it can access (or create) the root directory of the mount point.
43 // If |create| is true this may also create the root directory for
44 // the filesystem if it doesn't exist.
45 virtual void ValidateFileSystemRoot(
46 const GURL
& origin_url
,
49 const ValidateFileSystemCallback
& callback
) = 0;
51 // Retrieves the root path of the filesystem specified by the given
52 // |origin_url| and |type| on the file thread.
53 // If |create| is true this may also create the root directory for
54 // the filesystem if it doesn't exist.
55 virtual FilePath
GetFileSystemRootPathOnFileThread(
56 const GURL
& origin_url
,
58 const FilePath
& virtual_path
,
61 // Checks if access to |virtual_path| is allowed from |origin_url|.
62 virtual bool IsAccessAllowed(const GURL
& origin_url
,
64 const FilePath
& virtual_path
) = 0;
66 // Checks if a given |name| contains any restricted names/chars in it.
67 // Callable on any thread.
68 virtual bool IsRestrictedFileName(const FilePath
& filename
) const = 0;
70 // Returns the specialized FileSystemFileUtil for this mount point.
71 virtual FileSystemFileUtil
* GetFileUtil() = 0;
73 // Returns file path we should use to check access permissions for
75 virtual FilePath
GetPathForPermissionsCheck(const FilePath
& virtual_path
)
78 // Returns a new instance of the specialized FileSystemOperation for this
79 // mount point based on the given triplet of |origin_url|, |file_system_type|
80 // and |virtual_path|.
81 // This method is usually dispatched by
82 // FileSystemContext::CreateFileSystemOperation.
83 virtual FileSystemOperationInterface
* CreateFileSystemOperation(
84 const FileSystemURL
& url
,
85 FileSystemContext
* context
) const = 0;
87 // Creates a new file stream reader for a given filesystem URL |url| with an
89 // The returned object must be owned and managed by the caller.
90 // This method itself does *not* check if the given path exists and is a
92 virtual webkit_blob::FileStreamReader
* CreateFileStreamReader(
93 const FileSystemURL
& url
,
95 FileSystemContext
* context
) const = 0;
97 // Creates a new file stream writer for a given filesystem URL |url| with an
99 // The returned object must be owned and managed by the caller.
100 // This method itself does *not* check if the given path exists and is a
102 virtual FileStreamWriter
* CreateFileStreamWriter(
103 const FileSystemURL
& url
,
105 FileSystemContext
* context
) const = 0;
107 // Returns the specialized FileSystemQuotaUtil for this mount point.
108 // This could return NULL if this mount point does not support quota.
109 virtual FileSystemQuotaUtil
* GetQuotaUtil() = 0;
112 // An interface to control external file system access permissions.
113 class ExternalFileSystemMountPointProvider
114 : public FileSystemMountPointProvider
{
116 // Returns the list of top level directories that are exposed by this
117 // provider. This list is used to set appropriate child process file access
119 virtual std::vector
<FilePath
> GetRootDirectories() const = 0;
120 // Grant access to all external file system from extension identified with
122 virtual void GrantFullAccessToExtension(const std::string
& extension_id
) = 0;
123 // Grants access to |virtual_path| from |origin_url|.
124 virtual void GrantFileAccessToExtension(
125 const std::string
& extension_id
,
126 const FilePath
& virtual_path
) = 0;
127 // Revoke file access from extension identified with |extension_id|.
128 virtual void RevokeAccessForExtension(
129 const std::string
& extension_id
) = 0;
130 // Checks if a given |mount_point| already exists.
131 virtual bool HasMountPoint(const FilePath
& mount_point
) = 0;
132 // Adds a new local mount point.
133 virtual void AddLocalMountPoint(const FilePath
& mount_point
) = 0;
134 // Adds a new remote mount point.
135 virtual void AddRemoteMountPoint(
136 const FilePath
& mount_point
,
137 RemoteFileSystemProxyInterface
* remote_proxy
) = 0;
138 // Remove a mount point.
139 virtual void RemoveMountPoint(const FilePath
& mount_point
) = 0;
140 // Gets virtual path by known filesystem path. Returns false when filesystem
141 // path is not exposed by this provider.
142 virtual bool GetVirtualPath(const FilePath
& file_system_path
,
143 FilePath
* virtual_path
) = 0;
146 } // namespace fileapi
148 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_MOUNT_POINT_PROVIDER_H_