summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authortzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-07 00:12:27 +0000
committertzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-07 00:12:27 +0000
commitddbe551cd57c18397b3260c61a6ff0e4e308f923 (patch)
treece27e1aa654fff8a38584f9be9ed6e2e956448e6 /webkit
parentf3ded9f7a7164933b6c5548acbf304e6cc9b0b56 (diff)
downloadchromium_src-ddbe551cd57c18397b3260c61a6ff0e4e308f923.zip
chromium_src-ddbe551cd57c18397b3260c61a6ff0e4e308f923.tar.gz
chromium_src-ddbe551cd57c18397b3260c61a6ff0e4e308f923.tar.bz2
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
Diffstat (limited to 'webkit')
-rw-r--r--webkit/fileapi/media/device_media_file_util.cc34
-rw-r--r--webkit/fileapi/media/filtering_file_enumerator.cc44
-rw-r--r--webkit/fileapi/media/filtering_file_enumerator.h40
-rw-r--r--webkit/fileapi/media/native_media_file_util.cc56
-rw-r--r--webkit/fileapi/webkit_fileapi.gypi2
5 files changed, 123 insertions, 53 deletions
diff --git a/webkit/fileapi/media/device_media_file_util.cc b/webkit/fileapi/media/device_media_file_util.cc
index b1cbfca..ec95076 100644
--- a/webkit/fileapi/media/device_media_file_util.cc
+++ b/webkit/fileapi/media/device_media_file_util.cc
@@ -10,8 +10,10 @@
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_url.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_map_service.h"
+#include "webkit/fileapi/media/media_path_filter.h"
using base::PlatformFileError;
using base::PlatformFileInfo;
@@ -65,7 +67,15 @@ PlatformFileError DeviceMediaFileUtil::GetFileInfo(
FilePath* platform_path) {
if (!context->media_device())
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*
@@ -75,7 +85,10 @@ DeviceMediaFileUtil::CreateFileEnumerator(
bool recursive) {
if (!context->media_device())
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(
@@ -108,7 +121,11 @@ bool DeviceMediaFileUtil::PathExists(
const FileSystemURL& url) {
if (!context->media_device())
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(
@@ -124,7 +141,16 @@ bool DeviceMediaFileUtil::IsDirectoryEmpty(
const FileSystemURL& url) {
if (!context->media_device())
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(
diff --git a/webkit/fileapi/media/filtering_file_enumerator.cc b/webkit/fileapi/media/filtering_file_enumerator.cc
new file mode 100644
index 0000000..e1b9cc5
--- /dev/null
+++ b/webkit/fileapi/media/filtering_file_enumerator.cc
@@ -0,0 +1,44 @@
+// 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
diff --git a/webkit/fileapi/media/filtering_file_enumerator.h b/webkit/fileapi/media/filtering_file_enumerator.h
new file mode 100644
index 0000000..bda0708
--- /dev/null
+++ b/webkit/fileapi/media/filtering_file_enumerator.h
@@ -0,0 +1,40 @@
+// 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_
diff --git a/webkit/fileapi/media/native_media_file_util.cc b/webkit/fileapi/media/native_media_file_util.cc
index e873523..da5d6ba 100644
--- a/webkit/fileapi/media/native_media_file_util.cc
+++ b/webkit/fileapi/media/native_media_file_util.cc
@@ -7,6 +7,7 @@
#include "net/base/mime_util.h"
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/media/media_path_filter.h"
+#include "webkit/fileapi/media/filtering_file_enumerator.h"
using base::PlatformFileError;
using base::PlatformFileInfo;
@@ -15,49 +16,6 @@ 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() {
}
@@ -67,7 +25,7 @@ PlatformFileError NativeMediaFileUtil::CreateOrOpen(
int file_flags,
PlatformFile* file_handle,
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.
return base::PLATFORM_FILE_ERROR_SECURITY;
}
@@ -75,7 +33,7 @@ PlatformFileError NativeMediaFileUtil::CreateOrOpen(
PlatformFileError NativeMediaFileUtil::EnsureFileExists(
FileSystemOperationContext* context,
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.
return base::PLATFORM_FILE_ERROR_SECURITY;
}
@@ -99,7 +57,7 @@ PlatformFileError NativeMediaFileUtil::Touch(
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
+ // TODO(tzik): Apply context()->media_path_filter() here when we support write
// access.
return base::PLATFORM_FILE_ERROR_SECURITY;
}
@@ -108,7 +66,7 @@ PlatformFileError NativeMediaFileUtil::Truncate(
FileSystemOperationContext* context,
const FileSystemURL& url,
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.
return base::PLATFORM_FILE_ERROR_SECURITY;
}
@@ -147,7 +105,7 @@ PlatformFileError NativeMediaFileUtil::CopyOrMoveFile(
const FileSystemURL& src_url,
const FileSystemURL& dest_url,
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.
return base::PLATFORM_FILE_ERROR_SECURITY;
}
@@ -156,7 +114,7 @@ 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
+ // TODO(tzik): Apply context()->media_path_filter() here when we support write
// access.
return base::PLATFORM_FILE_ERROR_SECURITY;
}
diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi
index 126a0a9..c99cd63 100644
--- a/webkit/fileapi/webkit_fileapi.gypi
+++ b/webkit/fileapi/webkit_fileapi.gypi
@@ -72,6 +72,8 @@
'local_file_stream_writer.h',
'local_file_system_operation.cc',
'local_file_system_operation.h',
+ 'media/filtering_file_enumerator.cc',
+ 'media/filtering_file_enumerator.h',
'media/media_file_system_config.h',
'media/media_path_filter.cc',
'media/media_path_filter.h',