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 = GetFileInfo(context, url, &file_info, &path); |
| 130 return error == base::PLATFORM_FILE_OK; |
114 } | 131 } |
115 | 132 |
116 bool DeviceMediaFileUtil::DirectoryExists( | 133 bool DeviceMediaFileUtil::DirectoryExists( |
117 FileSystemOperationContext* context, | 134 FileSystemOperationContext* context, |
118 const FileSystemURL& url) { | 135 const FileSystemURL& url) { |
119 if (!context->media_device()) | 136 if (!context->media_device()) |
120 return false; | 137 return false; |
121 return context->media_device()->DirectoryExists(url.path()); | 138 return context->media_device()->DirectoryExists(url.path()); |
122 } | 139 } |
123 | 140 |
124 bool DeviceMediaFileUtil::IsDirectoryEmpty( | 141 bool DeviceMediaFileUtil::IsDirectoryEmpty( |
125 FileSystemOperationContext* context, | 142 FileSystemOperationContext* context, |
126 const FileSystemURL& url) { | 143 const FileSystemURL& url) { |
127 if (!context->media_device()) | 144 if (!context->media_device()) |
128 return false; | 145 return false; |
129 return context->media_device()->IsDirectoryEmpty(url.path()); | 146 |
| 147 scoped_ptr<AbstractFileEnumerator> enumerator( |
| 148 CreateFileEnumerator(context, url, false)); |
| 149 FilePath path; |
| 150 while (!(path = enumerator->Next()).empty()) { |
| 151 if (enumerator->IsDirectory() || |
| 152 context->media_path_filter()->Match(path)) |
| 153 return false; |
| 154 } |
| 155 return true; |
130 } | 156 } |
131 | 157 |
132 PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile( | 158 PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile( |
133 FileSystemOperationContext* context, | 159 FileSystemOperationContext* context, |
134 const FileSystemURL& src_url, | 160 const FileSystemURL& src_url, |
135 const FileSystemURL& dest_url, | 161 const FileSystemURL& dest_url, |
136 bool copy) { | 162 bool copy) { |
137 return base::PLATFORM_FILE_ERROR_SECURITY; | 163 return base::PLATFORM_FILE_ERROR_SECURITY; |
138 } | 164 } |
139 | 165 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 file_info); | 219 file_info); |
194 if (*result == base::PLATFORM_FILE_OK) { | 220 if (*result == base::PLATFORM_FILE_OK) { |
195 file_ref = ShareableFileReference::GetOrCreate( | 221 file_ref = ShareableFileReference::GetOrCreate( |
196 *local_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 222 *local_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
197 context->file_task_runner()); | 223 context->file_task_runner()); |
198 } | 224 } |
199 return file_ref; | 225 return file_ref; |
200 } | 226 } |
201 | 227 |
202 } // namespace fileapi | 228 } // namespace fileapi |
OLD | NEW |