OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/obfuscated_file_system_file_util.h" | 5 #include "webkit/fileapi/obfuscated_file_system_file_util.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 277 } |
278 } | 278 } |
279 return base::PLATFORM_FILE_OK; | 279 return base::PLATFORM_FILE_OK; |
280 } | 280 } |
281 | 281 |
282 PlatformFileError ObfuscatedFileSystemFileUtil::CopyOrMoveFile( | 282 PlatformFileError ObfuscatedFileSystemFileUtil::CopyOrMoveFile( |
283 FileSystemOperationContext* context, | 283 FileSystemOperationContext* context, |
284 const FilePath& src_file_path, | 284 const FilePath& src_file_path, |
285 const FilePath& dest_file_path, | 285 const FilePath& dest_file_path, |
286 bool copy) { | 286 bool copy) { |
287 // TODO(ericu): Handle multi-db move+copy, where src and dest aren't in the | |
288 // same database. Currently we'll just fail badly. This may get handled from | |
289 // higher-level code, though, and as we don't have cross-filesystem | |
290 // transactions that's not any less efficient than doing it here. | |
291 FileSystemDirectoryDatabase* db = | 287 FileSystemDirectoryDatabase* db = |
292 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 288 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
293 if (!db) | 289 if (!db) |
294 return base::PLATFORM_FILE_ERROR_FAILED; | 290 return base::PLATFORM_FILE_ERROR_FAILED; |
295 FileId src_file_id; | 291 FileId src_file_id; |
296 if (!db->GetFileWithPath(src_file_path, &src_file_id)) | 292 if (!db->GetFileWithPath(src_file_path, &src_file_id)) |
297 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 293 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
298 FileId dest_file_id; | 294 FileId dest_file_id; |
299 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); | 295 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); |
300 FileInfo src_file_info; | 296 FileInfo src_file_info; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 src_file_info.name = dest_file_path.BaseName().value(); | 361 src_file_info.name = dest_file_path.BaseName().value(); |
366 if (!db->UpdateFileInfo(src_file_id, src_file_info)) | 362 if (!db->UpdateFileInfo(src_file_id, src_file_info)) |
367 return base::PLATFORM_FILE_ERROR_FAILED; | 363 return base::PLATFORM_FILE_ERROR_FAILED; |
368 return base::PLATFORM_FILE_OK; | 364 return base::PLATFORM_FILE_OK; |
369 } | 365 } |
370 } | 366 } |
371 NOTREACHED(); | 367 NOTREACHED(); |
372 return base::PLATFORM_FILE_ERROR_FAILED; | 368 return base::PLATFORM_FILE_ERROR_FAILED; |
373 } | 369 } |
374 | 370 |
| 371 PlatformFileError ObfuscatedFileSystemFileUtil::CopyInForeignFile( |
| 372 FileSystemOperationContext* context, |
| 373 const FilePath& src_file_path, |
| 374 const FilePath& dest_file_path) { |
| 375 FileSystemDirectoryDatabase* db = |
| 376 GetDirectoryDatabase(context->dest_origin_url(), context->dest_type()); |
| 377 if (!db) |
| 378 return base::PLATFORM_FILE_ERROR_FAILED; |
| 379 FileId dest_file_id; |
| 380 bool overwrite = db->GetFileWithPath(dest_file_path, &dest_file_id); |
| 381 FileInfo dest_file_info; |
| 382 if (overwrite) { |
| 383 if (!db->GetFileInfo(dest_file_id, &dest_file_info) || |
| 384 dest_file_info.is_directory()) { |
| 385 NOTREACHED(); |
| 386 return base::PLATFORM_FILE_ERROR_FAILED; |
| 387 } |
| 388 FilePath dest_data_path = DataPathToLocalPath(context->dest_origin_url(), |
| 389 context->dest_type(), dest_file_info.data_path); |
| 390 return QuotaFileUtil::GetInstance()->CopyOrMoveFile(context, |
| 391 src_file_path, dest_data_path, true /* copy */); |
| 392 } else { |
| 393 FileId dest_parent_id; |
| 394 if (!db->GetFileWithPath(dest_file_path.DirName(), &dest_parent_id)) { |
| 395 NOTREACHED(); // We shouldn't be called in this case. |
| 396 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 397 } |
| 398 InitFileInfo(&dest_file_info, dest_parent_id, |
| 399 dest_file_path.BaseName().value()); |
| 400 return CreateFile(context, context->dest_origin_url(), |
| 401 context->dest_type(), src_file_path, &dest_file_info, 0, NULL); |
| 402 } |
| 403 return base::PLATFORM_FILE_ERROR_FAILED; |
| 404 } |
| 405 |
375 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteFile( | 406 PlatformFileError ObfuscatedFileSystemFileUtil::DeleteFile( |
376 FileSystemOperationContext* context, | 407 FileSystemOperationContext* context, |
377 const FilePath& virtual_path) { | 408 const FilePath& virtual_path) { |
378 FileSystemDirectoryDatabase* db = | 409 FileSystemDirectoryDatabase* db = |
379 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); | 410 GetDirectoryDatabase(context->src_origin_url(), context->src_type()); |
380 if (!db) | 411 if (!db) |
381 return base::PLATFORM_FILE_ERROR_FAILED; | 412 return base::PLATFORM_FILE_ERROR_FAILED; |
382 FileId file_id; | 413 FileId file_id; |
383 if (!db->GetFileWithPath(virtual_path, &file_id)) | 414 if (!db->GetFileWithPath(virtual_path, &file_id)) |
384 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 415 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 return false; | 993 return false; |
963 } | 994 } |
964 origin_database_.reset( | 995 origin_database_.reset( |
965 new FileSystemOriginDatabase( | 996 new FileSystemOriginDatabase( |
966 file_system_directory_.AppendASCII(kOriginDatabaseName))); | 997 file_system_directory_.AppendASCII(kOriginDatabaseName))); |
967 } | 998 } |
968 return true; | 999 return true; |
969 } | 1000 } |
970 | 1001 |
971 } // namespace fileapi | 1002 } // namespace fileapi |
OLD | NEW |