OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 WEBKIT_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ | 5 #ifndef WEBKIT_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ |
6 #define WEBKIT_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ | 6 #define WEBKIT_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_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/file_path.h" | 13 #include "base/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/fileapi/file_system_mount_point_provider.h" | 16 #include "webkit/fileapi/file_system_mount_point_provider.h" |
17 #include "webkit/quota/special_storage_policy.h" | 17 #include "webkit/quota/special_storage_policy.h" |
18 #include "webkit/storage/webkit_storage_export.h" | 18 #include "webkit/storage/webkit_storage_export.h" |
19 | 19 |
20 namespace fileapi { | 20 namespace fileapi { |
| 21 class ExternalMountPoints; |
21 class FileSystemFileUtil; | 22 class FileSystemFileUtil; |
22 class FileSystemURL; | 23 class FileSystemURL; |
23 class IsolatedContext; | 24 class IsolatedContext; |
24 class LocalFileUtil; | 25 class LocalFileUtil; |
25 } | 26 } |
26 | 27 |
27 namespace chromeos { | 28 namespace chromeos { |
28 | 29 |
29 class FileAccessPermissions; | 30 class FileAccessPermissions; |
30 | 31 |
31 // An interface to provide local filesystem paths. | 32 // An interface to provide local filesystem paths. |
32 class WEBKIT_STORAGE_EXPORT CrosMountPointProvider | 33 class WEBKIT_STORAGE_EXPORT CrosMountPointProvider |
33 : public fileapi::ExternalFileSystemMountPointProvider { | 34 : public fileapi::ExternalFileSystemMountPointProvider { |
34 public: | 35 public: |
35 using fileapi::FileSystemMountPointProvider::ValidateFileSystemCallback; | 36 using fileapi::FileSystemMountPointProvider::ValidateFileSystemCallback; |
36 using fileapi::FileSystemMountPointProvider::DeleteFileSystemCallback; | 37 using fileapi::FileSystemMountPointProvider::DeleteFileSystemCallback; |
37 | 38 |
| 39 // CrosMountPointProvider will take an ownership of a |mount_points| |
| 40 // reference. On the other hand, |system_mount_points| will be kept as a raw |
| 41 // pointer and it should outlive CrosMountPointProvider instance. |
38 CrosMountPointProvider( | 42 CrosMountPointProvider( |
39 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy); | 43 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
| 44 scoped_refptr<fileapi::ExternalMountPoints> mount_points, |
| 45 fileapi::ExternalMountPoints* system_mount_points); |
40 virtual ~CrosMountPointProvider(); | 46 virtual ~CrosMountPointProvider(); |
41 | 47 |
42 // Returns true if CrosMountpointProvider can handle |url|, i.e. its | 48 // Returns true if CrosMountpointProvider can handle |url|, i.e. its |
43 // file system type matches with what this provider supports. | 49 // file system type matches with what this provider supports. |
44 // This could be called on any threads. | 50 // This could be called on any threads. |
45 static bool CanHandleURL(const fileapi::FileSystemURL& url); | 51 static bool CanHandleURL(const fileapi::FileSystemURL& url); |
46 | 52 |
47 // fileapi::FileSystemMountPointProvider overrides. | 53 // fileapi::FileSystemMountPointProvider overrides. |
48 virtual void ValidateFileSystemRoot( | 54 virtual void ValidateFileSystemRoot( |
49 const GURL& origin_url, | 55 const GURL& origin_url, |
(...skipping 30 matching lines...) Expand all Loading... |
80 const DeleteFileSystemCallback& callback) OVERRIDE; | 86 const DeleteFileSystemCallback& callback) OVERRIDE; |
81 | 87 |
82 // fileapi::ExternalFileSystemMountPointProvider overrides. | 88 // fileapi::ExternalFileSystemMountPointProvider overrides. |
83 virtual std::vector<FilePath> GetRootDirectories() const OVERRIDE; | 89 virtual std::vector<FilePath> GetRootDirectories() const OVERRIDE; |
84 virtual void GrantFullAccessToExtension( | 90 virtual void GrantFullAccessToExtension( |
85 const std::string& extension_id) OVERRIDE; | 91 const std::string& extension_id) OVERRIDE; |
86 virtual void GrantFileAccessToExtension( | 92 virtual void GrantFileAccessToExtension( |
87 const std::string& extension_id, const FilePath& virtual_path) OVERRIDE; | 93 const std::string& extension_id, const FilePath& virtual_path) OVERRIDE; |
88 virtual void RevokeAccessForExtension( | 94 virtual void RevokeAccessForExtension( |
89 const std::string& extension_id) OVERRIDE; | 95 const std::string& extension_id) OVERRIDE; |
90 virtual bool HasMountPoint(const FilePath& mount_point) OVERRIDE; | 96 // Note: This will ignore |system_mount_points_|. The reasoning behind this is |
91 virtual void AddLocalMountPoint(const FilePath& mount_point) OVERRIDE; | 97 // the method should be used paired with Add/RemoveMountPoint methods, which |
92 virtual void AddRestrictedLocalMountPoint( | 98 // don't affect |system_mount_points_|. |
| 99 virtual bool HasMountPoint(const FilePath& mount_point) const OVERRIDE; |
| 100 virtual bool AddLocalMountPoint(const FilePath& mount_point) OVERRIDE; |
| 101 virtual bool AddRestrictedLocalMountPoint( |
93 const FilePath& mount_point) OVERRIDE; | 102 const FilePath& mount_point) OVERRIDE; |
94 virtual void AddRemoteMountPoint( | 103 virtual bool AddRemoteMountPoint( |
95 const FilePath& mount_point, | 104 const FilePath& mount_point, |
96 fileapi::RemoteFileSystemProxyInterface* remote_proxy) OVERRIDE; | 105 fileapi::RemoteFileSystemProxyInterface* remote_proxy) OVERRIDE; |
97 virtual void RemoveMountPoint(const FilePath& mount_point) OVERRIDE; | 106 virtual void RemoveMountPoint(const FilePath& mount_point) OVERRIDE; |
98 virtual bool GetVirtualPath(const FilePath& filesystem_path, | 107 virtual bool GetVirtualPath(const FilePath& filesystem_path, |
99 FilePath* virtual_path) OVERRIDE; | 108 FilePath* virtual_path) OVERRIDE; |
100 | 109 |
101 private: | 110 private: |
102 typedef scoped_refptr<fileapi::RemoteFileSystemProxyInterface> RemoteProxy; | 111 fileapi::RemoteFileSystemProxyInterface* GetRemoteProxy( |
103 typedef std::map<FilePath::StringType, RemoteProxy> RemoteProxyMap; | 112 const std::string& mount_name) const; |
104 | |
105 fileapi::IsolatedContext* isolated_context() const; | |
106 | |
107 // Represents a map from mount point name to a remote proxy. | |
108 RemoteProxyMap remote_proxy_map_; | |
109 | |
110 // Reverse map for GetVirtualPath. | |
111 std::map<FilePath, FilePath> local_to_virtual_map_; | |
112 | |
113 mutable base::Lock mount_point_map_lock_; | |
114 | 113 |
115 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 114 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; |
116 scoped_ptr<FileAccessPermissions> file_access_permissions_; | 115 scoped_ptr<FileAccessPermissions> file_access_permissions_; |
117 scoped_ptr<fileapi::LocalFileUtil> local_file_util_; | 116 scoped_ptr<fileapi::LocalFileUtil> local_file_util_; |
| 117 |
| 118 // Mount points specific to the owning context. |
| 119 // |
| 120 // Add/Remove MountPoints will affect only these mount points. |
| 121 // |
| 122 // It is legal to have mount points with the same name as in |
| 123 // system_mount_points_. Also, mount point paths may overlap with mount point |
| 124 // paths in system_mount_points_. In both cases mount points in |
| 125 // |mount_points_| will have a priority. |
| 126 // E.g. if |mount_points_| map 'foo1' to '/foo/foo1' and |
| 127 // |file_system_mount_points_| map 'xxx' to '/foo/foo1/xxx', |GetVirtualPaths| |
| 128 // will resolve '/foo/foo1/xxx/yyy' as 'foo1/xxx/yyy' (i.e. the mapping from |
| 129 // |mount_points_| will be used). |
| 130 scoped_refptr<fileapi::ExternalMountPoints> mount_points_; |
| 131 |
| 132 // Globally visible mount points. System MountPonts instance should outlive |
| 133 // all CrosMountPointProvider instances, so raw pointer is safe. |
| 134 fileapi::ExternalMountPoints* system_mount_points_; |
| 135 |
118 DISALLOW_COPY_AND_ASSIGN(CrosMountPointProvider); | 136 DISALLOW_COPY_AND_ASSIGN(CrosMountPointProvider); |
119 }; | 137 }; |
120 | 138 |
121 } // namespace chromeos | 139 } // namespace chromeos |
122 | 140 |
123 #endif // WEBKIT_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ | 141 #endif // WEBKIT_CHROMEOS_FILEAPI_CROS_MOUNT_POINT_PROVIDER_H_ |
OLD | NEW |