| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_SYSTEM_BACKEND_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_SYSTEM_BACKEND_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "webkit/browser/fileapi/file_system_mount_point_provider.h" | 16 #include "webkit/browser/fileapi/file_system_backend.h" |
| 17 #include "webkit/browser/quota/special_storage_policy.h" | 17 #include "webkit/browser/quota/special_storage_policy.h" |
| 18 #include "webkit/browser/webkit_storage_browser_export.h" | 18 #include "webkit/browser/webkit_storage_browser_export.h" |
| 19 #include "webkit/common/fileapi/file_system_types.h" | 19 #include "webkit/common/fileapi/file_system_types.h" |
| 20 | 20 |
| 21 namespace fileapi { | 21 namespace fileapi { |
| 22 class AsyncFileUtilAdapter; | 22 class AsyncFileUtilAdapter; |
| 23 class CopyOrMoveFileValidatorFactory; | 23 class CopyOrMoveFileValidatorFactory; |
| 24 class ExternalMountPoints; | 24 class ExternalMountPoints; |
| 25 class FileSystemFileUtil; | 25 class FileSystemFileUtil; |
| 26 class FileSystemURL; | 26 class FileSystemURL; |
| 27 class IsolatedContext; | 27 class IsolatedContext; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace chromeos { | 30 namespace chromeos { |
| 31 | 31 |
| 32 class CrosMountPointProviderDelegate; | 32 class FileSystemBackendDelegate; |
| 33 class FileAccessPermissions; | 33 class FileAccessPermissions; |
| 34 | 34 |
| 35 // CrosMountPointProvider is a Chrome OS specific implementation of | 35 // FileSystemBackend is a Chrome OS specific implementation of |
| 36 // ExternalFileSystemMountPointProvider. This class is responsible for a | 36 // ExternalFileSystemBackend. This class is responsible for a |
| 37 // number of things, including: | 37 // number of things, including: |
| 38 // | 38 // |
| 39 // - Add system mount points | 39 // - Add system mount points |
| 40 // - Grant/revoke/check file access permissions | 40 // - Grant/revoke/check file access permissions |
| 41 // - Create FileSystemOperation per file system type | 41 // - Create FileSystemOperation per file system type |
| 42 // - Create FileStreamReader/Writer per file system type | 42 // - Create FileStreamReader/Writer per file system type |
| 43 // | 43 // |
| 44 // Chrome OS specific mount points: | 44 // Chrome OS specific mount points: |
| 45 // | 45 // |
| 46 // "Downloads" is a mount point for user's Downloads directory on the local | 46 // "Downloads" is a mount point for user's Downloads directory on the local |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 // | 57 // |
| 58 // "drive" is a mount point for Google Drive. Drive is integrated with the | 58 // "drive" is a mount point for Google Drive. Drive is integrated with the |
| 59 // FileSystem API layer via drive::FileSystemProxy. This mount point is added | 59 // FileSystem API layer via drive::FileSystemProxy. This mount point is added |
| 60 // by drive::DriveIntegrationService. | 60 // by drive::DriveIntegrationService. |
| 61 // | 61 // |
| 62 // These mount points are placed under the "external" namespace, and file | 62 // These mount points are placed under the "external" namespace, and file |
| 63 // system URLs for these mount points look like: | 63 // system URLs for these mount points look like: |
| 64 // | 64 // |
| 65 // filesystem:<origin>/external/<mount_name>/... | 65 // filesystem:<origin>/external/<mount_name>/... |
| 66 // | 66 // |
| 67 class CrosMountPointProvider | 67 class FileSystemBackend : public fileapi::ExternalFileSystemBackend { |
| 68 : public fileapi::ExternalFileSystemMountPointProvider { | |
| 69 public: | 68 public: |
| 70 using fileapi::FileSystemMountPointProvider::OpenFileSystemCallback; | 69 using fileapi::FileSystemBackend::OpenFileSystemCallback; |
| 71 | 70 |
| 72 // CrosMountPointProvider will take an ownership of a |mount_points| | 71 // FileSystemBackend will take an ownership of a |mount_points| |
| 73 // reference. On the other hand, |system_mount_points| will be kept as a raw | 72 // reference. On the other hand, |system_mount_points| will be kept as a raw |
| 74 // pointer and it should outlive CrosMountPointProvider instance. | 73 // pointer and it should outlive FileSystemBackend instance. |
| 75 // The ownership of |drive_delegate| is also taken. | 74 // The ownership of |drive_delegate| is also taken. |
| 76 CrosMountPointProvider( | 75 FileSystemBackend( |
| 77 CrosMountPointProviderDelegate* drive_delegate, | 76 FileSystemBackendDelegate* drive_delegate, |
| 78 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 77 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
| 79 scoped_refptr<fileapi::ExternalMountPoints> mount_points, | 78 scoped_refptr<fileapi::ExternalMountPoints> mount_points, |
| 80 fileapi::ExternalMountPoints* system_mount_points); | 79 fileapi::ExternalMountPoints* system_mount_points); |
| 81 virtual ~CrosMountPointProvider(); | 80 virtual ~FileSystemBackend(); |
| 82 | 81 |
| 83 // Adds system mount points, such as "archive", and "removable". This | 82 // Adds system mount points, such as "archive", and "removable". This |
| 84 // function is no-op if these mount points are already present. | 83 // function is no-op if these mount points are already present. |
| 85 void AddSystemMountPoints(); | 84 void AddSystemMountPoints(); |
| 86 | 85 |
| 87 // Returns true if CrosMountpointProvider can handle |url|, i.e. its | 86 // Returns true if CrosMountpointProvider can handle |url|, i.e. its |
| 88 // file system type matches with what this provider supports. | 87 // file system type matches with what this provider supports. |
| 89 // This could be called on any threads. | 88 // This could be called on any threads. |
| 90 static bool CanHandleURL(const fileapi::FileSystemURL& url); | 89 static bool CanHandleURL(const fileapi::FileSystemURL& url); |
| 91 | 90 |
| 92 // fileapi::FileSystemMountPointProvider overrides. | 91 // fileapi::FileSystemBackend overrides. |
| 93 virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; | 92 virtual bool CanHandleType(fileapi::FileSystemType type) const OVERRIDE; |
| 94 virtual void OpenFileSystem( | 93 virtual void OpenFileSystem( |
| 95 const GURL& origin_url, | 94 const GURL& origin_url, |
| 96 fileapi::FileSystemType type, | 95 fileapi::FileSystemType type, |
| 97 fileapi::OpenFileSystemMode mode, | 96 fileapi::OpenFileSystemMode mode, |
| 98 const OpenFileSystemCallback& callback) OVERRIDE; | 97 const OpenFileSystemCallback& callback) OVERRIDE; |
| 99 virtual fileapi::FileSystemFileUtil* GetFileUtil( | 98 virtual fileapi::FileSystemFileUtil* GetFileUtil( |
| 100 fileapi::FileSystemType type) OVERRIDE; | 99 fileapi::FileSystemType type) OVERRIDE; |
| 101 virtual fileapi::AsyncFileUtil* GetAsyncFileUtil( | 100 virtual fileapi::AsyncFileUtil* GetAsyncFileUtil( |
| 102 fileapi::FileSystemType type) OVERRIDE; | 101 fileapi::FileSystemType type) OVERRIDE; |
| 103 virtual fileapi::CopyOrMoveFileValidatorFactory* | 102 virtual fileapi::CopyOrMoveFileValidatorFactory* |
| 104 GetCopyOrMoveFileValidatorFactory( | 103 GetCopyOrMoveFileValidatorFactory( |
| 105 fileapi::FileSystemType type, | 104 fileapi::FileSystemType type, |
| 106 base::PlatformFileError* error_code) OVERRIDE; | 105 base::PlatformFileError* error_code) OVERRIDE; |
| 107 virtual fileapi::FileSystemOperation* CreateFileSystemOperation( | 106 virtual fileapi::FileSystemOperation* CreateFileSystemOperation( |
| 108 const fileapi::FileSystemURL& url, | 107 const fileapi::FileSystemURL& url, |
| 109 fileapi::FileSystemContext* context, | 108 fileapi::FileSystemContext* context, |
| 110 base::PlatformFileError* error_code) const OVERRIDE; | 109 base::PlatformFileError* error_code) const OVERRIDE; |
| 111 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( | 110 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( |
| 112 const fileapi::FileSystemURL& path, | 111 const fileapi::FileSystemURL& path, |
| 113 int64 offset, | 112 int64 offset, |
| 114 const base::Time& expected_modification_time, | 113 const base::Time& expected_modification_time, |
| 115 fileapi::FileSystemContext* context) const OVERRIDE; | 114 fileapi::FileSystemContext* context) const OVERRIDE; |
| 116 virtual scoped_ptr<fileapi::FileStreamWriter> CreateFileStreamWriter( | 115 virtual scoped_ptr<fileapi::FileStreamWriter> CreateFileStreamWriter( |
| 117 const fileapi::FileSystemURL& url, | 116 const fileapi::FileSystemURL& url, |
| 118 int64 offset, | 117 int64 offset, |
| 119 fileapi::FileSystemContext* context) const OVERRIDE; | 118 fileapi::FileSystemContext* context) const OVERRIDE; |
| 120 virtual fileapi::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; | 119 virtual fileapi::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; |
| 121 | 120 |
| 122 // fileapi::ExternalFileSystemMountPointProvider overrides. | 121 // fileapi::ExternalFileSystemBackend overrides. |
| 123 virtual bool IsAccessAllowed(const fileapi::FileSystemURL& url) | 122 virtual bool IsAccessAllowed(const fileapi::FileSystemURL& url) |
| 124 const OVERRIDE; | 123 const OVERRIDE; |
| 125 virtual std::vector<base::FilePath> GetRootDirectories() const OVERRIDE; | 124 virtual std::vector<base::FilePath> GetRootDirectories() const OVERRIDE; |
| 126 virtual void GrantFullAccessToExtension( | 125 virtual void GrantFullAccessToExtension( |
| 127 const std::string& extension_id) OVERRIDE; | 126 const std::string& extension_id) OVERRIDE; |
| 128 virtual void GrantFileAccessToExtension( | 127 virtual void GrantFileAccessToExtension( |
| 129 const std::string& extension_id, | 128 const std::string& extension_id, |
| 130 const base::FilePath& virtual_path) OVERRIDE; | 129 const base::FilePath& virtual_path) OVERRIDE; |
| 131 virtual void RevokeAccessForExtension( | 130 virtual void RevokeAccessForExtension( |
| 132 const std::string& extension_id) OVERRIDE; | 131 const std::string& extension_id) OVERRIDE; |
| 133 virtual bool GetVirtualPath(const base::FilePath& filesystem_path, | 132 virtual bool GetVirtualPath(const base::FilePath& filesystem_path, |
| 134 base::FilePath* virtual_path) OVERRIDE; | 133 base::FilePath* virtual_path) OVERRIDE; |
| 135 | 134 |
| 136 private: | 135 private: |
| 137 base::FilePath GetFileSystemRootPath(const fileapi::FileSystemURL& url) const; | 136 base::FilePath GetFileSystemRootPath(const fileapi::FileSystemURL& url) const; |
| 138 | 137 |
| 139 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 138 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; |
| 140 scoped_ptr<FileAccessPermissions> file_access_permissions_; | 139 scoped_ptr<FileAccessPermissions> file_access_permissions_; |
| 141 scoped_ptr<fileapi::AsyncFileUtilAdapter> local_file_util_; | 140 scoped_ptr<fileapi::AsyncFileUtilAdapter> local_file_util_; |
| 142 | 141 |
| 143 // The Delegate instance for the drive file system related operation. | 142 // The Delegate instance for the drive file system related operation. |
| 144 scoped_ptr<CrosMountPointProviderDelegate> drive_delegate_; | 143 scoped_ptr<FileSystemBackendDelegate> drive_delegate_; |
| 145 | 144 |
| 146 // Mount points specific to the owning context (i.e. per-profile mount | 145 // Mount points specific to the owning context (i.e. per-profile mount |
| 147 // points). | 146 // points). |
| 148 // | 147 // |
| 149 // It is legal to have mount points with the same name as in | 148 // It is legal to have mount points with the same name as in |
| 150 // system_mount_points_. Also, mount point paths may overlap with mount point | 149 // system_mount_points_. Also, mount point paths may overlap with mount point |
| 151 // paths in system_mount_points_. In both cases mount points in | 150 // paths in system_mount_points_. In both cases mount points in |
| 152 // |mount_points_| will have a priority. | 151 // |mount_points_| will have a priority. |
| 153 // E.g. if |mount_points_| map 'foo1' to '/foo/foo1' and | 152 // E.g. if |mount_points_| map 'foo1' to '/foo/foo1' and |
| 154 // |file_system_mount_points_| map 'xxx' to '/foo/foo1/xxx', |GetVirtualPaths| | 153 // |file_system_mount_points_| map 'xxx' to '/foo/foo1/xxx', |GetVirtualPaths| |
| 155 // will resolve '/foo/foo1/xxx/yyy' as 'foo1/xxx/yyy' (i.e. the mapping from | 154 // will resolve '/foo/foo1/xxx/yyy' as 'foo1/xxx/yyy' (i.e. the mapping from |
| 156 // |mount_points_| will be used). | 155 // |mount_points_| will be used). |
| 157 scoped_refptr<fileapi::ExternalMountPoints> mount_points_; | 156 scoped_refptr<fileapi::ExternalMountPoints> mount_points_; |
| 158 | 157 |
| 159 // Globally visible mount points. System MountPonts instance should outlive | 158 // Globally visible mount points. System MountPonts instance should outlive |
| 160 // all CrosMountPointProvider instances, so raw pointer is safe. | 159 // all FileSystemBackend instances, so raw pointer is safe. |
| 161 fileapi::ExternalMountPoints* system_mount_points_; | 160 fileapi::ExternalMountPoints* system_mount_points_; |
| 162 | 161 |
| 163 DISALLOW_COPY_AND_ASSIGN(CrosMountPointProvider); | 162 DISALLOW_COPY_AND_ASSIGN(FileSystemBackend); |
| 164 }; | 163 }; |
| 165 | 164 |
| 166 } // namespace chromeos | 165 } // namespace chromeos |
| 167 | 166 |
| 168 #endif // CHROME_BROWSER_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ | 167 #endif // CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_SYSTEM_BACKEND_H_ |
| OLD | NEW |