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/fileapi/isolated_mount_point_provider.h" | 5 #include "webkit/fileapi/isolated_mount_point_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "webkit/blob/local_file_stream_reader.h" | 14 #include "webkit/blob/local_file_stream_reader.h" |
| 15 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 15 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 16 #include "webkit/fileapi/file_system_context.h" | 16 #include "webkit/fileapi/file_system_context.h" |
| 17 #include "webkit/fileapi/file_system_file_stream_reader.h" | 17 #include "webkit/fileapi/file_system_file_stream_reader.h" |
| 18 #include "webkit/fileapi/file_system_types.h" | 18 #include "webkit/fileapi/file_system_types.h" |
| 19 #include "webkit/fileapi/file_system_util.h" | 19 #include "webkit/fileapi/file_system_util.h" |
| 20 #include "webkit/fileapi/isolated_context.h" | 20 #include "webkit/fileapi/isolated_context.h" |
| 21 #include "webkit/fileapi/isolated_file_util.h" | 21 #include "webkit/fileapi/isolated_file_util.h" |
| 22 #include "webkit/fileapi/local_file_stream_writer.h" | 22 #include "webkit/fileapi/local_file_stream_writer.h" |
| 23 #include "webkit/fileapi/local_file_system_operation.h" | 23 #include "webkit/fileapi/local_file_system_operation.h" |
| 24 #include "webkit/fileapi/media/media_file_system_config.h" | |
| 24 #include "webkit/fileapi/native_file_util.h" | 25 #include "webkit/fileapi/native_file_util.h" |
| 25 | 26 |
| 27 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
| 28 #include "webkit/fileapi/media/device_media_file_util.h" | |
| 29 #include "webkit/fileapi/media/media_device_map_service.h" | |
| 30 #endif | |
| 31 | |
| 26 namespace fileapi { | 32 namespace fileapi { |
| 27 | 33 |
| 28 namespace { | 34 namespace { |
| 29 | 35 |
| 30 IsolatedContext* isolated_context() { | 36 IsolatedContext* isolated_context() { |
| 31 return IsolatedContext::GetInstance(); | 37 return IsolatedContext::GetInstance(); |
| 32 } | 38 } |
| 33 | 39 |
| 40 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
| 41 MediaDeviceInterfaceImpl* GetDeviceForUrl(const FileSystemURL& url, | |
| 42 FileSystemContext* context) { | |
| 43 | |
|
Lei Zhang
2012/07/31 20:04:37
nit: blank line
kmadhusu
2012/08/01 01:43:59
Done.
| |
| 44 FilePath root_path; | |
| 45 if (!isolated_context()->GetRegisteredPath(url.filesystem_id(), &root_path)) | |
| 46 return NULL; | |
| 47 | |
| 48 // Add the media device if required. | |
| 49 MediaDeviceMapService::GetInstance()->MaybeAddMediaDevice( | |
| 50 root_path.value(), context->file_task_runner()); | |
| 51 | |
| 52 return MediaDeviceMapService::GetInstance()->GetMediaDevice( | |
| 53 root_path.value()); | |
| 54 } | |
| 55 #endif | |
| 56 | |
| 34 } // namespace | 57 } // namespace |
| 35 | 58 |
| 36 IsolatedMountPointProvider::IsolatedMountPointProvider() | 59 IsolatedMountPointProvider::IsolatedMountPointProvider( |
| 37 : isolated_file_util_(new IsolatedFileUtil()), | 60 const FilePath& profile_path) |
| 61 : profile_path_(profile_path), | |
| 62 isolated_file_util_(new IsolatedFileUtil()), | |
| 38 dragged_file_util_(new DraggedFileUtil()) { | 63 dragged_file_util_(new DraggedFileUtil()) { |
| 64 // TODO(kmadhusu): Initialize device_media_file_util_ in initialization list. | |
| 65 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
| 66 device_media_file_util_.reset(new DeviceMediaFileUtil(profile_path_)); | |
| 67 #endif | |
| 39 } | 68 } |
| 40 | 69 |
| 41 IsolatedMountPointProvider::~IsolatedMountPointProvider() { | 70 IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
| 42 } | 71 } |
| 43 | 72 |
| 44 void IsolatedMountPointProvider::ValidateFileSystemRoot( | 73 void IsolatedMountPointProvider::ValidateFileSystemRoot( |
| 45 const GURL& origin_url, | 74 const GURL& origin_url, |
| 46 FileSystemType type, | 75 FileSystemType type, |
| 47 bool create, | 76 bool create, |
| 48 const ValidateFileSystemCallback& callback) { | 77 const ValidateFileSystemCallback& callback) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 71 const FilePath& filename) const { | 100 const FilePath& filename) const { |
| 72 // TODO(kinuko): We need to check platform-specific restricted file names | 101 // TODO(kinuko): We need to check platform-specific restricted file names |
| 73 // before we actually start allowing file creation in isolated file systems. | 102 // before we actually start allowing file creation in isolated file systems. |
| 74 return false; | 103 return false; |
| 75 } | 104 } |
| 76 | 105 |
| 77 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( | 106 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( |
| 78 FileSystemType type) { | 107 FileSystemType type) { |
| 79 if (type == kFileSystemTypeDragged) | 108 if (type == kFileSystemTypeDragged) |
| 80 return dragged_file_util_.get(); | 109 return dragged_file_util_.get(); |
| 110 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
| 111 else if (type == kFileSystemTypeDeviceMedia) | |
| 112 return device_media_file_util_.get(); | |
| 113 #endif | |
| 81 else | 114 else |
| 82 return isolated_file_util_.get(); | 115 return isolated_file_util_.get(); |
| 83 } | 116 } |
| 84 | 117 |
| 85 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( | 118 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( |
| 86 const FilePath& virtual_path) const { | 119 const FilePath& virtual_path) const { |
| 87 // For isolated filesystems we only check per-filesystem permissions. | 120 // For isolated filesystems we only check per-filesystem permissions. |
| 88 NOTREACHED(); | 121 NOTREACHED(); |
| 89 return virtual_path; | 122 return virtual_path; |
| 90 } | 123 } |
| 91 | 124 |
| 92 FileSystemOperationInterface* | 125 FileSystemOperationInterface* |
| 93 IsolatedMountPointProvider::CreateFileSystemOperation( | 126 IsolatedMountPointProvider::CreateFileSystemOperation( |
| 94 const FileSystemURL& url, | 127 const FileSystemURL& url, |
| 95 FileSystemContext* context) const { | 128 FileSystemContext* context) const { |
| 96 scoped_ptr<FileSystemOperationContext> operation_context( | 129 scoped_ptr<FileSystemOperationContext> operation_context( |
| 97 new FileSystemOperationContext(context)); | 130 new FileSystemOperationContext(context)); |
| 131 | |
| 132 #if defined(SUPPORT_MEDIA_FILESYSTEM) | |
| 133 if (url.type() == kFileSystemTypeDeviceMedia) { | |
| 134 scoped_refptr<MediaDeviceInterfaceImpl> device(GetDeviceForUrl(url, | |
| 135 context)); | |
| 136 if (device.get()) | |
| 137 operation_context->set_media_device(device); | |
|
kinuko
2012/07/31 20:32:31
nit: Could this be null? Should we DCHECK?
kmadhusu
2012/08/01 01:43:59
Yes, it can be null. As we discussed, I am leaving
| |
| 138 } | |
| 139 #endif | |
| 140 | |
| 98 return new LocalFileSystemOperation(context, operation_context.Pass()); | 141 return new LocalFileSystemOperation(context, operation_context.Pass()); |
| 99 } | 142 } |
| 100 | 143 |
| 101 webkit_blob::FileStreamReader* | 144 webkit_blob::FileStreamReader* |
| 102 IsolatedMountPointProvider::CreateFileStreamReader( | 145 IsolatedMountPointProvider::CreateFileStreamReader( |
| 103 const FileSystemURL& url, | 146 const FileSystemURL& url, |
| 104 int64 offset, | 147 int64 offset, |
| 105 FileSystemContext* context) const { | 148 FileSystemContext* context) const { |
| 106 return new webkit_blob::LocalFileStreamReader( | 149 return new webkit_blob::LocalFileStreamReader( |
| 107 context->file_task_runner(), url.path(), offset, base::Time()); | 150 context->file_task_runner(), url.path(), offset, base::Time()); |
| 108 } | 151 } |
| 109 | 152 |
| 110 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( | 153 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( |
| 111 const FileSystemURL& url, | 154 const FileSystemURL& url, |
| 112 int64 offset, | 155 int64 offset, |
| 113 FileSystemContext* context) const { | 156 FileSystemContext* context) const { |
| 114 return new LocalFileStreamWriter(url.path(), offset); | 157 return new LocalFileStreamWriter(url.path(), offset); |
| 115 } | 158 } |
| 116 | 159 |
| 117 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { | 160 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
| 118 // No quota support. | 161 // No quota support. |
| 119 return NULL; | 162 return NULL; |
| 120 } | 163 } |
| 121 | 164 |
| 122 } // namespace fileapi | 165 } // namespace fileapi |
| OLD | NEW |