Commit ddbe551c authored by tzik@chromium.org's avatar tzik@chromium.org

Add path filtering to DeviceMediaFileUtil

BUG=137670

Review URL: https://chromiumcodereview.appspot.com/10823171

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150183 0039d316-1c4b-4281-b951-d872f2087c98
parent f3ded9f7
...@@ -10,8 +10,10 @@ ...@@ -10,8 +10,10 @@
#include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_url.h" #include "webkit/fileapi/file_system_url.h"
#include "webkit/fileapi/isolated_context.h" #include "webkit/fileapi/isolated_context.h"
#include "webkit/fileapi/media/filtering_file_enumerator.h"
#include "webkit/fileapi/media/media_device_interface_impl.h" #include "webkit/fileapi/media/media_device_interface_impl.h"
#include "webkit/fileapi/media/media_device_map_service.h" #include "webkit/fileapi/media/media_device_map_service.h"
#include "webkit/fileapi/media/media_path_filter.h"
using base::PlatformFileError; using base::PlatformFileError;
using base::PlatformFileInfo; using base::PlatformFileInfo;
...@@ -65,7 +67,15 @@ PlatformFileError DeviceMediaFileUtil::GetFileInfo( ...@@ -65,7 +67,15 @@ PlatformFileError DeviceMediaFileUtil::GetFileInfo(
FilePath* platform_path) { FilePath* platform_path) {
if (!context->media_device()) if (!context->media_device())
return base::PLATFORM_FILE_ERROR_NOT_FOUND; return base::PLATFORM_FILE_ERROR_NOT_FOUND;
return context->media_device()->GetFileInfo(url.path(), file_info); PlatformFileError error =
context->media_device()->GetFileInfo(url.path(), file_info);
if (error != base::PLATFORM_FILE_OK)
return error;
if (file_info->is_directory ||
context->media_path_filter()->Match(url.path()))
return base::PLATFORM_FILE_OK;
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
} }
FileSystemFileUtil::AbstractFileEnumerator* FileSystemFileUtil::AbstractFileEnumerator*
...@@ -75,7 +85,10 @@ DeviceMediaFileUtil::CreateFileEnumerator( ...@@ -75,7 +85,10 @@ DeviceMediaFileUtil::CreateFileEnumerator(
bool recursive) { bool recursive) {
if (!context->media_device()) if (!context->media_device())
return new FileSystemFileUtil::EmptyFileEnumerator(); return new FileSystemFileUtil::EmptyFileEnumerator();
return context->media_device()->CreateFileEnumerator(url.path(), recursive); return new FilteringFileEnumerator(
make_scoped_ptr(
context->media_device()->CreateFileEnumerator(url.path(), recursive)),
context->media_path_filter());
} }
PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( PlatformFileError DeviceMediaFileUtil::GetLocalFilePath(
...@@ -108,7 +121,11 @@ bool DeviceMediaFileUtil::PathExists( ...@@ -108,7 +121,11 @@ bool DeviceMediaFileUtil::PathExists(
const FileSystemURL& url) { const FileSystemURL& url) {
if (!context->media_device()) if (!context->media_device())
return false; return false;
return context->media_device()->PathExists(url.path());
FilePath path;
PlatformFileInfo file_info;
PlatformFileError error = GetFileInfo(context, url, &file_info, &path);
return error == base::PLATFORM_FILE_OK;
} }
bool DeviceMediaFileUtil::DirectoryExists( bool DeviceMediaFileUtil::DirectoryExists(
...@@ -124,7 +141,16 @@ bool DeviceMediaFileUtil::IsDirectoryEmpty( ...@@ -124,7 +141,16 @@ bool DeviceMediaFileUtil::IsDirectoryEmpty(
const FileSystemURL& url) { const FileSystemURL& url) {
if (!context->media_device()) if (!context->media_device())
return false; return false;
return context->media_device()->IsDirectoryEmpty(url.path());
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 DeviceMediaFileUtil::CopyOrMoveFile( PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile(
......
// 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 "base/logging.h"
#include "webkit/fileapi/media/filtering_file_enumerator.h"
namespace fileapi {
FilteringFileEnumerator::FilteringFileEnumerator(
scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator,
MediaPathFilter* filter)
: base_enumerator_(base_enumerator.Pass()),
filter_(filter) {
DCHECK(base_enumerator_.get());
DCHECK(filter);
}
FilteringFileEnumerator::~FilteringFileEnumerator() {
}
FilePath FilteringFileEnumerator::Next() {
while (true) {
FilePath next = base_enumerator_->Next();
if (next.empty() ||
base_enumerator_->IsDirectory() ||
filter_->Match(next))
return next;
}
}
int64 FilteringFileEnumerator::Size() {
return base_enumerator_->Size();
}
base::Time FilteringFileEnumerator::LastModifiedTime() {
return base_enumerator_->LastModifiedTime();
}
bool FilteringFileEnumerator::IsDirectory() {
return base_enumerator_->IsDirectory();
}
} // namespace fileapi
// 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.
#ifndef WEBKIT_FILEAPI_MEDIA_FILTERING_FILE_ENUMERATOR_H_
#define WEBKIT_FILEAPI_MEDIA_FILTERING_FILE_ENUMERATOR_H_
#include "base/memory/scoped_ptr.h"
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/fileapi_export.h"
#include "webkit/fileapi/media/media_path_filter.h"
namespace fileapi {
// This class wraps another file enumerator and filters out non-media files
// from its result, refering given MediaPathFilter.
class FILEAPI_EXPORT FilteringFileEnumerator
: public NON_EXPORTED_BASE(FileSystemFileUtil::AbstractFileEnumerator) {
public:
FilteringFileEnumerator(
scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator,
MediaPathFilter* filter);
virtual ~FilteringFileEnumerator();
virtual FilePath Next() OVERRIDE;
virtual int64 Size() OVERRIDE;
virtual base::Time LastModifiedTime() OVERRIDE;
virtual bool IsDirectory() OVERRIDE;
private:
// The file enumerator to be wrapped.
scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator_;
// Path filter to filter out non-Media files.
MediaPathFilter* filter_;
};
} // namespace fileapi
#endif // WEBKIT_FILEAPI_MEDIA_FILTERING_FILE_ENUMERATOR_H_
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "net/base/mime_util.h" #include "net/base/mime_util.h"
#include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/media/media_path_filter.h" #include "webkit/fileapi/media/media_path_filter.h"
#include "webkit/fileapi/media/filtering_file_enumerator.h"
using base::PlatformFileError; using base::PlatformFileError;
using base::PlatformFileInfo; using base::PlatformFileInfo;
...@@ -15,49 +16,6 @@ namespace fileapi { ...@@ -15,49 +16,6 @@ namespace fileapi {
class MediaPathFilter; 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() { NativeMediaFileUtil::NativeMediaFileUtil() {
} }
...@@ -67,7 +25,7 @@ PlatformFileError NativeMediaFileUtil::CreateOrOpen( ...@@ -67,7 +25,7 @@ PlatformFileError NativeMediaFileUtil::CreateOrOpen(
int file_flags, int file_flags,
PlatformFile* file_handle, PlatformFile* file_handle,
bool* created) { bool* created) {
// TODO(tzik): Apply context()->mime_path_filter() here when we support write // TODO(tzik): Apply context()->media_path_filter() here when we support write
// access. // access.
return base::PLATFORM_FILE_ERROR_SECURITY; return base::PLATFORM_FILE_ERROR_SECURITY;
} }
...@@ -75,7 +33,7 @@ PlatformFileError NativeMediaFileUtil::CreateOrOpen( ...@@ -75,7 +33,7 @@ PlatformFileError NativeMediaFileUtil::CreateOrOpen(
PlatformFileError NativeMediaFileUtil::EnsureFileExists( PlatformFileError NativeMediaFileUtil::EnsureFileExists(
FileSystemOperationContext* context, FileSystemOperationContext* context,
const FileSystemURL& url, bool* created) { const FileSystemURL& url, bool* created) {
// TODO(tzik): Apply context()->mime_path_filter() here when we support write // TODO(tzik): Apply context()->media_path_filter() here when we support write
// access. // access.
return base::PLATFORM_FILE_ERROR_SECURITY; return base::PLATFORM_FILE_ERROR_SECURITY;
} }
...@@ -99,7 +57,7 @@ PlatformFileError NativeMediaFileUtil::Touch( ...@@ -99,7 +57,7 @@ PlatformFileError NativeMediaFileUtil::Touch(
const FileSystemURL& url, const FileSystemURL& url,
const base::Time& last_access_time, const base::Time& last_access_time,
const base::Time& last_modified_time) { const base::Time& last_modified_time) {
// TODO(tzik): Apply context()->mime_path_filter() here when we support write // TODO(tzik): Apply context()->media_path_filter() here when we support write
// access. // access.
return base::PLATFORM_FILE_ERROR_SECURITY; return base::PLATFORM_FILE_ERROR_SECURITY;
} }
...@@ -108,7 +66,7 @@ PlatformFileError NativeMediaFileUtil::Truncate( ...@@ -108,7 +66,7 @@ PlatformFileError NativeMediaFileUtil::Truncate(
FileSystemOperationContext* context, FileSystemOperationContext* context,
const FileSystemURL& url, const FileSystemURL& url,
int64 length) { int64 length) {
// TODO(tzik): Apply context()->mime_path_filter() here when we support write // TODO(tzik): Apply context()->media_path_filter() here when we support write
// access. // access.
return base::PLATFORM_FILE_ERROR_SECURITY; return base::PLATFORM_FILE_ERROR_SECURITY;
} }
...@@ -147,7 +105,7 @@ PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( ...@@ -147,7 +105,7 @@ PlatformFileError NativeMediaFileUtil::CopyOrMoveFile(
const FileSystemURL& src_url, const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
bool copy) { bool copy) {
// TODO(tzik): Apply context()->mime_path_filter() here when we support write // TODO(tzik): Apply context()->media_path_filter() here when we support write
// access. // access.
return base::PLATFORM_FILE_ERROR_SECURITY; return base::PLATFORM_FILE_ERROR_SECURITY;
} }
...@@ -156,7 +114,7 @@ PlatformFileError NativeMediaFileUtil::CopyInForeignFile( ...@@ -156,7 +114,7 @@ PlatformFileError NativeMediaFileUtil::CopyInForeignFile(
FileSystemOperationContext* context, FileSystemOperationContext* context,
const FilePath& src_file_path, const FilePath& src_file_path,
const FileSystemURL& dest_url) { const FileSystemURL& dest_url) {
// TODO(tzik): Apply context()->mime_path_filter() here when we support write // TODO(tzik): Apply context()->media_path_filter() here when we support write
// access. // access.
return base::PLATFORM_FILE_ERROR_SECURITY; return base::PLATFORM_FILE_ERROR_SECURITY;
} }
......
...@@ -72,6 +72,8 @@ ...@@ -72,6 +72,8 @@
'local_file_stream_writer.h', 'local_file_stream_writer.h',
'local_file_system_operation.cc', 'local_file_system_operation.cc',
'local_file_system_operation.h', 'local_file_system_operation.h',
'media/filtering_file_enumerator.cc',
'media/filtering_file_enumerator.h',
'media/media_file_system_config.h', 'media/media_file_system_config.h',
'media/media_path_filter.cc', 'media/media_path_filter.cc',
'media/media_path_filter.h', 'media/media_path_filter.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment