1 // Copyright 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 CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_SYSTEM_BACKEND_H_
6 #define CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_SYSTEM_BACKEND_H_
11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "storage/browser/fileapi/file_system_backend.h"
16 #include "storage/browser/fileapi/task_runner_bound_observer_list.h"
17 #include "storage/common/fileapi/file_system_types.h"
20 class CopyOrMoveFileValidatorFactory
;
21 class ExternalMountPoints
;
24 } // namespace storage
28 class FileSystemBackendDelegate
;
29 class FileAccessPermissions
;
31 // FileSystemBackend is a Chrome OS specific implementation of
32 // ExternalFileSystemBackend. This class is responsible for a
33 // number of things, including:
35 // - Add system mount points
36 // - Grant/revoke/check file access permissions
37 // - Create FileSystemOperation per file system type
38 // - Create FileStreamReader/Writer per file system type
40 // Chrome OS specific mount points:
42 // "Downloads" is a mount point for user's Downloads directory on the local
43 // disk, where downloaded files are stored by default.
45 // "archive" is a mount point for an archive file, such as a zip file. This
46 // mount point exposes contents of an archive file via cros_disks and AVFS
47 // <http://avf.sourceforge.net/>.
49 // "removable" is a mount point for removable media such as an SD card.
50 // Insertion and removal of removable media are handled by cros_disks.
52 // "oem" is a read-only mount point for a directory containing OEM data.
54 // "drive" is a mount point for Google Drive. Drive is integrated with the
55 // FileSystem API layer via drive::FileSystemProxy. This mount point is added
56 // by drive::DriveIntegrationService.
58 // These mount points are placed under the "external" namespace, and file
59 // system URLs for these mount points look like:
61 // filesystem:<origin>/external/<mount_name>/...
63 class FileSystemBackend
: public storage::ExternalFileSystemBackend
{
65 using storage::FileSystemBackend::OpenFileSystemCallback
;
67 // FileSystemBackend will take an ownership of a |mount_points|
68 // reference. On the other hand, |system_mount_points| will be kept as a raw
69 // pointer and it should outlive FileSystemBackend instance.
70 // The ownerships of |drive_delegate| and |file_system_provider_delegate| are
73 FileSystemBackendDelegate
* drive_delegate
,
74 FileSystemBackendDelegate
* file_system_provider_delegate
,
75 FileSystemBackendDelegate
* mtp_delegate
,
76 scoped_refptr
<storage::ExternalMountPoints
> mount_points
,
77 storage::ExternalMountPoints
* system_mount_points
);
78 ~FileSystemBackend() override
;
80 // Adds system mount points, such as "archive", and "removable". This
81 // function is no-op if these mount points are already present.
82 void AddSystemMountPoints();
84 // Returns true if CrosMountpointProvider can handle |url|, i.e. its
85 // file system type matches with what this provider supports.
86 // This could be called on any threads.
87 static bool CanHandleURL(const storage::FileSystemURL
& url
);
89 // storage::FileSystemBackend overrides.
90 bool CanHandleType(storage::FileSystemType type
) const override
;
91 void Initialize(storage::FileSystemContext
* context
) override
;
92 void ResolveURL(const storage::FileSystemURL
& url
,
93 storage::OpenFileSystemMode mode
,
94 const OpenFileSystemCallback
& callback
) override
;
95 storage::AsyncFileUtil
* GetAsyncFileUtil(
96 storage::FileSystemType type
) override
;
97 storage::WatcherManager
* GetWatcherManager(
98 storage::FileSystemType type
) override
;
99 storage::CopyOrMoveFileValidatorFactory
* GetCopyOrMoveFileValidatorFactory(
100 storage::FileSystemType type
,
101 base::File::Error
* error_code
) override
;
102 storage::FileSystemOperation
* CreateFileSystemOperation(
103 const storage::FileSystemURL
& url
,
104 storage::FileSystemContext
* context
,
105 base::File::Error
* error_code
) const override
;
106 bool SupportsStreaming(const storage::FileSystemURL
& url
) const override
;
107 bool HasInplaceCopyImplementation(
108 storage::FileSystemType type
) const override
;
109 scoped_ptr
<storage::FileStreamReader
> CreateFileStreamReader(
110 const storage::FileSystemURL
& path
,
112 int64 max_bytes_to_read
,
113 const base::Time
& expected_modification_time
,
114 storage::FileSystemContext
* context
) const override
;
115 scoped_ptr
<storage::FileStreamWriter
> CreateFileStreamWriter(
116 const storage::FileSystemURL
& url
,
118 storage::FileSystemContext
* context
) const override
;
119 storage::FileSystemQuotaUtil
* GetQuotaUtil() override
;
120 const storage::UpdateObserverList
* GetUpdateObservers(
121 storage::FileSystemType type
) const override
;
122 const storage::ChangeObserverList
* GetChangeObservers(
123 storage::FileSystemType type
) const override
;
124 const storage::AccessObserverList
* GetAccessObservers(
125 storage::FileSystemType type
) const override
;
127 // storage::ExternalFileSystemBackend overrides.
128 bool IsAccessAllowed(const storage::FileSystemURL
& url
) const override
;
129 std::vector
<base::FilePath
> GetRootDirectories() const override
;
130 void GrantFileAccessToExtension(const std::string
& extension_id
,
131 const base::FilePath
& virtual_path
) override
;
132 void RevokeAccessForExtension(const std::string
& extension_id
) override
;
133 bool GetVirtualPath(const base::FilePath
& filesystem_path
,
134 base::FilePath
* virtual_path
) const override
;
135 void GetRedirectURLForContents(
136 const storage::FileSystemURL
& url
,
137 const storage::URLCallback
& callback
) const override
;
138 storage::FileSystemURL
CreateInternalURL(
139 storage::FileSystemContext
* context
,
140 const base::FilePath
& entry_path
) const override
;
143 scoped_ptr
<FileAccessPermissions
> file_access_permissions_
;
144 scoped_ptr
<storage::AsyncFileUtil
> local_file_util_
;
146 // The delegate instance for the drive file system related operations.
147 scoped_ptr
<FileSystemBackendDelegate
> drive_delegate_
;
149 // The delegate instance for the provided file system related operations.
150 scoped_ptr
<FileSystemBackendDelegate
> file_system_provider_delegate_
;
152 // The delegate instance for the MTP file system related operations.
153 scoped_ptr
<FileSystemBackendDelegate
> mtp_delegate_
;
155 // Mount points specific to the owning context (i.e. per-profile mount
158 // It is legal to have mount points with the same name as in
159 // system_mount_points_. Also, mount point paths may overlap with mount point
160 // paths in system_mount_points_. In both cases mount points in
161 // |mount_points_| will have a priority.
162 // E.g. if |mount_points_| map 'foo1' to '/foo/foo1' and
163 // |file_system_mount_points_| map 'xxx' to '/foo/foo1/xxx', |GetVirtualPaths|
164 // will resolve '/foo/foo1/xxx/yyy' as 'foo1/xxx/yyy' (i.e. the mapping from
165 // |mount_points_| will be used).
166 scoped_refptr
<storage::ExternalMountPoints
> mount_points_
;
168 // Globally visible mount points. System MountPonts instance should outlive
169 // all FileSystemBackend instances, so raw pointer is safe.
170 storage::ExternalMountPoints
* system_mount_points_
;
172 DISALLOW_COPY_AND_ASSIGN(FileSystemBackend
);
175 } // namespace chromeos
177 #endif // CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_SYSTEM_BACKEND_H_