Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / chromeos / fileapi / file_system_backend.h
blob838c2235dbd0df86f5062e634414b58bae6201c6
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_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "storage/browser/fileapi/file_system_backend.h"
15 #include "storage/browser/fileapi/task_runner_bound_observer_list.h"
16 #include "storage/browser/quota/special_storage_policy.h"
17 #include "storage/common/fileapi/file_system_types.h"
19 namespace storage {
20 class CopyOrMoveFileValidatorFactory;
21 class ExternalMountPoints;
22 class FileSystemURL;
23 class WatcherManager;
24 } // namespace storage
26 namespace chromeos {
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 {
64 public:
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
71 // also taken.
72 FileSystemBackend(
73 FileSystemBackendDelegate* drive_delegate,
74 FileSystemBackendDelegate* file_system_provider_delegate,
75 FileSystemBackendDelegate* mtp_delegate,
76 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy,
77 scoped_refptr<storage::ExternalMountPoints> mount_points,
78 storage::ExternalMountPoints* system_mount_points);
79 virtual ~FileSystemBackend();
81 // Adds system mount points, such as "archive", and "removable". This
82 // function is no-op if these mount points are already present.
83 void AddSystemMountPoints();
85 // Returns true if CrosMountpointProvider can handle |url|, i.e. its
86 // file system type matches with what this provider supports.
87 // This could be called on any threads.
88 static bool CanHandleURL(const storage::FileSystemURL& url);
90 // storage::FileSystemBackend overrides.
91 virtual bool CanHandleType(storage::FileSystemType type) const override;
92 virtual void Initialize(storage::FileSystemContext* context) override;
93 virtual void ResolveURL(const storage::FileSystemURL& url,
94 storage::OpenFileSystemMode mode,
95 const OpenFileSystemCallback& callback) override;
96 virtual storage::AsyncFileUtil* GetAsyncFileUtil(
97 storage::FileSystemType type) override;
98 virtual storage::WatcherManager* GetWatcherManager(
99 storage::FileSystemType type) override;
100 virtual storage::CopyOrMoveFileValidatorFactory*
101 GetCopyOrMoveFileValidatorFactory(storage::FileSystemType type,
102 base::File::Error* error_code) override;
103 virtual storage::FileSystemOperation* CreateFileSystemOperation(
104 const storage::FileSystemURL& url,
105 storage::FileSystemContext* context,
106 base::File::Error* error_code) const override;
107 virtual bool SupportsStreaming(
108 const storage::FileSystemURL& url) const override;
109 virtual bool HasInplaceCopyImplementation(
110 storage::FileSystemType type) const override;
111 virtual scoped_ptr<storage::FileStreamReader> CreateFileStreamReader(
112 const storage::FileSystemURL& path,
113 int64 offset,
114 int64 max_bytes_to_read,
115 const base::Time& expected_modification_time,
116 storage::FileSystemContext* context) const override;
117 virtual scoped_ptr<storage::FileStreamWriter> CreateFileStreamWriter(
118 const storage::FileSystemURL& url,
119 int64 offset,
120 storage::FileSystemContext* context) const override;
121 virtual storage::FileSystemQuotaUtil* GetQuotaUtil() override;
122 virtual const storage::UpdateObserverList* GetUpdateObservers(
123 storage::FileSystemType type) const override;
124 virtual const storage::ChangeObserverList* GetChangeObservers(
125 storage::FileSystemType type) const override;
126 virtual const storage::AccessObserverList* GetAccessObservers(
127 storage::FileSystemType type) const override;
129 // storage::ExternalFileSystemBackend overrides.
130 virtual bool IsAccessAllowed(
131 const storage::FileSystemURL& url) const override;
132 virtual std::vector<base::FilePath> GetRootDirectories() const override;
133 virtual void GrantFullAccessToExtension(
134 const std::string& extension_id) override;
135 virtual void GrantFileAccessToExtension(
136 const std::string& extension_id,
137 const base::FilePath& virtual_path) override;
138 virtual void RevokeAccessForExtension(
139 const std::string& extension_id) override;
140 virtual bool GetVirtualPath(const base::FilePath& filesystem_path,
141 base::FilePath* virtual_path) override;
142 virtual void GetRedirectURLForContents(
143 const storage::FileSystemURL& url,
144 const storage::URLCallback& callback) override;
146 private:
147 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
148 scoped_ptr<FileAccessPermissions> file_access_permissions_;
149 scoped_ptr<storage::AsyncFileUtil> local_file_util_;
151 // The delegate instance for the drive file system related operations.
152 scoped_ptr<FileSystemBackendDelegate> drive_delegate_;
154 // The delegate instance for the provided file system related operations.
155 scoped_ptr<FileSystemBackendDelegate> file_system_provider_delegate_;
157 // The delegate instance for the MTP file system related operations.
158 scoped_ptr<FileSystemBackendDelegate> mtp_delegate_;
160 // Mount points specific to the owning context (i.e. per-profile mount
161 // points).
163 // It is legal to have mount points with the same name as in
164 // system_mount_points_. Also, mount point paths may overlap with mount point
165 // paths in system_mount_points_. In both cases mount points in
166 // |mount_points_| will have a priority.
167 // E.g. if |mount_points_| map 'foo1' to '/foo/foo1' and
168 // |file_system_mount_points_| map 'xxx' to '/foo/foo1/xxx', |GetVirtualPaths|
169 // will resolve '/foo/foo1/xxx/yyy' as 'foo1/xxx/yyy' (i.e. the mapping from
170 // |mount_points_| will be used).
171 scoped_refptr<storage::ExternalMountPoints> mount_points_;
173 // Globally visible mount points. System MountPonts instance should outlive
174 // all FileSystemBackend instances, so raw pointer is safe.
175 storage::ExternalMountPoints* system_mount_points_;
177 DISALLOW_COPY_AND_ASSIGN(FileSystemBackend);
180 } // namespace chromeos
182 #endif // CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_SYSTEM_BACKEND_H_