| 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/browser/fileapi/local_file_util.h" | 5 #include "webkit/browser/fileapi/local_file_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
| 9 #include "base/files/file_util_proxy.h" | 9 #include "base/files/file_util_proxy.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 11 #include "webkit/browser/fileapi/async_file_util_adapter.h" | 11 #include "webkit/browser/fileapi/async_file_util_adapter.h" |
| 12 #include "webkit/browser/fileapi/file_system_context.h" | 12 #include "webkit/browser/fileapi/file_system_context.h" |
| 13 #include "webkit/browser/fileapi/file_system_operation_context.h" | 13 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 14 #include "webkit/browser/fileapi/file_system_url.h" | 14 #include "webkit/browser/fileapi/file_system_url.h" |
| 15 #include "webkit/browser/fileapi/native_file_util.h" | 15 #include "webkit/browser/fileapi/native_file_util.h" |
| 16 #include "webkit/common/fileapi/file_system_types.h" | 16 #include "webkit/common/fileapi/file_system_types.h" |
| 17 #include "webkit/common/fileapi/file_system_util.h" | 17 #include "webkit/common/fileapi/file_system_util.h" |
| 18 | 18 |
| 19 namespace fileapi { | 19 namespace storage { |
| 20 | 20 |
| 21 AsyncFileUtil* AsyncFileUtil::CreateForLocalFileSystem() { | 21 AsyncFileUtil* AsyncFileUtil::CreateForLocalFileSystem() { |
| 22 return new AsyncFileUtilAdapter(new LocalFileUtil()); | 22 return new AsyncFileUtilAdapter(new LocalFileUtil()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 class LocalFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { | 25 class LocalFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { |
| 26 public: | 26 public: |
| 27 LocalFileEnumerator(const base::FilePath& platform_root_path, | 27 LocalFileEnumerator(const base::FilePath& platform_root_path, |
| 28 const base::FilePath& virtual_root_path, | 28 const base::FilePath& virtual_root_path, |
| 29 int file_type) | 29 int file_type) |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 base::File::Error error = GetLocalFilePath(context, src_url, &src_file_path); | 195 base::File::Error error = GetLocalFilePath(context, src_url, &src_file_path); |
| 196 if (error != base::File::FILE_OK) | 196 if (error != base::File::FILE_OK) |
| 197 return error; | 197 return error; |
| 198 | 198 |
| 199 base::FilePath dest_file_path; | 199 base::FilePath dest_file_path; |
| 200 error = GetLocalFilePath(context, dest_url, &dest_file_path); | 200 error = GetLocalFilePath(context, dest_url, &dest_file_path); |
| 201 if (error != base::File::FILE_OK) | 201 if (error != base::File::FILE_OK) |
| 202 return error; | 202 return error; |
| 203 | 203 |
| 204 return NativeFileUtil::CopyOrMoveFile( | 204 return NativeFileUtil::CopyOrMoveFile( |
| 205 src_file_path, dest_file_path, option, | 205 src_file_path, |
| 206 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, copy)); | 206 dest_file_path, |
| 207 option, |
| 208 storage::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, copy)); |
| 207 } | 209 } |
| 208 | 210 |
| 209 base::File::Error LocalFileUtil::CopyInForeignFile( | 211 base::File::Error LocalFileUtil::CopyInForeignFile( |
| 210 FileSystemOperationContext* context, | 212 FileSystemOperationContext* context, |
| 211 const base::FilePath& src_file_path, | 213 const base::FilePath& src_file_path, |
| 212 const FileSystemURL& dest_url) { | 214 const FileSystemURL& dest_url) { |
| 213 if (src_file_path.empty()) | 215 if (src_file_path.empty()) |
| 214 return base::File::FILE_ERROR_INVALID_OPERATION; | 216 return base::File::FILE_ERROR_INVALID_OPERATION; |
| 215 | 217 |
| 216 base::FilePath dest_file_path; | 218 base::FilePath dest_file_path; |
| 217 base::File::Error error = | 219 base::File::Error error = |
| 218 GetLocalFilePath(context, dest_url, &dest_file_path); | 220 GetLocalFilePath(context, dest_url, &dest_file_path); |
| 219 if (error != base::File::FILE_OK) | 221 if (error != base::File::FILE_OK) |
| 220 return error; | 222 return error; |
| 221 return NativeFileUtil::CopyOrMoveFile( | 223 return NativeFileUtil::CopyOrMoveFile( |
| 222 src_file_path, dest_file_path, FileSystemOperation::OPTION_NONE, | 224 src_file_path, |
| 223 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, | 225 dest_file_path, |
| 226 FileSystemOperation::OPTION_NONE, |
| 227 storage::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, |
| 224 true /* copy */)); | 228 true /* copy */)); |
| 225 } | 229 } |
| 226 | 230 |
| 227 base::File::Error LocalFileUtil::DeleteFile( | 231 base::File::Error LocalFileUtil::DeleteFile( |
| 228 FileSystemOperationContext* context, | 232 FileSystemOperationContext* context, |
| 229 const FileSystemURL& url) { | 233 const FileSystemURL& url) { |
| 230 base::FilePath file_path; | 234 base::FilePath file_path; |
| 231 base::File::Error error = GetLocalFilePath(context, url, &file_path); | 235 base::File::Error error = GetLocalFilePath(context, url, &file_path); |
| 232 if (error != base::File::FILE_OK) | 236 if (error != base::File::FILE_OK) |
| 233 return error; | 237 return error; |
| 234 return NativeFileUtil::DeleteFile(file_path); | 238 return NativeFileUtil::DeleteFile(file_path); |
| 235 } | 239 } |
| 236 | 240 |
| 237 base::File::Error LocalFileUtil::DeleteDirectory( | 241 base::File::Error LocalFileUtil::DeleteDirectory( |
| 238 FileSystemOperationContext* context, | 242 FileSystemOperationContext* context, |
| 239 const FileSystemURL& url) { | 243 const FileSystemURL& url) { |
| 240 base::FilePath file_path; | 244 base::FilePath file_path; |
| 241 base::File::Error error = GetLocalFilePath(context, url, &file_path); | 245 base::File::Error error = GetLocalFilePath(context, url, &file_path); |
| 242 if (error != base::File::FILE_OK) | 246 if (error != base::File::FILE_OK) |
| 243 return error; | 247 return error; |
| 244 return NativeFileUtil::DeleteDirectory(file_path); | 248 return NativeFileUtil::DeleteDirectory(file_path); |
| 245 } | 249 } |
| 246 | 250 |
| 247 webkit_blob::ScopedFile LocalFileUtil::CreateSnapshotFile( | 251 storage::ScopedFile LocalFileUtil::CreateSnapshotFile( |
| 248 FileSystemOperationContext* context, | 252 FileSystemOperationContext* context, |
| 249 const FileSystemURL& url, | 253 const FileSystemURL& url, |
| 250 base::File::Error* error, | 254 base::File::Error* error, |
| 251 base::File::Info* file_info, | 255 base::File::Info* file_info, |
| 252 base::FilePath* platform_path) { | 256 base::FilePath* platform_path) { |
| 253 DCHECK(file_info); | 257 DCHECK(file_info); |
| 254 // We're just returning the local file information. | 258 // We're just returning the local file information. |
| 255 *error = GetFileInfo(context, url, file_info, platform_path); | 259 *error = GetFileInfo(context, url, file_info, platform_path); |
| 256 if (*error == base::File::FILE_OK && file_info->is_directory) | 260 if (*error == base::File::FILE_OK && file_info->is_directory) |
| 257 *error = base::File::FILE_ERROR_NOT_A_FILE; | 261 *error = base::File::FILE_ERROR_NOT_A_FILE; |
| 258 return webkit_blob::ScopedFile(); | 262 return storage::ScopedFile(); |
| 259 } | 263 } |
| 260 | 264 |
| 261 } // namespace fileapi | 265 } // namespace storage |
| OLD | NEW |