Chromium Code Reviews| Index: webkit/fileapi/media/native_media_file_util.cc |
| diff --git a/webkit/fileapi/media/native_media_file_util.cc b/webkit/fileapi/media/native_media_file_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e87352380e7b441992d7c14fb9a12df8b4192167 |
| --- /dev/null |
| +++ b/webkit/fileapi/media/native_media_file_util.cc |
| @@ -0,0 +1,191 @@ |
| +// 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/native_media_file_util.h" |
|
vandebo (ex-Chrome)
2012/08/01 01:11:05
Maybe I'm wrong, but it seems that in the end, thi
tzik
2012/08/01 21:46:06
NativeFileUtil is no longer a subclass of FileSyst
|
| + |
| +#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) { |
| + DCHECK(base_enumerator_.get()); |
| + DCHECK(filter); |
| + } |
| + |
| + virtual FilePath Next() OVERRIDE { |
| + while (true) { |
| + FilePath next = base_enumerator_->Next(); |
| + if (next.empty() || |
| + base_enumerator_->IsDirectory() || |
| + filter_->Match(next)) |
| + return next; |
| + } |
| + } |
| + |
| + 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_; |
| +}; |
| + |
| +} // namespace |
| + |
| +NativeMediaFileUtil::NativeMediaFileUtil() { |
| +} |
| + |
| +PlatformFileError NativeMediaFileUtil::CreateOrOpen( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, |
| + int file_flags, |
| + PlatformFile* file_handle, |
| + bool* created) { |
| + // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| + // access. |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +PlatformFileError NativeMediaFileUtil::EnsureFileExists( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, bool* created) { |
| + // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| + // access. |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +FileSystemFileUtil::AbstractFileEnumerator* |
| +NativeMediaFileUtil::CreateFileEnumerator( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& root_url, |
| + bool recursive) { |
| + DCHECK(context); |
| + |
| + AbstractFileEnumerator* base_enumerator = |
| + IsolatedFileUtil::CreateFileEnumerator(context, root_url, recursive); |
| + return new FilteringFileEnumerator( |
| + scoped_ptr<AbstractFileEnumerator>(base_enumerator), |
| + context->media_path_filter()); |
| +} |
| + |
| +PlatformFileError NativeMediaFileUtil::Touch( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, |
| + const base::Time& last_access_time, |
| + const base::Time& last_modified_time) { |
| + // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| + // access. |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +PlatformFileError NativeMediaFileUtil::Truncate( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, |
| + int64 length) { |
| + // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| + // access. |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +bool NativeMediaFileUtil::PathExists( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url) { |
| + DCHECK(context); |
| + |
| + FilePath path; |
| + PlatformFileInfo file_info; |
| + PlatformFileError error = |
| + GetFileInfo(context, url, &file_info, &path); |
| + return error == base::PLATFORM_FILE_OK; |
| +} |
| + |
| +bool NativeMediaFileUtil::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 NativeMediaFileUtil::CopyOrMoveFile( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& src_url, |
| + const FileSystemURL& dest_url, |
| + bool copy) { |
| + // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| + // access. |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +PlatformFileError NativeMediaFileUtil::CopyInForeignFile( |
| + FileSystemOperationContext* context, |
| + const FilePath& src_file_path, |
| + const FileSystemURL& dest_url) { |
| + // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| + // access. |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +PlatformFileError NativeMediaFileUtil::DeleteFile( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url) { |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| + |
| +PlatformFileError NativeMediaFileUtil::GetFileInfo( |
| + FileSystemOperationContext* context, |
| + const FileSystemURL& url, |
| + PlatformFileInfo* file_info, |
| + FilePath* platform_path) { |
| + DCHECK(context); |
| + DCHECK(context->media_path_filter()); |
| + DCHECK(file_info); |
| + DCHECK(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 |