OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/fileapi/media/native_media_file_util.h" |
| 6 |
| 7 #include "net/base/mime_util.h" |
| 8 #include "webkit/fileapi/file_system_operation_context.h" |
| 9 #include "webkit/fileapi/media/media_path_filter.h" |
| 10 |
| 11 using base::PlatformFileError; |
| 12 using base::PlatformFileInfo; |
| 13 |
| 14 namespace fileapi { |
| 15 |
| 16 class MediaPathFilter; |
| 17 |
| 18 namespace { |
| 19 |
| 20 class FilteringFileEnumerator |
| 21 : public FileSystemFileUtil::AbstractFileEnumerator { |
| 22 public: |
| 23 FilteringFileEnumerator( |
| 24 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator, |
| 25 MediaPathFilter* filter) |
| 26 : base_enumerator_(base_enumerator.Pass()), |
| 27 filter_(filter) { |
| 28 DCHECK(base_enumerator_.get()); |
| 29 DCHECK(filter); |
| 30 } |
| 31 |
| 32 virtual FilePath Next() OVERRIDE { |
| 33 while (true) { |
| 34 FilePath next = base_enumerator_->Next(); |
| 35 if (next.empty() || |
| 36 base_enumerator_->IsDirectory() || |
| 37 filter_->Match(next)) |
| 38 return next; |
| 39 } |
| 40 } |
| 41 |
| 42 virtual int64 Size() OVERRIDE { |
| 43 return base_enumerator_->Size(); |
| 44 } |
| 45 |
| 46 virtual base::Time LastModifiedTime() OVERRIDE { |
| 47 return base_enumerator_->LastModifiedTime(); |
| 48 } |
| 49 |
| 50 virtual bool IsDirectory() OVERRIDE { |
| 51 return base_enumerator_->IsDirectory(); |
| 52 } |
| 53 |
| 54 private: |
| 55 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> base_enumerator_; |
| 56 MediaPathFilter* filter_; |
| 57 }; |
| 58 |
| 59 } // namespace |
| 60 |
| 61 NativeMediaFileUtil::NativeMediaFileUtil() { |
| 62 } |
| 63 |
| 64 PlatformFileError NativeMediaFileUtil::CreateOrOpen( |
| 65 FileSystemOperationContext* context, |
| 66 const FileSystemURL& url, |
| 67 int file_flags, |
| 68 PlatformFile* file_handle, |
| 69 bool* created) { |
| 70 // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| 71 // access. |
| 72 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 73 } |
| 74 |
| 75 PlatformFileError NativeMediaFileUtil::EnsureFileExists( |
| 76 FileSystemOperationContext* context, |
| 77 const FileSystemURL& url, bool* created) { |
| 78 // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| 79 // access. |
| 80 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 81 } |
| 82 |
| 83 FileSystemFileUtil::AbstractFileEnumerator* |
| 84 NativeMediaFileUtil::CreateFileEnumerator( |
| 85 FileSystemOperationContext* context, |
| 86 const FileSystemURL& root_url, |
| 87 bool recursive) { |
| 88 DCHECK(context); |
| 89 |
| 90 AbstractFileEnumerator* base_enumerator = |
| 91 IsolatedFileUtil::CreateFileEnumerator(context, root_url, recursive); |
| 92 return new FilteringFileEnumerator( |
| 93 scoped_ptr<AbstractFileEnumerator>(base_enumerator), |
| 94 context->media_path_filter()); |
| 95 } |
| 96 |
| 97 PlatformFileError NativeMediaFileUtil::Touch( |
| 98 FileSystemOperationContext* context, |
| 99 const FileSystemURL& url, |
| 100 const base::Time& last_access_time, |
| 101 const base::Time& last_modified_time) { |
| 102 // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| 103 // access. |
| 104 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 105 } |
| 106 |
| 107 PlatformFileError NativeMediaFileUtil::Truncate( |
| 108 FileSystemOperationContext* context, |
| 109 const FileSystemURL& url, |
| 110 int64 length) { |
| 111 // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| 112 // access. |
| 113 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 114 } |
| 115 |
| 116 bool NativeMediaFileUtil::PathExists( |
| 117 FileSystemOperationContext* context, |
| 118 const FileSystemURL& url) { |
| 119 DCHECK(context); |
| 120 |
| 121 FilePath path; |
| 122 PlatformFileInfo file_info; |
| 123 PlatformFileError error = |
| 124 GetFileInfo(context, url, &file_info, &path); |
| 125 return error == base::PLATFORM_FILE_OK; |
| 126 } |
| 127 |
| 128 bool NativeMediaFileUtil::IsDirectoryEmpty( |
| 129 FileSystemOperationContext* context, |
| 130 const FileSystemURL& url) { |
| 131 DCHECK(context); |
| 132 DCHECK(context->media_path_filter()); |
| 133 |
| 134 scoped_ptr<AbstractFileEnumerator> enumerator( |
| 135 CreateFileEnumerator(context, url, false)); |
| 136 FilePath path; |
| 137 while (!(path = enumerator->Next()).empty()) { |
| 138 if (enumerator->IsDirectory() || |
| 139 context->media_path_filter()->Match(path)) |
| 140 return false; |
| 141 } |
| 142 return true; |
| 143 } |
| 144 |
| 145 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( |
| 146 FileSystemOperationContext* context, |
| 147 const FileSystemURL& src_url, |
| 148 const FileSystemURL& dest_url, |
| 149 bool copy) { |
| 150 // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| 151 // access. |
| 152 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 153 } |
| 154 |
| 155 PlatformFileError NativeMediaFileUtil::CopyInForeignFile( |
| 156 FileSystemOperationContext* context, |
| 157 const FilePath& src_file_path, |
| 158 const FileSystemURL& dest_url) { |
| 159 // TODO(tzik): Apply context()->mime_path_filter() here when we support write |
| 160 // access. |
| 161 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 162 } |
| 163 |
| 164 PlatformFileError NativeMediaFileUtil::DeleteFile( |
| 165 FileSystemOperationContext* context, |
| 166 const FileSystemURL& url) { |
| 167 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 168 } |
| 169 |
| 170 PlatformFileError NativeMediaFileUtil::GetFileInfo( |
| 171 FileSystemOperationContext* context, |
| 172 const FileSystemURL& url, |
| 173 PlatformFileInfo* file_info, |
| 174 FilePath* platform_path) { |
| 175 DCHECK(context); |
| 176 DCHECK(context->media_path_filter()); |
| 177 DCHECK(file_info); |
| 178 DCHECK(platform_path); |
| 179 |
| 180 base::PlatformFileError error = |
| 181 IsolatedFileUtil::GetFileInfo(context, url, file_info, platform_path); |
| 182 if (error != base::PLATFORM_FILE_OK) |
| 183 return error; |
| 184 |
| 185 if (file_info->is_directory || |
| 186 context->media_path_filter()->Match(*platform_path)) |
| 187 return base::PLATFORM_FILE_OK; |
| 188 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 189 } |
| 190 |
| 191 } // namespace fileapi |
OLD | NEW |