Chromium Code Reviews| 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 "chrome/browser/extensions/api/developer_private/developer_private_api. h" | 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h" |
| 6 | 6 |
| 7 #include "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
| 8 #include "apps/app_restore_service.h" | 8 #include "apps/app_restore_service.h" |
| 9 #include "apps/saved_files_service.h" | 9 #include "apps/saved_files_service.h" |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 827 if (!file_util::Delete(project_path, true/*recursive*/)) { | 827 if (!file_util::Delete(project_path, true/*recursive*/)) { |
| 828 SetError("Error in copying files from sync filesystem."); | 828 SetError("Error in copying files from sync filesystem."); |
| 829 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 829 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 830 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 830 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| 831 SendResponse, | 831 SendResponse, |
| 832 this, | 832 this, |
| 833 false)); | 833 false)); |
| 834 return; | 834 return; |
| 835 } | 835 } |
| 836 | 836 |
| 837 pendingCallbacksCount_ = 1; | |
| 838 | |
| 837 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 839 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 838 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 840 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| 839 ReadSyncFileSystemDirectory, | 841 ReadSyncFileSystemDirectory, |
| 840 this, project_path)); | 842 this, project_path, project_path.BaseName())); |
| 841 } | 843 } |
| 842 | 844 |
| 843 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 845 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| 844 ReadSyncFileSystemDirectory(const base::FilePath& project_path) { | 846 ReadSyncFileSystemDirectory(const base::FilePath& project_path, |
| 847 const base::FilePath& current_path) { | |
| 845 std::string origin_url( | 848 std::string origin_url( |
| 846 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); | 849 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); |
| 847 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( | 850 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( |
| 848 GURL(origin_url), | 851 GURL(origin_url), |
| 849 project_path.BaseName())); | 852 current_path)); |
| 850 | 853 |
| 851 context_->operation_runner()->ReadDirectory( | 854 context_->operation_runner()->ReadDirectory( |
| 852 url, base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 855 url, base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| 853 ReadSyncFileSystemDirectoryCb, this, project_path)); | 856 ReadSyncFileSystemDirectoryCb, |
| 857 this, project_path, current_path)); | |
| 854 } | 858 } |
| 855 | 859 |
| 856 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 860 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| 857 ReadSyncFileSystemDirectoryCb( | 861 ReadSyncFileSystemDirectoryCb( |
| 858 const base::FilePath& project_path, | 862 const base::FilePath& project_path, |
| 863 const base::FilePath& current_path, | |
| 859 base::PlatformFileError status, | 864 base::PlatformFileError status, |
| 860 const fileapi::FileSystemOperation::FileEntryList& file_list, | 865 const fileapi::FileSystemOperation::FileEntryList& file_list, |
| 861 bool has_more) { | 866 bool has_more) { |
| 862 | 867 |
| 863 if (status != base::PLATFORM_FILE_OK) { | 868 if (status != base::PLATFORM_FILE_OK) { |
| 864 DLOG(ERROR) << "Error in copying files from sync filesystem."; | 869 DLOG(ERROR) << "Error in copying files from sync filesystem."; |
| 865 return; | 870 return; |
| 866 } | 871 } |
| 867 | 872 |
| 868 // Create an empty project folder if there are no files. | 873 pendingCallbacksCount_ += file_list.size(); |
|
miket_OOO
2013/06/12 19:39:24
This is pretty confusing. You're adding N to pendi
Gaurav
2013/06/21 22:11:00
Done.
| |
| 869 if (!file_list.size()) { | |
| 870 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | |
| 871 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | |
| 872 CreateFolderAndSendResponse, | |
| 873 this, | |
| 874 project_path)); | |
| 875 return; | |
| 876 } | |
| 877 | |
| 878 pendingCallbacksCount_ = file_list.size(); | |
| 879 | 874 |
| 880 for (size_t i = 0; i < file_list.size(); ++i) { | 875 for (size_t i = 0; i < file_list.size(); ++i) { |
| 876 if (file_list[i].is_directory) { | |
| 877 ReadSyncFileSystemDirectory(project_path.Append(file_list[i].name), | |
| 878 current_path.Append(file_list[i].name)); | |
| 879 continue; | |
|
miket_OOO
2013/06/12 19:39:24
This is a good example of why it's confusing. It s
Gaurav
2013/06/21 22:11:00
Done.
| |
| 880 } | |
| 881 | |
| 881 std::string origin_url( | 882 std::string origin_url( |
| 882 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); | 883 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); |
| 883 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( | 884 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( |
| 884 GURL(origin_url), | 885 GURL(origin_url), |
| 885 project_path.BaseName().Append(file_list[i].name))); | 886 current_path.Append(file_list[i].name))); |
| 886 base::FilePath target_path = project_path; | 887 base::FilePath target_path = project_path; |
| 887 target_path = target_path.Append(file_list[i].name); | 888 target_path = target_path.Append(file_list[i].name); |
| 888 | 889 |
| 889 context_->operation_runner()->CreateSnapshotFile( | 890 context_->operation_runner()->CreateSnapshotFile( |
| 890 url, | 891 url, |
| 891 base::Bind( | 892 base::Bind( |
| 892 &DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 893 &DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| 893 SnapshotFileCallback, | 894 SnapshotFileCallback, |
| 894 this, | 895 this, |
| 895 target_path)); | 896 target_path)); |
| 897 | |
| 898 } | |
| 899 pendingCallbacksCount_--; | |
| 900 if (!pendingCallbacksCount_) { | |
| 901 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 902 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | |
| 903 SendResponse, | |
| 904 this, | |
| 905 success_)); | |
| 896 } | 906 } |
| 897 } | 907 } |
| 898 | 908 |
| 899 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | |
| 900 CreateFolderAndSendResponse(const base::FilePath& project_path) { | |
| 901 if (!(success_ = file_util::CreateDirectory(project_path))) { | |
| 902 SetError("Error in copying files from sync filesystem."); | |
| 903 } | |
| 904 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 905 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | |
| 906 SendResponse, | |
| 907 this, | |
| 908 success_)); | |
| 909 } | |
| 910 | |
| 911 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::SnapshotFileCallback( | 909 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::SnapshotFileCallback( |
| 912 const base::FilePath& target_path, | 910 const base::FilePath& target_path, |
| 913 base::PlatformFileError result, | 911 base::PlatformFileError result, |
| 914 const base::PlatformFileInfo& file_info, | 912 const base::PlatformFileInfo& file_info, |
| 915 const base::FilePath& src_path, | 913 const base::FilePath& src_path, |
| 916 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 914 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
| 917 if (result != base::PLATFORM_FILE_OK) { | 915 if (result != base::PLATFORM_FILE_OK) { |
| 918 SetError("Error in copying files from sync filesystem."); | 916 SetError("Error in copying files from sync filesystem."); |
| 919 success_ = false; | 917 success_ = false; |
| 920 return; | 918 return; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1138 | 1136 |
| 1139 #undef SET_STRING | 1137 #undef SET_STRING |
| 1140 return true; | 1138 return true; |
| 1141 } | 1139 } |
| 1142 | 1140 |
| 1143 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} | 1141 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} |
| 1144 | 1142 |
| 1145 } // namespace api | 1143 } // namespace api |
| 1146 | 1144 |
| 1147 } // namespace extensions | 1145 } // namespace extensions |
| OLD | NEW |