| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef WEBKIT_BROWSER_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ | |
| 6 #define WEBKIT_BROWSER_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 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/browser/fileapi/file_system_mount_point_provider.h" | |
| 17 #include "webkit/browser/quota/special_storage_policy.h" | |
| 18 #include "webkit/browser/webkit_storage_browser_export.h" | |
| 19 #include "webkit/common/fileapi/file_system_types.h" | |
| 20 | |
| 21 namespace fileapi { | |
| 22 class AsyncFileUtilAdapter; | |
| 23 class CopyOrMoveFileValidatorFactory; | |
| 24 class ExternalMountPoints; | |
| 25 class FileSystemFileUtil; | |
| 26 class FileSystemURL; | |
| 27 class IsolatedContext; | |
| 28 } | |
| 29 | |
| 30 namespace chromeos { | |
| 31 | |
| 32 class FileAccessPermissions; | |
| 33 | |
| 34 // CrosMountPointProvider is a Chrome OS specific implementation of | |
| 35 // ExternalFileSystemMountPointProvider. This class is responsible for a | |
| 36 // number of things, including: | |
| 37 // | |
| 38 // - Add system mount points | |
| 39 // - Grant/revoke/check file access permissions | |
| 40 // - Create FileSystemOperation per file system type | |
| 41 // - Create FileStreamReader/Writer per file system type | |
| 42 // | |
| 43 // Chrome OS specific mount points: | |
| 44 // | |
| 45 // "Downloads" is a mount point for user's Downloads directory on the local | |
| 46 // disk, where downloaded files are stored by default. | |
| 47 // | |
| 48 // "archive" is a mount point for an archive file, such as a zip file. This | |
| 49 // mount point exposes contents of an archive file via cros_disks and AVFS | |
| 50 // <http://avf.sourceforge.net/>. | |
| 51 // | |
| 52 // "removable" is a mount point for removable media such as an SD card. | |
| 53 // Insertion and removal of removable media are handled by cros_disks. | |
| 54 // | |
| 55 // "oem" is a read-only mount point for a directory containing OEM data. | |
| 56 // | |
| 57 // "drive" is a mount point for Google Drive. Drive is integrated with the | |
| 58 // FileSystem API layer via drive::FileSystemProxy. This mount point is added | |
| 59 // by drive::DriveIntegrationService. | |
| 60 // | |
| 61 // These mount points are placed under the "external" namespace, and file | |
| 62 // system URLs for these mount points look like: | |
| 63 // | |
| 64 // filesystem:<origin>/external/<mount_name>/... | |
| 65 // | |
| 66 class WEBKIT_STORAGE_BROWSER_EXPORT CrosMountPointProvider | |
| 67 : public fileapi::ExternalFileSystemMountPointProvider { | |
| 68 public: | |
| 69 using fileapi::FileSystemMountPointProvider::OpenFileSystemCallback; | |
| 70 using fileapi::FileSystemMountPointProvider::DeleteFileSystemCallback; | |
| 71 | |
| 72 // CrosMountPointProvider will take an ownership of a |mount_points| | |
| 73 // reference. On the other hand, |system_mount_points| will be kept as a raw | |
| 74 // pointer and it should outlive CrosMountPointProvider instance. | |
| 75 CrosMountPointProvider( | |
| 76 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | |
| 77 scoped_refptr<fileapi::ExternalMountPoints> mount_points, | |
| 78 fileapi::ExternalMountPoints* system_mount_points); | |
| 79 virtual ~CrosMountPointProvider(); | |
| 80 | |
| 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(); | |
| 84 | |
| 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 fileapi::FileSystemURL& url); | |
| 89 | |
| 90 // fileapi::FileSystemMountPointProvider overrides. | |
| 91 virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; | |
| 92 virtual void OpenFileSystem( | |
| 93 const GURL& origin_url, | |
| 94 fileapi::FileSystemType type, | |
| 95 fileapi::OpenFileSystemMode mode, | |
| 96 const OpenFileSystemCallback& callback) OVERRIDE; | |
| 97 virtual fileapi::FileSystemFileUtil* GetFileUtil( | |
| 98 fileapi::FileSystemType type) OVERRIDE; | |
| 99 virtual fileapi::AsyncFileUtil* GetAsyncFileUtil( | |
| 100 fileapi::FileSystemType type) OVERRIDE; | |
| 101 virtual fileapi::CopyOrMoveFileValidatorFactory* | |
| 102 GetCopyOrMoveFileValidatorFactory( | |
| 103 fileapi::FileSystemType type, | |
| 104 base::PlatformFileError* error_code) OVERRIDE; | |
| 105 virtual fileapi::FilePermissionPolicy GetPermissionPolicy( | |
| 106 const fileapi::FileSystemURL& url, | |
| 107 int permissions) const OVERRIDE; | |
| 108 virtual fileapi::FileSystemOperation* CreateFileSystemOperation( | |
| 109 const fileapi::FileSystemURL& url, | |
| 110 fileapi::FileSystemContext* context, | |
| 111 base::PlatformFileError* error_code) const OVERRIDE; | |
| 112 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( | |
| 113 const fileapi::FileSystemURL& path, | |
| 114 int64 offset, | |
| 115 const base::Time& expected_modification_time, | |
| 116 fileapi::FileSystemContext* context) const OVERRIDE; | |
| 117 virtual scoped_ptr<fileapi::FileStreamWriter> CreateFileStreamWriter( | |
| 118 const fileapi::FileSystemURL& url, | |
| 119 int64 offset, | |
| 120 fileapi::FileSystemContext* context) const OVERRIDE; | |
| 121 virtual fileapi::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; | |
| 122 virtual void DeleteFileSystem( | |
| 123 const GURL& origin_url, | |
| 124 fileapi::FileSystemType type, | |
| 125 fileapi::FileSystemContext* context, | |
| 126 const DeleteFileSystemCallback& callback) OVERRIDE; | |
| 127 | |
| 128 // fileapi::ExternalFileSystemMountPointProvider overrides. | |
| 129 virtual bool IsAccessAllowed(const fileapi::FileSystemURL& url) | |
| 130 const OVERRIDE; | |
| 131 virtual std::vector<base::FilePath> GetRootDirectories() const OVERRIDE; | |
| 132 virtual void GrantFullAccessToExtension( | |
| 133 const std::string& extension_id) OVERRIDE; | |
| 134 virtual void GrantFileAccessToExtension( | |
| 135 const std::string& extension_id, | |
| 136 const base::FilePath& virtual_path) OVERRIDE; | |
| 137 virtual void RevokeAccessForExtension( | |
| 138 const std::string& extension_id) OVERRIDE; | |
| 139 virtual bool GetVirtualPath(const base::FilePath& filesystem_path, | |
| 140 base::FilePath* virtual_path) OVERRIDE; | |
| 141 | |
| 142 private: | |
| 143 fileapi::RemoteFileSystemProxyInterface* GetRemoteProxy( | |
| 144 const std::string& mount_name) const; | |
| 145 base::FilePath GetFileSystemRootPath(const fileapi::FileSystemURL& url) const; | |
| 146 | |
| 147 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | |
| 148 scoped_ptr<FileAccessPermissions> file_access_permissions_; | |
| 149 scoped_ptr<fileapi::AsyncFileUtilAdapter> local_file_util_; | |
| 150 | |
| 151 // Mount points specific to the owning context (i.e. per-profile mount | |
| 152 // points). | |
| 153 // | |
| 154 // It is legal to have mount points with the same name as in | |
| 155 // system_mount_points_. Also, mount point paths may overlap with mount point | |
| 156 // paths in system_mount_points_. In both cases mount points in | |
| 157 // |mount_points_| will have a priority. | |
| 158 // E.g. if |mount_points_| map 'foo1' to '/foo/foo1' and | |
| 159 // |file_system_mount_points_| map 'xxx' to '/foo/foo1/xxx', |GetVirtualPaths| | |
| 160 // will resolve '/foo/foo1/xxx/yyy' as 'foo1/xxx/yyy' (i.e. the mapping from | |
| 161 // |mount_points_| will be used). | |
| 162 scoped_refptr<fileapi::ExternalMountPoints> mount_points_; | |
| 163 | |
| 164 // Globally visible mount points. System MountPonts instance should outlive | |
| 165 // all CrosMountPointProvider instances, so raw pointer is safe. | |
| 166 fileapi::ExternalMountPoints* system_mount_points_; | |
| 167 | |
| 168 DISALLOW_COPY_AND_ASSIGN(CrosMountPointProvider); | |
| 169 }; | |
| 170 | |
| 171 } // namespace chromeos | |
| 172 | |
| 173 #endif // WEBKIT_BROWSER_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ | |
| OLD | NEW |