OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "webkit/fileapi/isolated_mount_point_provider.h" | 5 #include "webkit/fileapi/media/media_file_system_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/files/file_path.h" | 10 #include "base/files/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/platform_file.h" | 13 #include "base/platform_file.h" |
14 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
15 #include "webkit/blob/local_file_stream_reader.h" | 15 #include "webkit/blob/local_file_stream_reader.h" |
(...skipping 13 matching lines...) Expand all Loading... |
29 #include "webkit/fileapi/media/media_path_filter.h" | 29 #include "webkit/fileapi/media/media_path_filter.h" |
30 #include "webkit/fileapi/media/native_media_file_util.h" | 30 #include "webkit/fileapi/media/native_media_file_util.h" |
31 #include "webkit/fileapi/native_file_util.h" | 31 #include "webkit/fileapi/native_file_util.h" |
32 | 32 |
33 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 33 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
34 #include "webkit/fileapi/media/device_media_async_file_util.h" | 34 #include "webkit/fileapi/media/device_media_async_file_util.h" |
35 #endif | 35 #endif |
36 | 36 |
37 namespace fileapi { | 37 namespace fileapi { |
38 | 38 |
39 const char IsolatedMountPointProvider::kMediaPathFilterKey[] = | 39 const char MediaFileSystemMountPointProvider::kMediaPathFilterKey[] = |
40 "MediaPathFilterKey"; | 40 "MediaPathFilterKey"; |
41 const char IsolatedMountPointProvider::kMTPDeviceDelegateURLKey[] = | 41 const char MediaFileSystemMountPointProvider::kMTPDeviceDelegateURLKey[] = |
42 "MTPDeviceDelegateKey"; | 42 "MTPDeviceDelegateKey"; |
43 | 43 |
44 IsolatedMountPointProvider::IsolatedMountPointProvider( | 44 MediaFileSystemMountPointProvider::MediaFileSystemMountPointProvider( |
45 const base::FilePath& profile_path) | 45 const base::FilePath& profile_path) |
46 : profile_path_(profile_path), | 46 : profile_path_(profile_path), |
47 media_path_filter_(new MediaPathFilter()), | 47 media_path_filter_(new MediaPathFilter()), |
48 isolated_file_util_(new AsyncFileUtilAdapter(new IsolatedFileUtil())), | |
49 dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())), | |
50 native_media_file_util_( | 48 native_media_file_util_( |
51 new AsyncFileUtilAdapter(new NativeMediaFileUtil())) { | 49 new AsyncFileUtilAdapter(new NativeMediaFileUtil())) { |
52 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 50 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
53 // TODO(kmadhusu): Initialize |device_media_file_util_| in | 51 // TODO(kmadhusu): Initialize |device_media_file_util_| in |
54 // initialization list. | 52 // initialization list. |
55 device_media_async_file_util_.reset( | 53 device_media_async_file_util_.reset( |
56 DeviceMediaAsyncFileUtil::Create(profile_path_)); | 54 DeviceMediaAsyncFileUtil::Create(profile_path_)); |
57 #endif | 55 #endif |
58 } | 56 } |
59 | 57 |
60 IsolatedMountPointProvider::~IsolatedMountPointProvider() { | 58 MediaFileSystemMountPointProvider::~MediaFileSystemMountPointProvider() { |
61 } | 59 } |
62 | 60 |
63 bool IsolatedMountPointProvider::CanHandleType(FileSystemType type) const { | 61 bool MediaFileSystemMountPointProvider::CanHandleType( |
| 62 FileSystemType type) const { |
64 switch (type) { | 63 switch (type) { |
65 case kFileSystemTypeIsolated: | |
66 case kFileSystemTypeDragged: | |
67 case kFileSystemTypeNativeMedia: | 64 case kFileSystemTypeNativeMedia: |
68 case kFileSystemTypeDeviceMedia: | 65 case kFileSystemTypeDeviceMedia: |
69 return true; | 66 return true; |
70 #if !defined(OS_CHROMEOS) | |
71 case kFileSystemTypeNativeLocal: | |
72 case kFileSystemTypeNativeForPlatformApp: | |
73 return true; | |
74 #endif | |
75 default: | 67 default: |
76 return false; | 68 return false; |
77 } | 69 } |
78 } | 70 } |
79 | 71 |
80 void IsolatedMountPointProvider::ValidateFileSystemRoot( | 72 void MediaFileSystemMountPointProvider::ValidateFileSystemRoot( |
81 const GURL& origin_url, | 73 const GURL& origin_url, |
82 FileSystemType type, | 74 FileSystemType type, |
83 bool create, | 75 bool create, |
84 const ValidateFileSystemCallback& callback) { | 76 const ValidateFileSystemCallback& callback) { |
85 // We never allow opening a new isolated FileSystem via usual OpenFileSystem. | 77 // We never allow opening a new isolated FileSystem via usual OpenFileSystem. |
86 base::MessageLoopProxy::current()->PostTask( | 78 base::MessageLoopProxy::current()->PostTask( |
87 FROM_HERE, | 79 FROM_HERE, |
88 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); | 80 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); |
89 } | 81 } |
90 | 82 |
91 base::FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread( | 83 base::FilePath |
| 84 MediaFileSystemMountPointProvider::GetFileSystemRootPathOnFileThread( |
92 const FileSystemURL& url, | 85 const FileSystemURL& url, |
93 bool create) { | 86 bool create) { |
94 // This is not supposed to be used. | 87 // This is not supposed to be used. |
95 NOTREACHED(); | 88 NOTREACHED(); |
96 return base::FilePath(); | 89 return base::FilePath(); |
97 } | 90 } |
98 | 91 |
99 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( | 92 FileSystemFileUtil* MediaFileSystemMountPointProvider::GetFileUtil( |
100 FileSystemType type) { | 93 FileSystemType type) { |
101 switch (type) { | 94 switch (type) { |
102 case kFileSystemTypeNativeLocal: | |
103 return isolated_file_util_->sync_file_util(); | |
104 case kFileSystemTypeDragged: | |
105 return dragged_file_util_->sync_file_util(); | |
106 case kFileSystemTypeNativeMedia: | 95 case kFileSystemTypeNativeMedia: |
107 return native_media_file_util_->sync_file_util(); | 96 return native_media_file_util_->sync_file_util(); |
108 default: | 97 default: |
109 NOTREACHED(); | 98 NOTREACHED(); |
110 } | 99 } |
111 return NULL; | 100 return NULL; |
112 } | 101 } |
113 | 102 |
114 AsyncFileUtil* IsolatedMountPointProvider::GetAsyncFileUtil( | 103 AsyncFileUtil* MediaFileSystemMountPointProvider::GetAsyncFileUtil( |
115 FileSystemType type) { | 104 FileSystemType type) { |
116 switch (type) { | 105 switch (type) { |
117 case kFileSystemTypeNativeLocal: | |
118 return isolated_file_util_.get(); | |
119 case kFileSystemTypeDragged: | |
120 return dragged_file_util_.get(); | |
121 case kFileSystemTypeNativeMedia: | 106 case kFileSystemTypeNativeMedia: |
122 return native_media_file_util_.get(); | 107 return native_media_file_util_.get(); |
123 case kFileSystemTypeDeviceMedia: | 108 case kFileSystemTypeDeviceMedia: |
124 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 109 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
125 return device_media_async_file_util_.get(); | 110 return device_media_async_file_util_.get(); |
126 #endif | 111 #endif |
127 default: | 112 default: |
128 NOTREACHED(); | 113 NOTREACHED(); |
129 } | 114 } |
130 return NULL; | 115 return NULL; |
131 } | 116 } |
132 | 117 |
133 CopyOrMoveFileValidatorFactory* | 118 CopyOrMoveFileValidatorFactory* |
134 IsolatedMountPointProvider::GetCopyOrMoveFileValidatorFactory( | 119 MediaFileSystemMountPointProvider::GetCopyOrMoveFileValidatorFactory( |
135 FileSystemType type, base::PlatformFileError* error_code) { | 120 FileSystemType type, base::PlatformFileError* error_code) { |
136 DCHECK(error_code); | 121 DCHECK(error_code); |
137 *error_code = base::PLATFORM_FILE_OK; | 122 *error_code = base::PLATFORM_FILE_OK; |
138 switch (type) { | 123 switch (type) { |
139 case kFileSystemTypeNativeLocal: | |
140 case kFileSystemTypeDragged: | |
141 return NULL; | |
142 case kFileSystemTypeNativeMedia: | 124 case kFileSystemTypeNativeMedia: |
143 case kFileSystemTypeDeviceMedia: | 125 case kFileSystemTypeDeviceMedia: |
144 if (!media_copy_or_move_file_validator_factory_) { | 126 if (!media_copy_or_move_file_validator_factory_) { |
145 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | 127 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; |
146 return NULL; | 128 return NULL; |
147 } | 129 } |
148 return media_copy_or_move_file_validator_factory_.get(); | 130 return media_copy_or_move_file_validator_factory_.get(); |
149 default: | 131 default: |
150 NOTREACHED(); | 132 NOTREACHED(); |
151 } | 133 } |
152 return NULL; | 134 return NULL; |
153 } | 135 } |
154 | 136 |
155 void IsolatedMountPointProvider::InitializeCopyOrMoveFileValidatorFactory( | 137 void |
| 138 MediaFileSystemMountPointProvider::InitializeCopyOrMoveFileValidatorFactory( |
156 FileSystemType type, | 139 FileSystemType type, |
157 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) { | 140 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) { |
158 switch (type) { | 141 switch (type) { |
159 case kFileSystemTypeNativeLocal: | |
160 case kFileSystemTypeDragged: | |
161 DCHECK(factory == NULL); | |
162 break; | |
163 case kFileSystemTypeNativeMedia: | 142 case kFileSystemTypeNativeMedia: |
164 case kFileSystemTypeDeviceMedia: | 143 case kFileSystemTypeDeviceMedia: |
165 if (!media_copy_or_move_file_validator_factory_) | 144 if (!media_copy_or_move_file_validator_factory_) |
166 media_copy_or_move_file_validator_factory_.reset(factory.release()); | 145 media_copy_or_move_file_validator_factory_.reset(factory.release()); |
167 break; | 146 break; |
168 default: | 147 default: |
169 NOTREACHED(); | 148 NOTREACHED(); |
170 } | 149 } |
171 } | 150 } |
172 | 151 |
173 FilePermissionPolicy IsolatedMountPointProvider::GetPermissionPolicy( | 152 FilePermissionPolicy MediaFileSystemMountPointProvider::GetPermissionPolicy( |
174 const FileSystemURL& url, int permissions) const { | 153 const FileSystemURL& url, int permissions) const { |
175 if (url.type() == kFileSystemTypeDragged && url.path().empty()) { | 154 // Access to media file systems should be checked using per-filesystem |
176 // The root directory of the dragged filesystem must be always read-only. | |
177 if (permissions & ~fileapi::kReadFilePermissions) | |
178 return FILE_PERMISSION_ALWAYS_DENY; | |
179 } | |
180 // Access to isolated file systems should be checked using per-filesystem | |
181 // access permission. | 155 // access permission. |
182 return FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; | 156 return FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; |
183 } | 157 } |
184 | 158 |
185 FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation( | 159 FileSystemOperation* |
| 160 MediaFileSystemMountPointProvider::CreateFileSystemOperation( |
186 const FileSystemURL& url, | 161 const FileSystemURL& url, |
187 FileSystemContext* context, | 162 FileSystemContext* context, |
188 base::PlatformFileError* error_code) const { | 163 base::PlatformFileError* error_code) const { |
189 if (url.type() != kFileSystemTypeNativeMedia && | |
190 url.type() != kFileSystemTypeDeviceMedia) { | |
191 return new LocalFileSystemOperation( | |
192 context, make_scoped_ptr(new FileSystemOperationContext(context))); | |
193 } | |
194 | |
195 // For media filesystems. | |
196 scoped_ptr<FileSystemOperationContext> operation_context( | 164 scoped_ptr<FileSystemOperationContext> operation_context( |
197 new FileSystemOperationContext( | 165 new FileSystemOperationContext( |
198 context, context->task_runners()->media_task_runner())); | 166 context, context->task_runners()->media_task_runner())); |
199 | 167 |
200 operation_context->SetUserValue(kMediaPathFilterKey, | 168 operation_context->SetUserValue(kMediaPathFilterKey, |
201 media_path_filter_.get()); | 169 media_path_filter_.get()); |
202 | |
203 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) | 170 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) |
204 if (url.type() == kFileSystemTypeDeviceMedia) { | 171 if (url.type() == kFileSystemTypeDeviceMedia) { |
205 operation_context->SetUserValue(kMTPDeviceDelegateURLKey, | 172 operation_context->SetUserValue(kMTPDeviceDelegateURLKey, |
206 url.filesystem_id()); | 173 url.filesystem_id()); |
207 } | 174 } |
208 #endif | 175 #endif |
209 | 176 |
210 return new LocalFileSystemOperation(context, operation_context.Pass()); | 177 return new LocalFileSystemOperation(context, operation_context.Pass()); |
211 } | 178 } |
212 | 179 |
213 scoped_ptr<webkit_blob::FileStreamReader> | 180 scoped_ptr<webkit_blob::FileStreamReader> |
214 IsolatedMountPointProvider::CreateFileStreamReader( | 181 MediaFileSystemMountPointProvider::CreateFileStreamReader( |
215 const FileSystemURL& url, | 182 const FileSystemURL& url, |
216 int64 offset, | 183 int64 offset, |
217 const base::Time& expected_modification_time, | 184 const base::Time& expected_modification_time, |
218 FileSystemContext* context) const { | 185 FileSystemContext* context) const { |
219 return scoped_ptr<webkit_blob::FileStreamReader>( | 186 return scoped_ptr<webkit_blob::FileStreamReader>( |
220 new webkit_blob::LocalFileStreamReader( | 187 new webkit_blob::LocalFileStreamReader( |
221 context->task_runners()->file_task_runner(), | 188 context->task_runners()->file_task_runner(), |
222 url.path(), offset, expected_modification_time)); | 189 url.path(), offset, expected_modification_time)); |
223 } | 190 } |
224 | 191 |
225 scoped_ptr<FileStreamWriter> IsolatedMountPointProvider::CreateFileStreamWriter( | 192 scoped_ptr<FileStreamWriter> |
| 193 MediaFileSystemMountPointProvider::CreateFileStreamWriter( |
226 const FileSystemURL& url, | 194 const FileSystemURL& url, |
227 int64 offset, | 195 int64 offset, |
228 FileSystemContext* context) const { | 196 FileSystemContext* context) const { |
229 return scoped_ptr<FileStreamWriter>( | 197 return scoped_ptr<FileStreamWriter>( |
230 new LocalFileStreamWriter(url.path(), offset)); | 198 new LocalFileStreamWriter(url.path(), offset)); |
231 } | 199 } |
232 | 200 |
233 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { | 201 FileSystemQuotaUtil* MediaFileSystemMountPointProvider::GetQuotaUtil() { |
234 // No quota support. | 202 // No quota support. |
235 return NULL; | 203 return NULL; |
236 } | 204 } |
237 | 205 |
238 void IsolatedMountPointProvider::DeleteFileSystem( | 206 void MediaFileSystemMountPointProvider::DeleteFileSystem( |
239 const GURL& origin_url, | 207 const GURL& origin_url, |
240 FileSystemType type, | 208 FileSystemType type, |
241 FileSystemContext* context, | 209 FileSystemContext* context, |
242 const DeleteFileSystemCallback& callback) { | 210 const DeleteFileSystemCallback& callback) { |
243 NOTREACHED(); | 211 NOTREACHED(); |
244 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 212 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
245 } | 213 } |
246 | 214 |
247 } // namespace fileapi | 215 } // namespace fileapi |
OLD | NEW |