| 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(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // Permissions in isolated filesystems should be examined with | 222 // Permissions in isolated filesystems should be examined with |
| 221 // FileSystem permission. | 223 // FileSystem permission. |
| 222 return fileapi::FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; | 224 return fileapi::FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; |
| 223 } | 225 } |
| 224 | 226 |
| 225 // Also apply system's file permission by default. | 227 // Also apply system's file permission by default. |
| 226 return fileapi::FILE_PERMISSION_USE_FILE_PERMISSION; | 228 return fileapi::FILE_PERMISSION_USE_FILE_PERMISSION; |
| 227 } | 229 } |
| 228 | 230 |
| 229 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( | 231 fileapi::FileSystemOperation* CrosMountPointProvider::CreateFileSystemOperation( |
| 230 const fileapi::FileSystemURL& url, | 232 const FileSystemURL& url, |
| 231 fileapi::FileSystemContext* context, | 233 fileapi::FileSystemContext* context, |
| 232 base::PlatformFileError* error_code) const { | 234 base::PlatformFileError* error_code) const { |
| 233 DCHECK(url.is_valid()); | 235 DCHECK(url.is_valid()); |
| 234 | 236 |
| 235 if (url.type() == fileapi::kFileSystemTypeDrive) { | 237 fileapi::RemoteFileSystemProxyInterface* remote_proxy = GetRemoteProxy(url); |
| 236 fileapi::RemoteFileSystemProxyInterface* remote_proxy = | 238 if (remote_proxy) |
| 237 GetRemoteProxy(url.filesystem_id()); | |
| 238 if (!remote_proxy) { | |
| 239 *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 240 return NULL; | |
| 241 } | |
| 242 return new chromeos::RemoteFileSystemOperation(remote_proxy); | 239 return new chromeos::RemoteFileSystemOperation(remote_proxy); |
| 243 } | |
| 244 | 240 |
| 245 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || | 241 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || |
| 246 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); | 242 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal); |
| 247 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | 243 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
| 248 new fileapi::FileSystemOperationContext(context)); | 244 new fileapi::FileSystemOperationContext(context)); |
| 249 return new fileapi::LocalFileSystemOperation(context, | 245 return new fileapi::LocalFileSystemOperation(context, |
| 250 operation_context.Pass()); | 246 operation_context.Pass()); |
| 251 } | 247 } |
| 252 | 248 |
| 253 webkit_blob::FileStreamReader* CrosMountPointProvider::CreateFileStreamReader( | 249 webkit_blob::FileStreamReader* CrosMountPointProvider::CreateFileStreamReader( |
| 254 const fileapi::FileSystemURL& url, | 250 const FileSystemURL& url, |
| 255 int64 offset, | 251 int64 offset, |
| 256 const base::Time& expected_modification_time, | 252 const base::Time& expected_modification_time, |
| 257 fileapi::FileSystemContext* context) const { | 253 fileapi::FileSystemContext* context) const { |
| 258 // For now we return a generic Reader implementation which utilizes | 254 // For now we return a generic Reader implementation which utilizes |
| 259 // CreateSnapshotFile internally (i.e. will download everything first). | 255 // CreateSnapshotFile internally (i.e. will download everything first). |
| 260 // TODO(satorux,zel): implement more efficient reader for remote cases. | 256 // TODO(satorux,zel): implement more efficient reader for remote cases. |
| 261 return new fileapi::FileSystemFileStreamReader( | 257 return new fileapi::FileSystemFileStreamReader( |
| 262 context, url, offset, expected_modification_time); | 258 context, url, offset, expected_modification_time); |
| 263 } | 259 } |
| 264 | 260 |
| 265 fileapi::FileStreamWriter* CrosMountPointProvider::CreateFileStreamWriter( | 261 fileapi::FileStreamWriter* CrosMountPointProvider::CreateFileStreamWriter( |
| 266 const fileapi::FileSystemURL& url, | 262 const FileSystemURL& url, |
| 267 int64 offset, | 263 int64 offset, |
| 268 fileapi::FileSystemContext* context) const { | 264 fileapi::FileSystemContext* context) const { |
| 269 DCHECK(url.is_valid()); | 265 DCHECK(url.is_valid()); |
| 270 | 266 |
| 271 if (url.type() == fileapi::kFileSystemTypeDrive) { | 267 fileapi::RemoteFileSystemProxyInterface* remote_proxy = GetRemoteProxy(url); |
| 272 fileapi::RemoteFileSystemProxyInterface* remote_proxy = | 268 if (remote_proxy) |
| 273 GetRemoteProxy(url.filesystem_id()); | |
| 274 if (!remote_proxy) | |
| 275 return NULL; | |
| 276 return new fileapi::RemoteFileStreamWriter(remote_proxy, url, offset); | 269 return new fileapi::RemoteFileStreamWriter(remote_proxy, url, offset); |
| 277 } | |
| 278 | 270 |
| 279 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) | 271 if (url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal) |
| 280 return NULL; | 272 return NULL; |
| 281 | 273 |
| 282 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); | 274 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); |
| 283 return new fileapi::LocalFileStreamWriter(url.path(), offset); | 275 return new fileapi::LocalFileStreamWriter(url.path(), offset); |
| 284 } | 276 } |
| 285 | 277 |
| 286 bool CrosMountPointProvider::GetVirtualPath( | 278 bool CrosMountPointProvider::GetVirtualPath( |
| 287 const base::FilePath& filesystem_path, | 279 const base::FilePath& filesystem_path, |
| 288 base::FilePath* virtual_path) { | 280 base::FilePath* virtual_path) const { |
| 289 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || | 281 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
| 290 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); | 282 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
| 291 } | 283 } |
| 292 | 284 |
| 293 fileapi::RemoteFileSystemProxyInterface* CrosMountPointProvider::GetRemoteProxy( | 285 fileapi::RemoteFileSystemProxyInterface* CrosMountPointProvider::GetRemoteProxy( |
| 294 const std::string& mount_name) const { | 286 const fileapi::FileSystemURL& url) const { |
| 295 fileapi::RemoteFileSystemProxyInterface* proxy = | 287 fileapi::RemoteFileSystemProxyInterface* proxy = |
| 296 mount_points_->GetRemoteFileSystemProxy(mount_name); | 288 mount_points_->GetRemoteFileSystemProxyForPath(url.path()); |
| 297 if (proxy) | 289 if (proxy) |
| 298 return proxy; | 290 return proxy; |
| 299 return system_mount_points_->GetRemoteFileSystemProxy(mount_name); | 291 return system_mount_points_->GetRemoteFileSystemProxyForPath(url.path()); |
| 300 } | 292 } |
| 301 | 293 |
| 302 } // namespace chromeos | 294 } // namespace chromeos |
| OLD | NEW |