OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "storage/browser/fileapi/sandbox_file_system_backend_delegate.h" | 5 #include "storage/browser/fileapi/sandbox_file_system_backend_delegate.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 REPORT(kNotFound); | 641 REPORT(kNotFound); |
642 break; | 642 break; |
643 case base::File::FILE_ERROR_FAILED: | 643 case base::File::FILE_ERROR_FAILED: |
644 default: | 644 default: |
645 REPORT(kUnknownError); | 645 REPORT(kUnknownError); |
646 break; | 646 break; |
647 } | 647 } |
648 #undef REPORT | 648 #undef REPORT |
649 } | 649 } |
650 | 650 |
| 651 void SandboxFileSystemBackendDelegate::CopyFileSystem( |
| 652 const GURL& origin_url, |
| 653 FileSystemType type, |
| 654 SandboxFileSystemBackendDelegate* destination) { |
| 655 DCHECK(file_task_runner()->RunsTasksOnCurrentThread()); |
| 656 |
| 657 base::FilePath base_path = |
| 658 GetBaseDirectoryForOriginAndType(origin_url, type, false /* create */); |
| 659 if (base::PathExists(base_path)) { |
| 660 // Delete any existing file system directories in the destination. A |
| 661 // previously failed migration |
| 662 // may have left behind partially copied directories. |
| 663 base::FilePath dest_path = destination->GetBaseDirectoryForOriginAndType( |
| 664 origin_url, type, false /* create */); |
| 665 |
| 666 // Make sure we're not about to delete our own file system. |
| 667 CHECK_NE(base_path.value(), dest_path.value()); |
| 668 base::DeleteFile(dest_path, true); |
| 669 |
| 670 dest_path = destination->GetBaseDirectoryForOriginAndType( |
| 671 origin_url, type, true /* create */); |
| 672 |
| 673 obfuscated_file_util()->CloseFileSystemForOriginAndType( |
| 674 origin_url, GetTypeString(type)); |
| 675 base::CopyDirectory(base_path, dest_path.DirName(), true /* rescursive */); |
| 676 } |
| 677 } |
| 678 |
651 ObfuscatedFileUtil* SandboxFileSystemBackendDelegate::obfuscated_file_util() { | 679 ObfuscatedFileUtil* SandboxFileSystemBackendDelegate::obfuscated_file_util() { |
652 return static_cast<ObfuscatedFileUtil*>(sync_file_util()); | 680 return static_cast<ObfuscatedFileUtil*>(sync_file_util()); |
653 } | 681 } |
654 | 682 |
655 // Declared in obfuscated_file_util.h. | 683 // Declared in obfuscated_file_util.h. |
656 // static | 684 // static |
657 ObfuscatedFileUtil* ObfuscatedFileUtil::CreateForTesting( | 685 ObfuscatedFileUtil* ObfuscatedFileUtil::CreateForTesting( |
658 storage::SpecialStoragePolicy* special_storage_policy, | 686 storage::SpecialStoragePolicy* special_storage_policy, |
659 const base::FilePath& file_system_directory, | 687 const base::FilePath& file_system_directory, |
660 leveldb::Env* env_override, | 688 leveldb::Env* env_override, |
661 base::SequencedTaskRunner* file_task_runner) { | 689 base::SequencedTaskRunner* file_task_runner) { |
662 return new ObfuscatedFileUtil(special_storage_policy, | 690 return new ObfuscatedFileUtil(special_storage_policy, |
663 file_system_directory, | 691 file_system_directory, |
664 env_override, | 692 env_override, |
665 file_task_runner, | 693 file_task_runner, |
666 base::Bind(&GetTypeStringForURL), | 694 base::Bind(&GetTypeStringForURL), |
667 GetKnownTypeStrings(), | 695 GetKnownTypeStrings(), |
668 NULL); | 696 NULL); |
669 } | 697 } |
670 | 698 |
671 } // namespace storage | 699 } // namespace storage |
OLD | NEW |