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_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_
6 #define WEBKIT_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/synchronization/lock.h"
16 #include "webkit/fileapi/file_system_mount_point_provider.h"
17 #include "webkit/quota/special_storage_policy.h"
18 #include "webkit/storage/webkit_storage_export.h"
21 class AsyncFileUtilAdapter
;
22 class CopyOrMoveFileValidatorFactory
;
23 class ExternalMountPoints
;
24 class FileSystemFileUtil
;
26 class IsolatedContext
;
31 class FileAccessPermissions
;
33 // An interface to provide local filesystem paths.
34 class WEBKIT_STORAGE_EXPORT CrosMountPointProvider
35 : public fileapi::ExternalFileSystemMountPointProvider
{
37 using fileapi::FileSystemMountPointProvider::ValidateFileSystemCallback
;
38 using fileapi::FileSystemMountPointProvider::DeleteFileSystemCallback
;
40 // CrosMountPointProvider will take an ownership of a |mount_points|
41 // reference. On the other hand, |system_mount_points| will be kept as a raw
42 // pointer and it should outlive CrosMountPointProvider instance.
43 CrosMountPointProvider(
44 scoped_refptr
<quota::SpecialStoragePolicy
> special_storage_policy
,
45 scoped_refptr
<fileapi::ExternalMountPoints
> mount_points
,
46 fileapi::ExternalMountPoints
* system_mount_points
);
47 virtual ~CrosMountPointProvider();
49 // Returns true if CrosMountpointProvider can handle |url|, i.e. its
50 // file system type matches with what this provider supports.
51 // This could be called on any threads.
52 static bool CanHandleURL(const fileapi::FileSystemURL
& url
);
54 // fileapi::FileSystemMountPointProvider overrides.
55 virtual void ValidateFileSystemRoot(
56 const GURL
& origin_url
,
57 fileapi::FileSystemType type
,
59 const ValidateFileSystemCallback
& callback
) OVERRIDE
;
60 virtual base::FilePath
GetFileSystemRootPathOnFileThread(
61 const fileapi::FileSystemURL
& url
,
62 bool create
) OVERRIDE
;
63 virtual fileapi::FileSystemFileUtil
* GetFileUtil(
64 fileapi::FileSystemType type
) OVERRIDE
;
65 virtual fileapi::AsyncFileUtil
* GetAsyncFileUtil(
66 fileapi::FileSystemType type
) OVERRIDE
;
67 virtual fileapi::CopyOrMoveFileValidatorFactory
*
68 GetCopyOrMoveFileValidatorFactory(
69 fileapi::FileSystemType type
,
70 base::PlatformFileError
* error_code
) OVERRIDE
;
71 virtual void InitializeCopyOrMoveFileValidatorFactory(
72 fileapi::FileSystemType type
,
73 scoped_ptr
<fileapi::CopyOrMoveFileValidatorFactory
> factory
) OVERRIDE
;
74 virtual fileapi::FilePermissionPolicy
GetPermissionPolicy(
75 const fileapi::FileSystemURL
& url
,
76 int permissions
) const OVERRIDE
;
77 virtual fileapi::FileSystemOperation
* CreateFileSystemOperation(
78 const fileapi::FileSystemURL
& url
,
79 fileapi::FileSystemContext
* context
,
80 base::PlatformFileError
* error_code
) const OVERRIDE
;
81 virtual scoped_ptr
<webkit_blob::FileStreamReader
> CreateFileStreamReader(
82 const fileapi::FileSystemURL
& path
,
84 const base::Time
& expected_modification_time
,
85 fileapi::FileSystemContext
* context
) const OVERRIDE
;
86 virtual scoped_ptr
<fileapi::FileStreamWriter
> CreateFileStreamWriter(
87 const fileapi::FileSystemURL
& url
,
89 fileapi::FileSystemContext
* context
) const OVERRIDE
;
90 virtual fileapi::FileSystemQuotaUtil
* GetQuotaUtil() OVERRIDE
;
91 virtual void DeleteFileSystem(
92 const GURL
& origin_url
,
93 fileapi::FileSystemType type
,
94 fileapi::FileSystemContext
* context
,
95 const DeleteFileSystemCallback
& callback
) OVERRIDE
;
97 // fileapi::ExternalFileSystemMountPointProvider overrides.
98 virtual bool IsAccessAllowed(const fileapi::FileSystemURL
& url
)
100 virtual std::vector
<base::FilePath
> GetRootDirectories() const OVERRIDE
;
101 virtual void GrantFullAccessToExtension(
102 const std::string
& extension_id
) OVERRIDE
;
103 virtual void GrantFileAccessToExtension(
104 const std::string
& extension_id
,
105 const base::FilePath
& virtual_path
) OVERRIDE
;
106 virtual void RevokeAccessForExtension(
107 const std::string
& extension_id
) OVERRIDE
;
108 virtual bool GetVirtualPath(const base::FilePath
& filesystem_path
,
109 base::FilePath
* virtual_path
) OVERRIDE
;
112 fileapi::RemoteFileSystemProxyInterface
* GetRemoteProxy(
113 const std::string
& mount_name
) const;
115 scoped_refptr
<quota::SpecialStoragePolicy
> special_storage_policy_
;
116 scoped_ptr
<FileAccessPermissions
> file_access_permissions_
;
117 scoped_ptr
<fileapi::AsyncFileUtilAdapter
> local_file_util_
;
119 // Mount points specific to the owning context.
121 // Add/Remove MountPoints will affect only these mount points.
123 // It is legal to have mount points with the same name as in
124 // system_mount_points_. Also, mount point paths may overlap with mount point
125 // paths in system_mount_points_. In both cases mount points in
126 // |mount_points_| will have a priority.
127 // E.g. if |mount_points_| map 'foo1' to '/foo/foo1' and
128 // |file_system_mount_points_| map 'xxx' to '/foo/foo1/xxx', |GetVirtualPaths|
129 // will resolve '/foo/foo1/xxx/yyy' as 'foo1/xxx/yyy' (i.e. the mapping from
130 // |mount_points_| will be used).
131 scoped_refptr
<fileapi::ExternalMountPoints
> mount_points_
;
133 // Globally visible mount points. System MountPonts instance should outlive
134 // all CrosMountPointProvider instances, so raw pointer is safe.
135 fileapi::ExternalMountPoints
* system_mount_points_
;
137 DISALLOW_COPY_AND_ASSIGN(CrosMountPointProvider
);
140 } // namespace chromeos
142 #endif // WEBKIT_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_