Chromium Code Reviews| Index: webkit/fileapi/media/local_media_file_util.cc |
| diff --git a/webkit/fileapi/media/local_media_file_util.cc b/webkit/fileapi/media/local_media_file_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..342e79b4bb11807b1a4d84162e4dfdf040383fc6 |
| --- /dev/null |
| +++ b/webkit/fileapi/media/local_media_file_util.cc |
| @@ -0,0 +1,180 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "webkit/fileapi/media/local_media_file_util.h" |
| + |
| +#include "net/base/mime_util.h" |
| +#include "webkit/fileapi/file_system_operation_context.h" |
| +#include "webkit/fileapi/media/media_path_filter.h" |
| + |
| +using base::PlatformFileError; |
| +using base::PlatformFileInfo; |
| + |
| +namespace fileapi { |
| + |
| +class MediaPathFilter; |
| + |
| +namespace { |
| + |
| +class FilteringFileEnumerator |
| + : public FileSystemFileUtil::AbstractFileEnumerator { |
| + public: |
| + FilteringFileEnumerator( |
| + scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator, |
| + MediaPathFilter* filter) |
| + : base_enumerator_(base_enumerator.Pass()), |
| + filter_(filter) { |
| + } |
| + |
| + virtual FilePath Next() OVERRIDE { |
| + { |
| + FilePath next = base_enumerator_->Next(); |
| + if (next.empty() || |
| + base_enumerator_->IsDirectory() || |
| + filter_->Match(next)) |
| + return next; |
| + } |
|
kinuko
2012/07/26 20:21:56
Why is this in a separate blocK?
tzik
2012/07/27 17:18:56
I think, this block makes Next() call tail recursi
kinuko
2012/07/28 01:23:35
Ah oh ok :) clever.
|
| + return Next(); |
|
kinuko
2012/07/26 20:21:56
Can we make this non-recursive?
tzik
2012/07/27 17:18:56
Done.
|
| + } |
| + |
| + virtual int64 Size() OVERRIDE { |
| + return base_enumerator_->Size(); |
| + } |
| + |
| + virtual base::Time LastModifiedTime() OVERRIDE { |
| + return base_enumerator_->LastModifiedTime(); |
| + } |
| + |
| + virtual bool IsDirectory() OVERRIDE { |
| + return base_enumerator_->IsDirectory(); |
| + } |
| + |
| + private: |
| + scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator_; |
| + MediaPathFilter* filter_; |
| +}; |
| +} // anonymous namespace |
|
kinuko
2012/07/28 01:23:35
nit: please add empty line between line 56 and 57.
tzik
2012/07/30 23:32:36
Done.
|
| + |
| +LocalMediaFileUtil::LocalMediaFileUtil() { |
| +} |
| + |
| + |
|
kinuko
2012/07/26 20:21:56
nit: please remove extra empty line.
tzik
2012/07/27 17:18:56
Done.
|
| +PlatformFileError LocalMediaFileUtil::CreateOrOpen( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, |
| + int file_flags, |
| + PlatformFile* file_handle, |
| + bool* created) { |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +PlatformFileError LocalMediaFileUtil::EnsureFileExists( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, bool* created) { |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
|
kinuko
2012/07/26 20:21:56
Is this FileUtil also trying to explicitly disable
tzik
2012/07/27 17:18:56
Yes, for now. We need some special handling to sup
|
| +} |
| + |
| +FileSystemFileUtil::AbstractFileEnumerator* |
| +LocalMediaFileUtil::CreateFileEnumerator( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& root_url, |
| + bool recursive) { |
| + AbstractFileEnumerator* base_enumerator = |
| + IsolatedFileUtil::CreateFileEnumerator(context, root_url, recursive); |
| + return new FilteringFileEnumerator( |
| + scoped_ptr<AbstractFileEnumerator>(base_enumerator), |
| + context->media_path_filter()); |
| +} |
| + |
| +PlatformFileError LocalMediaFileUtil::Touch( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, |
| + const base::Time& last_access_time, |
| + const base::Time& last_modified_time) { |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +PlatformFileError LocalMediaFileUtil::Truncate( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, |
| + int64 length) { |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +bool LocalMediaFileUtil::PathExists( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url) { |
| + FilePath path; |
| + PlatformFileInfo file_info; |
| + PlatformFileError error = |
| + GetFileInfo(context, url, &file_info, &path); |
| + return error == base::PLATFORM_FILE_OK; |
| +} |
| + |
| +bool LocalMediaFileUtil::IsDirectoryEmpty( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url) { |
| + DCHECK(context); |
| + DCHECK(context->media_path_filter()); |
| + |
| + scoped_ptr<AbstractFileEnumerator> enumerator( |
| + CreateFileEnumerator(context, url, false)); |
| + FilePath path; |
| + while (!(path = enumerator->Next()).empty()) { |
| + if (enumerator->IsDirectory() || |
| + context->media_path_filter()->Match(path)) |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +PlatformFileError LocalMediaFileUtil::CopyOrMoveFile( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& src_url, |
| + const FileSystemURL& dest_url, |
| + bool copy) { |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +PlatformFileError LocalMediaFileUtil::CopyInForeignFile( |
| + FileSystemOperationContext* context, |
| + const FilePath& src_file_path, |
| + const FileSystemURL& dest_url) { |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +PlatformFileError LocalMediaFileUtil::DeleteFile( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url) { |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +scoped_refptr<webkit_blob::ShareableFileReference> |
| +LocalMediaFileUtil::CreateSnapshotFile( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, |
| + base::PlatformFileError* result, |
| + base::PlatformFileInfo* file_info, |
| + FilePath* platform_path) { |
| + *result = base::PLATFORM_FILE_ERROR_SECURITY; |
|
kinuko
2012/07/26 20:21:56
Why does this just return error?
tzik
2012/07/27 17:18:56
Ah, it's an error. We shouldn't block this. Remove
|
| + return NULL; |
| +} |
| + |
| +PlatformFileError LocalMediaFileUtil::GetFileInfo( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, |
| + PlatformFileInfo* file_info, |
| + FilePath* platform_path) { |
| + base::PlatformFileError error = |
| + IsolatedFileUtil::GetFileInfo(context, url, file_info, platform_path); |
| + if (error != base::PLATFORM_FILE_OK) |
| + return error; |
| + |
| + if (file_info->is_directory || |
| + context->media_path_filter()->Match(*platform_path)) |
| + return base::PLATFORM_FILE_OK; |
| + return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| +} |
| + |
| +} // namespace fileapi |