Chromium Code Reviews| 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 if (base::PathExists(dest_path)) { | |
|
cmumford
2015/01/06 15:30:27
Consider disposing of the exists check and just ca
| |
| 666 // Make sure we're not about to delete our own file system. | |
| 667 CHECK(base_path != dest_path); | |
|
cmumford
2015/01/06 15:30:27
CHECK_NE
| |
| 668 base::DeleteFile(dest_path, true); | |
| 669 } | |
| 670 | |
| 671 // Create the required path in the destination | |
| 672 dest_path = destination->GetBaseDirectoryForOriginAndType( | |
| 673 origin_url, type, true /* create */); | |
| 674 | |
| 675 obfuscated_file_util()->CloseFileSystemForOriginAndType( | |
| 676 origin_url, GetTypeString(type)); | |
| 677 base::CopyDirectory(base_path, dest_path.DirName(), true /* rescursive */); | |
| 678 } | |
| 679 } | |
| 680 | |
| 651 ObfuscatedFileUtil* SandboxFileSystemBackendDelegate::obfuscated_file_util() { | 681 ObfuscatedFileUtil* SandboxFileSystemBackendDelegate::obfuscated_file_util() { |
| 652 return static_cast<ObfuscatedFileUtil*>(sync_file_util()); | 682 return static_cast<ObfuscatedFileUtil*>(sync_file_util()); |
| 653 } | 683 } |
| 654 | 684 |
| 655 // Declared in obfuscated_file_util.h. | 685 // Declared in obfuscated_file_util.h. |
| 656 // static | 686 // static |
| 657 ObfuscatedFileUtil* ObfuscatedFileUtil::CreateForTesting( | 687 ObfuscatedFileUtil* ObfuscatedFileUtil::CreateForTesting( |
| 658 storage::SpecialStoragePolicy* special_storage_policy, | 688 storage::SpecialStoragePolicy* special_storage_policy, |
| 659 const base::FilePath& file_system_directory, | 689 const base::FilePath& file_system_directory, |
| 660 leveldb::Env* env_override, | 690 leveldb::Env* env_override, |
| 661 base::SequencedTaskRunner* file_task_runner) { | 691 base::SequencedTaskRunner* file_task_runner) { |
| 662 return new ObfuscatedFileUtil(special_storage_policy, | 692 return new ObfuscatedFileUtil(special_storage_policy, |
| 663 file_system_directory, | 693 file_system_directory, |
| 664 env_override, | 694 env_override, |
| 665 file_task_runner, | 695 file_task_runner, |
| 666 base::Bind(&GetTypeStringForURL), | 696 base::Bind(&GetTypeStringForURL), |
| 667 GetKnownTypeStrings(), | 697 GetKnownTypeStrings(), |
| 668 NULL); | 698 NULL); |
| 669 } | 699 } |
| 670 | 700 |
| 671 } // namespace storage | 701 } // namespace storage |
| OLD | NEW |