Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/media/device_media_file_util.h" | 5 #include "webkit/fileapi/media/device_media_file_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "webkit/blob/shareable_file_reference.h" | 10 #include "webkit/blob/shareable_file_reference.h" |
| 11 #include "webkit/fileapi/file_system_operation_context.h" | 11 #include "webkit/fileapi/file_system_operation_context.h" |
| 12 #include "webkit/fileapi/file_system_url.h" | 12 #include "webkit/fileapi/file_system_url.h" |
| 13 #include "webkit/fileapi/isolated_context.h" | 13 #include "webkit/fileapi/isolated_context.h" |
| 14 #include "webkit/fileapi/media/filtering_file_enumerator.h" | |
| 14 #include "webkit/fileapi/media/media_device_interface_impl.h" | 15 #include "webkit/fileapi/media/media_device_interface_impl.h" |
| 15 #include "webkit/fileapi/media/media_device_map_service.h" | 16 #include "webkit/fileapi/media/media_device_map_service.h" |
| 17 #include "webkit/fileapi/media/media_path_filter.h" | |
| 16 | 18 |
| 17 using base::PlatformFileError; | 19 using base::PlatformFileError; |
| 18 using base::PlatformFileInfo; | 20 using base::PlatformFileInfo; |
| 19 using webkit_blob::ShareableFileReference; | 21 using webkit_blob::ShareableFileReference; |
| 20 | 22 |
| 21 namespace fileapi { | 23 namespace fileapi { |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 const FilePath::CharType kDeviceMediaFileUtilTempDir[] = | 27 const FilePath::CharType kDeviceMediaFileUtilTempDir[] = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 return base::PLATFORM_FILE_ERROR_SECURITY; | 62 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 61 } | 63 } |
| 62 | 64 |
| 63 PlatformFileError DeviceMediaFileUtil::GetFileInfo( | 65 PlatformFileError DeviceMediaFileUtil::GetFileInfo( |
| 64 FileSystemOperationContext* context, | 66 FileSystemOperationContext* context, |
| 65 const FileSystemURL& url, | 67 const FileSystemURL& url, |
| 66 PlatformFileInfo* file_info, | 68 PlatformFileInfo* file_info, |
| 67 FilePath* platform_path) { | 69 FilePath* platform_path) { |
| 68 if (!context->media_device()) | 70 if (!context->media_device()) |
| 69 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 71 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 70 return context->media_device()->GetFileInfo(url.path(), file_info); | 72 PlatformFileError error = |
| 73 context->media_device()->GetFileInfo(url.path(), file_info); | |
| 74 if (error != base::PLATFORM_FILE_OK) | |
| 75 return error; | |
| 76 | |
| 77 if (file_info->is_directory || | |
| 78 context->media_path_filter()->Match(url.path())) | |
| 79 return base::PLATFORM_FILE_OK; | |
| 80 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 71 } | 81 } |
| 72 | 82 |
| 73 FileSystemFileUtil::AbstractFileEnumerator* | 83 FileSystemFileUtil::AbstractFileEnumerator* |
| 74 DeviceMediaFileUtil::CreateFileEnumerator( | 84 DeviceMediaFileUtil::CreateFileEnumerator( |
| 75 FileSystemOperationContext* context, | 85 FileSystemOperationContext* context, |
| 76 const FileSystemURL& url, | 86 const FileSystemURL& url, |
| 77 bool recursive) { | 87 bool recursive) { |
| 78 if (!context->media_device()) | 88 if (!context->media_device()) |
| 79 return new FileSystemFileUtil::EmptyFileEnumerator(); | 89 return new FileSystemFileUtil::EmptyFileEnumerator(); |
| 80 return context->media_device()->CreateFileEnumerator(url.path(), recursive); | 90 return new FilteringFileEnumerator( |
| 91 make_scoped_ptr( | |
| 92 context->media_device()->CreateFileEnumerator(url.path(), recursive)), | |
| 93 context->media_path_filter()); | |
| 81 } | 94 } |
| 82 | 95 |
| 83 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( | 96 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( |
| 84 FileSystemOperationContext* context, | 97 FileSystemOperationContext* context, |
| 85 const FileSystemURL& file_system_url, | 98 const FileSystemURL& file_system_url, |
| 86 FilePath* local_file_path) { | 99 FilePath* local_file_path) { |
| 87 return base::PLATFORM_FILE_ERROR_SECURITY; | 100 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 88 } | 101 } |
| 89 | 102 |
| 90 PlatformFileError DeviceMediaFileUtil::Touch( | 103 PlatformFileError DeviceMediaFileUtil::Touch( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 103 const FileSystemURL& url, | 116 const FileSystemURL& url, |
| 104 int64 length) { | 117 int64 length) { |
| 105 return base::PLATFORM_FILE_ERROR_SECURITY; | 118 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 106 } | 119 } |
| 107 | 120 |
| 108 bool DeviceMediaFileUtil::PathExists( | 121 bool DeviceMediaFileUtil::PathExists( |
| 109 FileSystemOperationContext* context, | 122 FileSystemOperationContext* context, |
| 110 const FileSystemURL& url) { | 123 const FileSystemURL& url) { |
| 111 if (!context->media_device()) | 124 if (!context->media_device()) |
| 112 return false; | 125 return false; |
| 113 return context->media_device()->PathExists(url.path()); | 126 |
| 127 FilePath path; | |
| 128 PlatformFileInfo file_info; | |
| 129 PlatformFileError error = | |
| 130 GetFileInfo(context, url, &file_info, &path); | |
|
kmadhusu
2012/08/03 23:58:47
nit: Try to fit as much as possible in line 129.
tzik
2012/08/04 01:00:42
Done.
| |
| 131 return error == base::PLATFORM_FILE_OK; | |
| 114 } | 132 } |
| 115 | 133 |
| 116 bool DeviceMediaFileUtil::DirectoryExists( | 134 bool DeviceMediaFileUtil::DirectoryExists( |
| 117 FileSystemOperationContext* context, | 135 FileSystemOperationContext* context, |
| 118 const FileSystemURL& url) { | 136 const FileSystemURL& url) { |
| 119 if (!context->media_device()) | 137 if (!context->media_device()) |
| 120 return false; | 138 return false; |
| 121 return context->media_device()->DirectoryExists(url.path()); | 139 return context->media_device()->DirectoryExists(url.path()); |
| 122 } | 140 } |
| 123 | 141 |
| 124 bool DeviceMediaFileUtil::IsDirectoryEmpty( | 142 bool DeviceMediaFileUtil::IsDirectoryEmpty( |
| 125 FileSystemOperationContext* context, | 143 FileSystemOperationContext* context, |
| 126 const FileSystemURL& url) { | 144 const FileSystemURL& url) { |
| 127 if (!context->media_device()) | 145 if (!context->media_device()) |
| 128 return false; | 146 return false; |
| 129 return context->media_device()->IsDirectoryEmpty(url.path()); | 147 |
| 148 scoped_ptr<AbstractFileEnumerator> enumerator( | |
| 149 CreateFileEnumerator(context, url, false)); | |
| 150 FilePath path; | |
| 151 while (!(path = enumerator->Next()).empty()) { | |
| 152 if (enumerator->IsDirectory() || | |
| 153 context->media_path_filter()->Match(path)) | |
| 154 return false; | |
| 155 } | |
| 156 return true; | |
| 130 } | 157 } |
| 131 | 158 |
| 132 PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile( | 159 PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile( |
| 133 FileSystemOperationContext* context, | 160 FileSystemOperationContext* context, |
| 134 const FileSystemURL& src_url, | 161 const FileSystemURL& src_url, |
| 135 const FileSystemURL& dest_url, | 162 const FileSystemURL& dest_url, |
| 136 bool copy) { | 163 bool copy) { |
| 137 return base::PLATFORM_FILE_ERROR_SECURITY; | 164 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 138 } | 165 } |
| 139 | 166 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 file_info); | 220 file_info); |
| 194 if (*result == base::PLATFORM_FILE_OK) { | 221 if (*result == base::PLATFORM_FILE_OK) { |
| 195 file_ref = ShareableFileReference::GetOrCreate( | 222 file_ref = ShareableFileReference::GetOrCreate( |
| 196 *local_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 223 *local_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
| 197 context->file_task_runner()); | 224 context->file_task_runner()); |
| 198 } | 225 } |
| 199 return file_ref; | 226 return file_ref; |
| 200 } | 227 } |
| 201 | 228 |
| 202 } // namespace fileapi | 229 } // namespace fileapi |
| OLD | NEW |