Chromium Code Reviews| 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 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 5 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
| 6 | 6 |
| 7 #include "base/chromeos/chromeos_version.h" | 7 #include "base/chromeos/chromeos_version.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "webkit/fileapi/file_system_file_stream_reader.h" | 23 #include "webkit/fileapi/file_system_file_stream_reader.h" |
| 24 #include "webkit/fileapi/file_system_operation_context.h" | 24 #include "webkit/fileapi/file_system_operation_context.h" |
| 25 #include "webkit/fileapi/file_system_url.h" | 25 #include "webkit/fileapi/file_system_url.h" |
| 26 #include "webkit/fileapi/file_system_util.h" | 26 #include "webkit/fileapi/file_system_util.h" |
| 27 #include "webkit/fileapi/isolated_context.h" | 27 #include "webkit/fileapi/isolated_context.h" |
| 28 #include "webkit/fileapi/isolated_file_util.h" | 28 #include "webkit/fileapi/isolated_file_util.h" |
| 29 #include "webkit/fileapi/local_file_stream_writer.h" | 29 #include "webkit/fileapi/local_file_stream_writer.h" |
| 30 #include "webkit/fileapi/local_file_system_operation.h" | 30 #include "webkit/fileapi/local_file_system_operation.h" |
| 31 #include "webkit/glue/webkit_glue.h" | 31 #include "webkit/glue/webkit_glue.h" |
| 32 | 32 |
| 33 using fileapi::FileSystemURL; | |
| 34 | |
| 33 namespace { | 35 namespace { |
| 34 | 36 |
| 35 const char kChromeUIScheme[] = "chrome"; | 37 const char kChromeUIScheme[] = "chrome"; |
| 36 | 38 |
| 37 } // namespace | 39 } // namespace |
| 38 | 40 |
| 39 namespace chromeos { | 41 namespace chromeos { |
| 40 | 42 |
| 41 // static | 43 // static |
| 42 bool CrosMountPointProvider::CanHandleURL(const fileapi::FileSystemURL& url) { | 44 bool CrosMountPointProvider::CanHandleURL(const FileSystemURL& url) { |
| 43 if (!url.is_valid()) | 45 if (!url.is_valid()) |
| 44 return false; | 46 return false; |
| 45 return url.type() == fileapi::kFileSystemTypeNativeLocal || | 47 return url.type() == fileapi::kFileSystemTypeNativeLocal || |
| 46 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || | 48 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || |
| 47 url.type() == fileapi::kFileSystemTypeDrive; | 49 url.type() == fileapi::kFileSystemTypeDrive; |
| 48 } | 50 } |
| 49 | 51 |
| 50 CrosMountPointProvider::CrosMountPointProvider( | 52 CrosMountPointProvider::CrosMountPointProvider( |
| 51 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 53 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
| 52 scoped_refptr<fileapi::ExternalMountPoints> mount_points, | 54 scoped_refptr<fileapi::ExternalMountPoints> mount_points, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 66 const GURL& origin_url, | 68 const GURL& origin_url, |
| 67 fileapi::FileSystemType type, | 69 fileapi::FileSystemType type, |
| 68 bool create, | 70 bool create, |
| 69 const ValidateFileSystemCallback& callback) { | 71 const ValidateFileSystemCallback& callback) { |
| 70 DCHECK(fileapi::IsolatedContext::IsIsolatedType(type)); | 72 DCHECK(fileapi::IsolatedContext::IsIsolatedType(type)); |
| 71 // Nothing to validate for external filesystem. | 73 // Nothing to validate for external filesystem. |
| 72 callback.Run(base::PLATFORM_FILE_OK); | 74 callback.Run(base::PLATFORM_FILE_OK); |
| 73 } | 75 } |
| 74 | 76 |
| 75 base::FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( | 77 base::FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( |
| 76 const fileapi::FileSystemURL& url, | 78 const FileSystemURL& url, |
| 77 bool create) { | 79 bool create) { |
| 78 DCHECK(fileapi::IsolatedContext::IsIsolatedType(url.mount_type())); | 80 DCHECK(fileapi::IsolatedContext::IsIsolatedType(url.mount_type())); |
| 79 if (!url.is_valid()) | 81 if (!url.is_valid()) |
| 80 return base::FilePath(); | 82 return base::FilePath(); |
| 81 | 83 |
| 82 base::FilePath root_path; | 84 base::FilePath root_path; |
| 83 std::string mount_name = url.filesystem_id(); | 85 std::string mount_name = url.filesystem_id(); |
| 84 if (!mount_points_->GetRegisteredPath(mount_name, &root_path) && | 86 if (!mount_points_->GetRegisteredPath(mount_name, &root_path) && |
| 85 !system_mount_points_->GetRegisteredPath(mount_name, &root_path)) { | 87 !system_mount_points_->GetRegisteredPath(mount_name, &root_path)) { |
| 86 return base::FilePath(); | 88 return base::FilePath(); |
| 87 } | 89 } |
| 88 | 90 |
| 89 return root_path.DirName(); | 91 return root_path.DirName(); |
| 90 } | 92 } |
| 91 | 93 |
| 92 bool CrosMountPointProvider::IsAccessAllowed( | 94 bool CrosMountPointProvider::IsAccessAllowed(const FileSystemURL& url) { |
| 93 const fileapi::FileSystemURL& url) { | |
| 94 if (!url.is_valid()) | 95 if (!url.is_valid()) |
| 95 return false; | 96 return false; |
| 96 | 97 |
| 97 // Permit access to mount points from internal WebUI. | 98 // Permit access to mount points from internal WebUI. |
| 98 const GURL& origin_url = url.origin(); | 99 const GURL& origin_url = url.origin(); |
| 99 if (origin_url.SchemeIs(kChromeUIScheme)) | 100 if (origin_url.SchemeIs(kChromeUIScheme)) |
| 100 return true; | 101 return true; |
| 101 | 102 |
| 102 // No extra check is needed for isolated file systems. | 103 // No extra check is needed for isolated file systems. |
| 103 if (url.mount_type() == fileapi::kFileSystemTypeIsolated) | 104 if (url.mount_type() == fileapi::kFileSystemTypeIsolated) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 } | 201 } |
| 201 | 202 |
| 202 fileapi::AsyncFileUtil* CrosMountPointProvider::GetAsyncFileUtil( | 203 fileapi::AsyncFileUtil* CrosMountPointProvider::GetAsyncFileUtil( |
| 203 fileapi::FileSystemType type) { | 204 fileapi::FileSystemType type) { |
| 204 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || | 205 DCHECK(type == fileapi::kFileSystemTypeNativeLocal || |
| 205 type == fileapi::kFileSystemTypeRestrictedNativeLocal); | 206 type == fileapi::kFileSystemTypeRestrictedNativeLocal); |
| 206 return local_file_util_.get(); | 207 return local_file_util_.get(); |
| 207 } | 208 } |
| 208 | 209 |
| 209 fileapi::FilePermissionPolicy CrosMountPointProvider::GetPermissionPolicy( | 210 fileapi::FilePermissionPolicy CrosMountPointProvider::GetPermissionPolicy( |
| 210 const fileapi::FileSystemURL& url, int permissions) const { | 211 const FileSystemURL& url, int permissions) const { |
| 211 if (url.mount_type() == fileapi::kFileSystemTypeIsolated) { | 212 if (url.mount_type() == fileapi::kFileSystemTypeIsolated) { |
| 212 // Permissions in isolated filesystems should be examined with | 213 // Permissions in isolated filesystems should be examined with |
| 213 // FileSystem permission. | 214 // FileSystem permission. |
| 214 return fileapi::FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; | 215 return fileapi::FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; |
| 215 } | 216 } |
| 216 return fileapi::FILE_PERMISSION_USE_FILE_PERMISSION; | 217 return fileapi::FILE_PERMISSION_USE_FILE_PERMISSION; |
| 217 } | 218 } |
| 218 | 219 |
| 219 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( | 220 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( |
| 220 const fileapi::FileSystemURL& url, | 221 const FileSystemURL& url, |
| 221 fileapi::FileSystemContext* context, | 222 fileapi::FileSystemContext* context, |
| 222 base::PlatformFileError* error_code) const { | 223 base::PlatformFileError* error_code) const { |
| 223 DCHECK(url.is_valid()); | 224 DCHECK(url.is_valid()); |
| 224 | 225 |
| 225 if (url.type() == fileapi::kFileSystemTypeDrive) { | 226 if (url.type() == fileapi::kFileSystemTypeDrive) { |
| 227 FileSystemURL external_url = GetAsExternalFileSystemURL(url); | |
| 226 fileapi::RemoteFileSystemProxyInterface* remote_proxy = | 228 fileapi::RemoteFileSystemProxyInterface* remote_proxy = |
| 227 GetRemoteProxy(url.filesystem_id()); | 229 GetRemoteProxy(external_url); |
| 228 if (!remote_proxy) { | 230 if (!remote_proxy) { |
| 229 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 231 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 230 return NULL; | 232 return NULL; |
| 231 } | 233 } |
| 232 return new chromeos::RemoteFileSystemOperation(remote_proxy); | 234 return new chromeos::RemoteFileSystemOperation(remote_proxy); |
| 233 } | 235 } |
| 234 | 236 |
| 235 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || | 237 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || |
| 236 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); | 238 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); |
| 237 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | 239 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
| 238 new fileapi::FileSystemOperationContext(context)); | 240 new fileapi::FileSystemOperationContext(context)); |
| 239 return new fileapi::LocalFileSystemOperation(context, | 241 return new fileapi::LocalFileSystemOperation(context, |
| 240 operation_context.Pass()); | 242 operation_context.Pass()); |
| 241 } | 243 } |
| 242 | 244 |
| 243 webkit_blob::FileStreamReader* CrosMountPointProvider::CreateFileStreamReader( | 245 webkit_blob::FileStreamReader* CrosMountPointProvider::CreateFileStreamReader( |
| 244 const fileapi::FileSystemURL& url, | 246 const FileSystemURL& url, |
| 245 int64 offset, | 247 int64 offset, |
| 246 const base::Time& expected_modification_time, | 248 const base::Time& expected_modification_time, |
| 247 fileapi::FileSystemContext* context) const { | 249 fileapi::FileSystemContext* context) const { |
| 248 // For now we return a generic Reader implementation which utilizes | 250 // For now we return a generic Reader implementation which utilizes |
| 249 // CreateSnapshotFile internally (i.e. will download everything first). | 251 // CreateSnapshotFile internally (i.e. will download everything first). |
| 250 // TODO(satorux,zel): implement more efficient reader for remote cases. | 252 // TODO(satorux,zel): implement more efficient reader for remote cases. |
| 251 return new fileapi::FileSystemFileStreamReader( | 253 return new fileapi::FileSystemFileStreamReader( |
| 252 context, url, offset, expected_modification_time); | 254 context, url, offset, expected_modification_time); |
| 253 } | 255 } |
| 254 | 256 |
| 255 fileapi::FileStreamWriter* CrosMountPointProvider::CreateFileStreamWriter( | 257 fileapi::FileStreamWriter* CrosMountPointProvider::CreateFileStreamWriter( |
| 256 const fileapi::FileSystemURL& url, | 258 const FileSystemURL& url, |
| 257 int64 offset, | 259 int64 offset, |
| 258 fileapi::FileSystemContext* context) const { | 260 fileapi::FileSystemContext* context) const { |
| 259 DCHECK(url.is_valid()); | 261 DCHECK(url.is_valid()); |
| 260 | 262 |
| 261 if (url.type() == fileapi::kFileSystemTypeDrive) { | 263 if (url.type() == fileapi::kFileSystemTypeDrive) { |
| 264 FileSystemURL external_url = GetAsExternalFileSystemURL(url); | |
| 262 fileapi::RemoteFileSystemProxyInterface* remote_proxy = | 265 fileapi::RemoteFileSystemProxyInterface* remote_proxy = |
| 263 GetRemoteProxy(url.filesystem_id()); | 266 GetRemoteProxy(external_url); |
| 264 if (!remote_proxy) | 267 if (!remote_proxy) |
| 265 return NULL; | 268 return NULL; |
| 266 return new fileapi::RemoteFileStreamWriter(remote_proxy, url, offset); | 269 return new fileapi::RemoteFileStreamWriter(remote_proxy, url, offset); |
| 267 } | 270 } |
| 268 | 271 |
| 269 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) | 272 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) |
| 270 return NULL; | 273 return NULL; |
| 271 | 274 |
| 272 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); | 275 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
| 273 return new fileapi::LocalFileStreamWriter(url.path(), offset); | 276 return new fileapi::LocalFileStreamWriter(url.path(), offset); |
| 274 } | 277 } |
| 275 | 278 |
| 276 bool CrosMountPointProvider::GetVirtualPath(const base::FilePath& filesystem_pat h, | 279 bool CrosMountPointProvider::GetVirtualPath( |
| 277 base::FilePath* virtual_path) { | 280 const base::FilePath& filesystem_path, |
| 281 base::FilePath* virtual_path) const { | |
| 278 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || | 282 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
| 279 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); | 283 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
| 280 } | 284 } |
| 281 | 285 |
| 286 fileapi::FileSystemURL CrosMountPointProvider::GetAsExternalFileSystemURL( | |
| 287 const fileapi::FileSystemURL& original) const { | |
|
kinuko
2013/02/14 17:09:48
Do we need to specifically crack the isolated URL
tbarzic
2013/02/14 20:22:32
this could be problematic because we use different
| |
| 288 if (original.mount_type() == fileapi::kFileSystemTypeExternal) | |
| 289 return original; | |
| 290 | |
| 291 if (original.mount_type() == fileapi::kFileSystemTypeIsolated) { | |
| 292 base::FilePath external_path; | |
| 293 if (!GetVirtualPath(original.path(), &external_path)) | |
| 294 return fileapi::FileSystemURL(); | |
| 295 | |
| 296 fileapi::FileSystemURL external = mount_points_->CreateCrackedFileSystemURL( | |
| 297 original.origin(), fileapi::kFileSystemTypeExternal, external_path); | |
| 298 if (external.is_valid() && external.type() == original.type()) | |
| 299 return external; | |
| 300 | |
| 301 external = system_mount_points_->CreateCrackedFileSystemURL( | |
| 302 original.origin(), fileapi::kFileSystemTypeExternal, external_path); | |
| 303 if (external.is_valid() && external.type() == original.type()) | |
| 304 return external; | |
| 305 } | |
| 306 | |
| 307 return fileapi::FileSystemURL(); | |
| 308 } | |
| 309 | |
| 282 fileapi::RemoteFileSystemProxyInterface* CrosMountPointProvider::GetRemoteProxy( | 310 fileapi::RemoteFileSystemProxyInterface* CrosMountPointProvider::GetRemoteProxy( |
| 283 const std::string& mount_name) const { | 311 const FileSystemURL& url) const { |
| 312 if (!url.is_valid()) | |
| 313 return NULL; | |
| 284 fileapi::RemoteFileSystemProxyInterface* proxy = | 314 fileapi::RemoteFileSystemProxyInterface* proxy = |
| 285 mount_points_->GetRemoteFileSystemProxy(mount_name); | 315 mount_points_->GetRemoteFileSystemProxy(url.filesystem_id()); |
| 286 if (proxy) | 316 if (proxy) |
| 287 return proxy; | 317 return proxy; |
| 288 return system_mount_points_->GetRemoteFileSystemProxy(mount_name); | 318 return system_mount_points_->GetRemoteFileSystemProxy(url.filesystem_id()); |
| 289 } | 319 } |
| 290 | 320 |
| 291 } // namespace chromeos | 321 } // namespace chromeos |
| OLD | NEW |