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/native_media_file_util.h" | 5 #include "webkit/fileapi/media/native_media_file_util.h" |
6 | 6 |
7 #include "webkit/fileapi/file_system_operation_context.h" | 7 #include "webkit/fileapi/file_system_operation_context.h" |
| 8 #include "webkit/fileapi/isolated_mount_point_provider.h" |
| 9 #include "webkit/fileapi/media/filtering_file_enumerator.h" |
8 #include "webkit/fileapi/media/media_path_filter.h" | 10 #include "webkit/fileapi/media/media_path_filter.h" |
9 #include "webkit/fileapi/media/filtering_file_enumerator.h" | |
10 #include "webkit/fileapi/native_file_util.h" | 11 #include "webkit/fileapi/native_file_util.h" |
11 | 12 |
12 using base::PlatformFile; | 13 using base::PlatformFile; |
13 using base::PlatformFileError; | 14 using base::PlatformFileError; |
14 using base::PlatformFileInfo; | 15 using base::PlatformFileInfo; |
15 | 16 |
16 namespace fileapi { | 17 namespace fileapi { |
17 | 18 |
| 19 namespace { |
| 20 |
| 21 MediaPathFilter* GetMediaPathFilter(FileSystemOperationContext* context) { |
| 22 return context->GetUserValue<MediaPathFilter*>( |
| 23 IsolatedMountPointProvider::kMediaPathFilterKey); |
| 24 } |
| 25 |
| 26 } // namespace |
| 27 |
18 NativeMediaFileUtil::NativeMediaFileUtil() { | 28 NativeMediaFileUtil::NativeMediaFileUtil() { |
19 } | 29 } |
20 | 30 |
21 PlatformFileError NativeMediaFileUtil::CreateOrOpen( | 31 PlatformFileError NativeMediaFileUtil::CreateOrOpen( |
22 FileSystemOperationContext* context, | 32 FileSystemOperationContext* context, |
23 const FileSystemURL& url, | 33 const FileSystemURL& url, |
24 int file_flags, | 34 int file_flags, |
25 PlatformFile* file_handle, | 35 PlatformFile* file_handle, |
26 bool* created) { | 36 bool* created) { |
27 // Only called by NaCl, which should not have access to media file systems. | 37 // Only called by NaCl, which should not have access to media file systems. |
(...skipping 10 matching lines...) Expand all Loading... |
38 return NativeFileUtil::EnsureFileExists(file_path, created); | 48 return NativeFileUtil::EnsureFileExists(file_path, created); |
39 } | 49 } |
40 | 50 |
41 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> | 51 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> |
42 NativeMediaFileUtil::CreateFileEnumerator( | 52 NativeMediaFileUtil::CreateFileEnumerator( |
43 FileSystemOperationContext* context, | 53 FileSystemOperationContext* context, |
44 const FileSystemURL& root_url) { | 54 const FileSystemURL& root_url) { |
45 DCHECK(context); | 55 DCHECK(context); |
46 return make_scoped_ptr(new FilteringFileEnumerator( | 56 return make_scoped_ptr(new FilteringFileEnumerator( |
47 IsolatedFileUtil::CreateFileEnumerator(context, root_url), | 57 IsolatedFileUtil::CreateFileEnumerator(context, root_url), |
48 context->media_path_filter())) | 58 GetMediaPathFilter(context))) |
49 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 59 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); |
50 } | 60 } |
51 | 61 |
52 PlatformFileError NativeMediaFileUtil::Touch( | 62 PlatformFileError NativeMediaFileUtil::Touch( |
53 FileSystemOperationContext* context, | 63 FileSystemOperationContext* context, |
54 const FileSystemURL& url, | 64 const FileSystemURL& url, |
55 const base::Time& last_access_time, | 65 const base::Time& last_access_time, |
56 const base::Time& last_modified_time) { | 66 const base::Time& last_modified_time) { |
57 base::FilePath file_path; | 67 base::FilePath file_path; |
58 PlatformFileError error = GetFilteredLocalFilePathForExistingFileOrDirectory( | 68 PlatformFileError error = GetFilteredLocalFilePathForExistingFileOrDirectory( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 error = GetLocalFilePath(context, dest_url, &dest_file_path); | 112 error = GetLocalFilePath(context, dest_url, &dest_file_path); |
103 if (error != base::PLATFORM_FILE_OK) | 113 if (error != base::PLATFORM_FILE_OK) |
104 return error; | 114 return error; |
105 PlatformFileInfo file_info; | 115 PlatformFileInfo file_info; |
106 error = NativeFileUtil::GetFileInfo(dest_file_path, &file_info); | 116 error = NativeFileUtil::GetFileInfo(dest_file_path, &file_info); |
107 if (error != base::PLATFORM_FILE_OK && | 117 if (error != base::PLATFORM_FILE_OK && |
108 error != base::PLATFORM_FILE_ERROR_NOT_FOUND) | 118 error != base::PLATFORM_FILE_ERROR_NOT_FOUND) |
109 return error; | 119 return error; |
110 if (error == base::PLATFORM_FILE_OK && file_info.is_directory) | 120 if (error == base::PLATFORM_FILE_OK && file_info.is_directory) |
111 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 121 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
112 if (!context->media_path_filter()->Match(dest_file_path)) | 122 if (!GetMediaPathFilter(context)->Match(dest_file_path)) |
113 return base::PLATFORM_FILE_ERROR_SECURITY; | 123 return base::PLATFORM_FILE_ERROR_SECURITY; |
114 | 124 |
115 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy); | 125 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy); |
116 } | 126 } |
117 | 127 |
118 PlatformFileError NativeMediaFileUtil::CopyInForeignFile( | 128 PlatformFileError NativeMediaFileUtil::CopyInForeignFile( |
119 FileSystemOperationContext* context, | 129 FileSystemOperationContext* context, |
120 const base::FilePath& src_file_path, | 130 const base::FilePath& src_file_path, |
121 const FileSystemURL& dest_url) { | 131 const FileSystemURL& dest_url) { |
122 if (src_file_path.empty()) | 132 if (src_file_path.empty()) |
(...skipping 13 matching lines...) Expand all Loading... |
136 base::FilePath file_path; | 146 base::FilePath file_path; |
137 PlatformFileError error = GetLocalFilePath(context, url, &file_path); | 147 PlatformFileError error = GetLocalFilePath(context, url, &file_path); |
138 if (error != base::PLATFORM_FILE_OK) | 148 if (error != base::PLATFORM_FILE_OK) |
139 return error; | 149 return error; |
140 PlatformFileInfo file_info; | 150 PlatformFileInfo file_info; |
141 error = NativeFileUtil::GetFileInfo(file_path, &file_info); | 151 error = NativeFileUtil::GetFileInfo(file_path, &file_info); |
142 if (error != base::PLATFORM_FILE_OK) | 152 if (error != base::PLATFORM_FILE_OK) |
143 return error; | 153 return error; |
144 if (file_info.is_directory) | 154 if (file_info.is_directory) |
145 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 155 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
146 if (!context->media_path_filter()->Match(file_path)) | 156 if (!GetMediaPathFilter(context)->Match(file_path)) |
147 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 157 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
148 return NativeFileUtil::DeleteFile(file_path); | 158 return NativeFileUtil::DeleteFile(file_path); |
149 } | 159 } |
150 | 160 |
151 PlatformFileError NativeMediaFileUtil::GetFileInfo( | 161 PlatformFileError NativeMediaFileUtil::GetFileInfo( |
152 FileSystemOperationContext* context, | 162 FileSystemOperationContext* context, |
153 const FileSystemURL& url, | 163 const FileSystemURL& url, |
154 PlatformFileInfo* file_info, | 164 PlatformFileInfo* file_info, |
155 base::FilePath* platform_path) { | 165 base::FilePath* platform_path) { |
156 DCHECK(context); | 166 DCHECK(context); |
157 DCHECK(context->media_path_filter()); | 167 DCHECK(GetMediaPathFilter(context)); |
158 DCHECK(file_info); | 168 DCHECK(file_info); |
159 DCHECK(platform_path); | 169 DCHECK(platform_path); |
160 | 170 |
161 base::PlatformFileError error = | 171 base::PlatformFileError error = |
162 IsolatedFileUtil::GetFileInfo(context, url, file_info, platform_path); | 172 IsolatedFileUtil::GetFileInfo(context, url, file_info, platform_path); |
163 if (error != base::PLATFORM_FILE_OK) | 173 if (error != base::PLATFORM_FILE_OK) |
164 return error; | 174 return error; |
165 | 175 |
166 if (file_info->is_directory || | 176 if (file_info->is_directory || |
167 context->media_path_filter()->Match(*platform_path)) { | 177 GetMediaPathFilter(context)->Match(*platform_path)) { |
168 return base::PLATFORM_FILE_OK; | 178 return base::PLATFORM_FILE_OK; |
169 } | 179 } |
170 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 180 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
171 } | 181 } |
172 | 182 |
173 PlatformFileError NativeMediaFileUtil::GetFilteredLocalFilePath( | 183 PlatformFileError NativeMediaFileUtil::GetFilteredLocalFilePath( |
174 FileSystemOperationContext* context, | 184 FileSystemOperationContext* context, |
175 const FileSystemURL& file_system_url, | 185 const FileSystemURL& file_system_url, |
176 base::FilePath* local_file_path) { | 186 base::FilePath* local_file_path) { |
177 base::FilePath file_path; | 187 base::FilePath file_path; |
178 PlatformFileError error = | 188 PlatformFileError error = |
179 IsolatedFileUtil::GetLocalFilePath(context, file_system_url, &file_path); | 189 IsolatedFileUtil::GetLocalFilePath(context, file_system_url, &file_path); |
180 if (error != base::PLATFORM_FILE_OK) | 190 if (error != base::PLATFORM_FILE_OK) |
181 return error; | 191 return error; |
182 if (!context->media_path_filter()->Match(file_path)) | 192 if (!GetMediaPathFilter(context)->Match(file_path)) |
183 return base::PLATFORM_FILE_ERROR_SECURITY; | 193 return base::PLATFORM_FILE_ERROR_SECURITY; |
184 | 194 |
185 *local_file_path = file_path; | 195 *local_file_path = file_path; |
186 return base::PLATFORM_FILE_OK; | 196 return base::PLATFORM_FILE_OK; |
187 } | 197 } |
188 | 198 |
189 PlatformFileError | 199 PlatformFileError |
190 NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory( | 200 NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory( |
191 FileSystemOperationContext* context, | 201 FileSystemOperationContext* context, |
192 const FileSystemURL& file_system_url, | 202 const FileSystemURL& file_system_url, |
193 PlatformFileError failure_error, | 203 PlatformFileError failure_error, |
194 base::FilePath* local_file_path) { | 204 base::FilePath* local_file_path) { |
195 base::FilePath file_path; | 205 base::FilePath file_path; |
196 PlatformFileError error = | 206 PlatformFileError error = |
197 GetLocalFilePath(context, file_system_url, &file_path); | 207 GetLocalFilePath(context, file_system_url, &file_path); |
198 if (error != base::PLATFORM_FILE_OK) | 208 if (error != base::PLATFORM_FILE_OK) |
199 return error; | 209 return error; |
200 | 210 |
201 if (!file_util::PathExists(file_path)) | 211 if (!file_util::PathExists(file_path)) |
202 return failure_error; | 212 return failure_error; |
203 PlatformFileInfo file_info; | 213 PlatformFileInfo file_info; |
204 if (!file_util::GetFileInfo(file_path, &file_info)) | 214 if (!file_util::GetFileInfo(file_path, &file_info)) |
205 return base::PLATFORM_FILE_ERROR_FAILED; | 215 return base::PLATFORM_FILE_ERROR_FAILED; |
206 | 216 |
207 if (!file_info.is_directory && | 217 if (!file_info.is_directory && |
208 !context->media_path_filter()->Match(file_path)) { | 218 !GetMediaPathFilter(context)->Match(file_path)) { |
209 return failure_error; | 219 return failure_error; |
210 } | 220 } |
211 | 221 |
212 *local_file_path = file_path; | 222 *local_file_path = file_path; |
213 return base::PLATFORM_FILE_OK; | 223 return base::PLATFORM_FILE_OK; |
214 } | 224 } |
215 | 225 |
216 } // namespace fileapi | 226 } // namespace fileapi |
OLD | NEW |