OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/chromeos/fileapi/file_system_backend.h" | 5 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" | 10 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h" |
11 #include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h" | 11 #include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h" |
12 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | |
12 #include "chromeos/dbus/cros_disks_client.h" | 13 #include "chromeos/dbus/cros_disks_client.h" |
13 #include "webkit/browser/blob/file_stream_reader.h" | 14 #include "webkit/browser/blob/file_stream_reader.h" |
14 #include "webkit/browser/fileapi/async_file_util.h" | 15 #include "webkit/browser/fileapi/async_file_util.h" |
15 #include "webkit/browser/fileapi/external_mount_points.h" | 16 #include "webkit/browser/fileapi/external_mount_points.h" |
16 #include "webkit/browser/fileapi/file_stream_writer.h" | 17 #include "webkit/browser/fileapi/file_stream_writer.h" |
17 #include "webkit/browser/fileapi/file_system_context.h" | 18 #include "webkit/browser/fileapi/file_system_context.h" |
18 #include "webkit/browser/fileapi/file_system_operation.h" | 19 #include "webkit/browser/fileapi/file_system_operation.h" |
19 #include "webkit/browser/fileapi/file_system_operation_context.h" | 20 #include "webkit/browser/fileapi/file_system_operation_context.h" |
20 #include "webkit/browser/fileapi/file_system_url.h" | 21 #include "webkit/browser/fileapi/file_system_url.h" |
21 | 22 |
22 namespace chromeos { | 23 namespace chromeos { |
23 | 24 |
24 // static | 25 // static |
25 bool FileSystemBackend::CanHandleURL(const fileapi::FileSystemURL& url) { | 26 bool FileSystemBackend::CanHandleURL(const fileapi::FileSystemURL& url) { |
26 if (!url.is_valid()) | 27 if (!url.is_valid()) |
27 return false; | 28 return false; |
28 return url.type() == fileapi::kFileSystemTypeNativeLocal || | 29 return url.type() == fileapi::kFileSystemTypeNativeLocal || |
29 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || | 30 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || |
30 url.type() == fileapi::kFileSystemTypeDrive || | 31 url.type() == fileapi::kFileSystemTypeDrive || |
31 url.type() == fileapi::kFileSystemTypeProvided; | 32 url.type() == fileapi::kFileSystemTypeProvided || |
33 url.type() == fileapi::kFileSystemTypeDeviceMediaAsFileStorage; | |
32 } | 34 } |
33 | 35 |
34 FileSystemBackend::FileSystemBackend( | 36 FileSystemBackend::FileSystemBackend( |
37 const base::FilePath& profile_path, | |
35 FileSystemBackendDelegate* drive_delegate, | 38 FileSystemBackendDelegate* drive_delegate, |
36 FileSystemBackendDelegate* file_system_provider_delegate, | 39 FileSystemBackendDelegate* file_system_provider_delegate, |
37 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 40 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
38 scoped_refptr<fileapi::ExternalMountPoints> mount_points, | 41 scoped_refptr<fileapi::ExternalMountPoints> mount_points, |
39 fileapi::ExternalMountPoints* system_mount_points) | 42 fileapi::ExternalMountPoints* system_mount_points) |
40 : special_storage_policy_(special_storage_policy), | 43 : special_storage_policy_(special_storage_policy), |
41 file_access_permissions_(new FileAccessPermissions()), | 44 file_access_permissions_(new FileAccessPermissions()), |
42 local_file_util_(fileapi::AsyncFileUtil::CreateForLocalFileSystem()), | 45 local_file_util_(fileapi::AsyncFileUtil::CreateForLocalFileSystem()), |
46 device_media_async_file_util_( | |
47 DeviceMediaAsyncFileUtil::Create(profile_path)), | |
43 drive_delegate_(drive_delegate), | 48 drive_delegate_(drive_delegate), |
44 file_system_provider_delegate_(file_system_provider_delegate), | 49 file_system_provider_delegate_(file_system_provider_delegate), |
45 mount_points_(mount_points), | 50 mount_points_(mount_points), |
46 system_mount_points_(system_mount_points) {} | 51 system_mount_points_(system_mount_points) {} |
47 | 52 |
48 FileSystemBackend::~FileSystemBackend() { | 53 FileSystemBackend::~FileSystemBackend() { |
49 } | 54 } |
50 | 55 |
51 void FileSystemBackend::AddSystemMountPoints() { | 56 void FileSystemBackend::AddSystemMountPoints() { |
52 // RegisterFileSystem() is no-op if the mount point with the same name | 57 // RegisterFileSystem() is no-op if the mount point with the same name |
(...skipping 16 matching lines...) Expand all Loading... | |
69 base::FilePath(FILE_PATH_LITERAL("/usr/share/oem"))); | 74 base::FilePath(FILE_PATH_LITERAL("/usr/share/oem"))); |
70 } | 75 } |
71 | 76 |
72 bool FileSystemBackend::CanHandleType(fileapi::FileSystemType type) const { | 77 bool FileSystemBackend::CanHandleType(fileapi::FileSystemType type) const { |
73 switch (type) { | 78 switch (type) { |
74 case fileapi::kFileSystemTypeExternal: | 79 case fileapi::kFileSystemTypeExternal: |
75 case fileapi::kFileSystemTypeDrive: | 80 case fileapi::kFileSystemTypeDrive: |
76 case fileapi::kFileSystemTypeRestrictedNativeLocal: | 81 case fileapi::kFileSystemTypeRestrictedNativeLocal: |
77 case fileapi::kFileSystemTypeNativeLocal: | 82 case fileapi::kFileSystemTypeNativeLocal: |
78 case fileapi::kFileSystemTypeNativeForPlatformApp: | 83 case fileapi::kFileSystemTypeNativeForPlatformApp: |
84 case fileapi::kFileSystemTypeDeviceMediaAsFileStorage: | |
79 return true; | 85 return true; |
80 default: | 86 default: |
81 return false; | 87 return false; |
82 } | 88 } |
83 } | 89 } |
84 | 90 |
85 void FileSystemBackend::Initialize(fileapi::FileSystemContext* context) { | 91 void FileSystemBackend::Initialize(fileapi::FileSystemContext* context) { |
86 } | 92 } |
87 | 93 |
88 void FileSystemBackend::ResolveURL(const fileapi::FileSystemURL& url, | 94 void FileSystemBackend::ResolveURL(const fileapi::FileSystemURL& url, |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 fileapi::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil( | 224 fileapi::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil( |
219 fileapi::FileSystemType type) { | 225 fileapi::FileSystemType type) { |
220 switch (type) { | 226 switch (type) { |
221 case fileapi::kFileSystemTypeDrive: | 227 case fileapi::kFileSystemTypeDrive: |
222 return drive_delegate_->GetAsyncFileUtil(type); | 228 return drive_delegate_->GetAsyncFileUtil(type); |
223 case fileapi::kFileSystemTypeProvided: | 229 case fileapi::kFileSystemTypeProvided: |
224 return file_system_provider_delegate_->GetAsyncFileUtil(type); | 230 return file_system_provider_delegate_->GetAsyncFileUtil(type); |
225 case fileapi::kFileSystemTypeNativeLocal: | 231 case fileapi::kFileSystemTypeNativeLocal: |
226 case fileapi::kFileSystemTypeRestrictedNativeLocal: | 232 case fileapi::kFileSystemTypeRestrictedNativeLocal: |
227 return local_file_util_.get(); | 233 return local_file_util_.get(); |
234 case fileapi::kFileSystemTypeDeviceMediaAsFileStorage: | |
235 return device_media_async_file_util_.get(); | |
228 default: | 236 default: |
229 NOTREACHED(); | 237 NOTREACHED(); |
230 } | 238 } |
231 return NULL; | 239 return NULL; |
232 } | 240 } |
233 | 241 |
234 fileapi::CopyOrMoveFileValidatorFactory* | 242 fileapi::CopyOrMoveFileValidatorFactory* |
235 FileSystemBackend::GetCopyOrMoveFileValidatorFactory( | 243 FileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
236 fileapi::FileSystemType type, base::File::Error* error_code) { | 244 fileapi::FileSystemType type, base::File::Error* error_code) { |
237 DCHECK(error_code); | 245 DCHECK(error_code); |
238 *error_code = base::File::FILE_OK; | 246 *error_code = base::File::FILE_OK; |
239 return NULL; | 247 return NULL; |
240 } | 248 } |
241 | 249 |
242 fileapi::FileSystemOperation* FileSystemBackend::CreateFileSystemOperation( | 250 fileapi::FileSystemOperation* FileSystemBackend::CreateFileSystemOperation( |
243 const fileapi::FileSystemURL& url, | 251 const fileapi::FileSystemURL& url, |
244 fileapi::FileSystemContext* context, | 252 fileapi::FileSystemContext* context, |
245 base::File::Error* error_code) const { | 253 base::File::Error* error_code) const { |
246 DCHECK(url.is_valid()); | 254 DCHECK(url.is_valid()); |
247 | 255 |
248 if (!IsAccessAllowed(url)) { | 256 if (!IsAccessAllowed(url)) { |
249 *error_code = base::File::FILE_ERROR_SECURITY; | 257 *error_code = base::File::FILE_ERROR_SECURITY; |
250 return NULL; | 258 return NULL; |
251 } | 259 } |
252 | 260 |
253 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || | 261 DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal || |
254 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || | 262 url.type() == fileapi::kFileSystemTypeRestrictedNativeLocal || |
255 url.type() == fileapi::kFileSystemTypeDrive); | 263 url.type() == fileapi::kFileSystemTypeDrive || |
264 url.type() == fileapi::kFileSystemTypeDeviceMediaAsFileStorage); | |
256 return fileapi::FileSystemOperation::Create( | 265 return fileapi::FileSystemOperation::Create( |
257 url, context, | 266 url, context, |
258 make_scoped_ptr(new fileapi::FileSystemOperationContext(context))); | 267 make_scoped_ptr(new fileapi::FileSystemOperationContext( |
268 context, MediaFileSystemBackend::MediaTaskRunner()))); | |
vandebo (ex-Chrome)
2014/04/23 16:24:44
Passing in the media task runner here will do the
kinaba
2014/04/24 01:33:30
Right. I can't remember why I wrote it like the fi
| |
259 } | 269 } |
260 | 270 |
261 bool FileSystemBackend::SupportsStreaming( | 271 bool FileSystemBackend::SupportsStreaming( |
262 const fileapi::FileSystemURL& url) const { | 272 const fileapi::FileSystemURL& url) const { |
263 return false; | 273 return false; |
264 } | 274 } |
265 | 275 |
266 scoped_ptr<webkit_blob::FileStreamReader> | 276 scoped_ptr<webkit_blob::FileStreamReader> |
267 FileSystemBackend::CreateFileStreamReader( | 277 FileSystemBackend::CreateFileStreamReader( |
268 const fileapi::FileSystemURL& url, | 278 const fileapi::FileSystemURL& url, |
(...skipping 10 matching lines...) Expand all Loading... | |
279 return drive_delegate_->CreateFileStreamReader( | 289 return drive_delegate_->CreateFileStreamReader( |
280 url, offset, expected_modification_time, context); | 290 url, offset, expected_modification_time, context); |
281 case fileapi::kFileSystemTypeProvided: | 291 case fileapi::kFileSystemTypeProvided: |
282 return file_system_provider_delegate_->CreateFileStreamReader( | 292 return file_system_provider_delegate_->CreateFileStreamReader( |
283 url, offset, expected_modification_time, context); | 293 url, offset, expected_modification_time, context); |
284 case fileapi::kFileSystemTypeNativeLocal: | 294 case fileapi::kFileSystemTypeNativeLocal: |
285 case fileapi::kFileSystemTypeRestrictedNativeLocal: | 295 case fileapi::kFileSystemTypeRestrictedNativeLocal: |
286 return scoped_ptr<webkit_blob::FileStreamReader>( | 296 return scoped_ptr<webkit_blob::FileStreamReader>( |
287 webkit_blob::FileStreamReader::CreateForFileSystemFile( | 297 webkit_blob::FileStreamReader::CreateForFileSystemFile( |
288 context, url, offset, expected_modification_time)); | 298 context, url, offset, expected_modification_time)); |
299 case fileapi::kFileSystemTypeDeviceMediaAsFileStorage: | |
300 // TODO(kinaba): the stream reader from device media async util limits | |
vandebo (ex-Chrome)
2014/04/23 16:24:44
I'm not sure what you mean here?
kinaba
2014/04/24 01:33:30
Revised the comment. Does it make sense?
| |
301 // itself only for reading arbitrary file types. Handle non-media files | |
302 // here as well. | |
303 return device_media_async_file_util_->GetFileStreamReader( | |
304 url, offset, expected_modification_time, context); | |
289 default: | 305 default: |
290 NOTREACHED(); | 306 NOTREACHED(); |
291 } | 307 } |
292 return scoped_ptr<webkit_blob::FileStreamReader>(); | 308 return scoped_ptr<webkit_blob::FileStreamReader>(); |
293 } | 309 } |
294 | 310 |
295 scoped_ptr<fileapi::FileStreamWriter> | 311 scoped_ptr<fileapi::FileStreamWriter> |
296 FileSystemBackend::CreateFileStreamWriter( | 312 FileSystemBackend::CreateFileStreamWriter( |
297 const fileapi::FileSystemURL& url, | 313 const fileapi::FileSystemURL& url, |
298 int64 offset, | 314 int64 offset, |
(...skipping 10 matching lines...) Expand all Loading... | |
309 return file_system_provider_delegate_->CreateFileStreamWriter( | 325 return file_system_provider_delegate_->CreateFileStreamWriter( |
310 url, offset, context); | 326 url, offset, context); |
311 case fileapi::kFileSystemTypeNativeLocal: | 327 case fileapi::kFileSystemTypeNativeLocal: |
312 return scoped_ptr<fileapi::FileStreamWriter>( | 328 return scoped_ptr<fileapi::FileStreamWriter>( |
313 fileapi::FileStreamWriter::CreateForLocalFile( | 329 fileapi::FileStreamWriter::CreateForLocalFile( |
314 context->default_file_task_runner(), url.path(), offset, | 330 context->default_file_task_runner(), url.path(), offset, |
315 fileapi::FileStreamWriter::OPEN_EXISTING_FILE)); | 331 fileapi::FileStreamWriter::OPEN_EXISTING_FILE)); |
316 case fileapi::kFileSystemTypeRestrictedNativeLocal: | 332 case fileapi::kFileSystemTypeRestrictedNativeLocal: |
317 // Restricted native local file system is read only. | 333 // Restricted native local file system is read only. |
318 return scoped_ptr<fileapi::FileStreamWriter>(); | 334 return scoped_ptr<fileapi::FileStreamWriter>(); |
335 case fileapi::kFileSystemTypeDeviceMediaAsFileStorage: | |
336 // TODO(kinaba): support writing. | |
337 return scoped_ptr<fileapi::FileStreamWriter>(); | |
319 default: | 338 default: |
320 NOTREACHED(); | 339 NOTREACHED(); |
321 } | 340 } |
322 return scoped_ptr<fileapi::FileStreamWriter>(); | 341 return scoped_ptr<fileapi::FileStreamWriter>(); |
323 } | 342 } |
324 | 343 |
325 bool FileSystemBackend::GetVirtualPath( | 344 bool FileSystemBackend::GetVirtualPath( |
326 const base::FilePath& filesystem_path, | 345 const base::FilePath& filesystem_path, |
327 base::FilePath* virtual_path) { | 346 base::FilePath* virtual_path) { |
328 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || | 347 return mount_points_->GetVirtualPath(filesystem_path, virtual_path) || |
329 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); | 348 system_mount_points_->GetVirtualPath(filesystem_path, virtual_path); |
330 } | 349 } |
331 | 350 |
332 } // namespace chromeos | 351 } // namespace chromeos |
OLD | NEW |