| 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_window.h" | 8 #include "apps/app_window.h" |
| 9 #include "apps/app_window_registry.h" | 9 #include "apps/app_window_registry.h" |
| 10 #include "apps/saved_files_service.h" | 10 #include "apps/saved_files_service.h" |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); | 1063 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
| 1064 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); | 1064 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
| 1065 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &directory_url_str)); | 1065 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &directory_url_str)); |
| 1066 | 1066 |
| 1067 context_ = content::BrowserContext::GetStoragePartition( | 1067 context_ = content::BrowserContext::GetStoragePartition( |
| 1068 GetProfile(), render_view_host()->GetSiteInstance()) | 1068 GetProfile(), render_view_host()->GetSiteInstance()) |
| 1069 ->GetFileSystemContext(); | 1069 ->GetFileSystemContext(); |
| 1070 | 1070 |
| 1071 // Directory url is non empty only for syncfilesystem. | 1071 // Directory url is non empty only for syncfilesystem. |
| 1072 if (directory_url_str != "") { | 1072 if (directory_url_str != "") { |
| 1073 fileapi::FileSystemURL directory_url = | 1073 storage::FileSystemURL directory_url = |
| 1074 context_->CrackURL(GURL(directory_url_str)); | 1074 context_->CrackURL(GURL(directory_url_str)); |
| 1075 if (!directory_url.is_valid() || | 1075 if (!directory_url.is_valid() || |
| 1076 directory_url.type() != fileapi::kFileSystemTypeSyncable) { | 1076 directory_url.type() != storage::kFileSystemTypeSyncable) { |
| 1077 SetError("DirectoryEntry of unsupported filesystem."); | 1077 SetError("DirectoryEntry of unsupported filesystem."); |
| 1078 return false; | 1078 return false; |
| 1079 } | 1079 } |
| 1080 return LoadByFileSystemAPI(directory_url); | 1080 return LoadByFileSystemAPI(directory_url); |
| 1081 } else { | 1081 } else { |
| 1082 // Check if the DirecotryEntry is the instance of chrome filesystem. | 1082 // Check if the DirecotryEntry is the instance of chrome filesystem. |
| 1083 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name, | 1083 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name, |
| 1084 filesystem_path, | 1084 filesystem_path, |
| 1085 render_view_host_, | 1085 render_view_host_, |
| 1086 &project_base_path_, | 1086 &project_base_path_, |
| 1087 &error_)) { | 1087 &error_)) { |
| 1088 SetError("DirectoryEntry of unsupported filesystem."); | 1088 SetError("DirectoryEntry of unsupported filesystem."); |
| 1089 return false; | 1089 return false; |
| 1090 } | 1090 } |
| 1091 | 1091 |
| 1092 // Try to load using the FileSystem API backend, in case the filesystem | 1092 // Try to load using the FileSystem API backend, in case the filesystem |
| 1093 // points to a non-native local directory. | 1093 // points to a non-native local directory. |
| 1094 std::string filesystem_id; | 1094 std::string filesystem_id; |
| 1095 bool cracked = | 1095 bool cracked = |
| 1096 fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id); | 1096 storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id); |
| 1097 CHECK(cracked); | 1097 CHECK(cracked); |
| 1098 base::FilePath virtual_path = | 1098 base::FilePath virtual_path = |
| 1099 fileapi::IsolatedContext::GetInstance() | 1099 storage::IsolatedContext::GetInstance() |
| 1100 ->CreateVirtualRootPath(filesystem_id) | 1100 ->CreateVirtualRootPath(filesystem_id) |
| 1101 .Append(base::FilePath::FromUTF8Unsafe(filesystem_path)); | 1101 .Append(base::FilePath::FromUTF8Unsafe(filesystem_path)); |
| 1102 fileapi::FileSystemURL directory_url = context_->CreateCrackedFileSystemURL( | 1102 storage::FileSystemURL directory_url = context_->CreateCrackedFileSystemURL( |
| 1103 extensions::Extension::GetBaseURLFromExtensionId(extension_id()), | 1103 extensions::Extension::GetBaseURLFromExtensionId(extension_id()), |
| 1104 fileapi::kFileSystemTypeIsolated, | 1104 storage::kFileSystemTypeIsolated, |
| 1105 virtual_path); | 1105 virtual_path); |
| 1106 | 1106 |
| 1107 if (directory_url.is_valid() && | 1107 if (directory_url.is_valid() && |
| 1108 directory_url.type() != fileapi::kFileSystemTypeNativeLocal && | 1108 directory_url.type() != storage::kFileSystemTypeNativeLocal && |
| 1109 directory_url.type() != fileapi::kFileSystemTypeRestrictedNativeLocal && | 1109 directory_url.type() != storage::kFileSystemTypeRestrictedNativeLocal && |
| 1110 directory_url.type() != fileapi::kFileSystemTypeDragged) { | 1110 directory_url.type() != storage::kFileSystemTypeDragged) { |
| 1111 return LoadByFileSystemAPI(directory_url); | 1111 return LoadByFileSystemAPI(directory_url); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 Load(); | 1114 Load(); |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 return true; | 1117 return true; |
| 1118 } | 1118 } |
| 1119 | 1119 |
| 1120 bool DeveloperPrivateLoadDirectoryFunction::LoadByFileSystemAPI( | 1120 bool DeveloperPrivateLoadDirectoryFunction::LoadByFileSystemAPI( |
| 1121 const fileapi::FileSystemURL& directory_url) { | 1121 const storage::FileSystemURL& directory_url) { |
| 1122 std::string directory_url_str = directory_url.ToGURL().spec(); | 1122 std::string directory_url_str = directory_url.ToGURL().spec(); |
| 1123 | 1123 |
| 1124 size_t pos = 0; | 1124 size_t pos = 0; |
| 1125 // Parse the project directory name from the project url. The project url is | 1125 // Parse the project directory name from the project url. The project url is |
| 1126 // expected to have project name as the suffix. | 1126 // expected to have project name as the suffix. |
| 1127 if ((pos = directory_url_str.rfind("/")) == std::string::npos) { | 1127 if ((pos = directory_url_str.rfind("/")) == std::string::npos) { |
| 1128 SetError("Invalid Directory entry."); | 1128 SetError("Invalid Directory entry."); |
| 1129 return false; | 1129 return false; |
| 1130 } | 1130 } |
| 1131 | 1131 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 1169 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| 1170 base::Bind(&DeveloperPrivateLoadDirectoryFunction:: | 1170 base::Bind(&DeveloperPrivateLoadDirectoryFunction:: |
| 1171 ReadDirectoryByFileSystemAPI, | 1171 ReadDirectoryByFileSystemAPI, |
| 1172 this, project_path, project_path.BaseName())); | 1172 this, project_path, project_path.BaseName())); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 void DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPI( | 1175 void DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPI( |
| 1176 const base::FilePath& project_path, | 1176 const base::FilePath& project_path, |
| 1177 const base::FilePath& destination_path) { | 1177 const base::FilePath& destination_path) { |
| 1178 GURL project_url = GURL(project_base_url_ + destination_path.AsUTF8Unsafe()); | 1178 GURL project_url = GURL(project_base_url_ + destination_path.AsUTF8Unsafe()); |
| 1179 fileapi::FileSystemURL url = context_->CrackURL(project_url); | 1179 storage::FileSystemURL url = context_->CrackURL(project_url); |
| 1180 | 1180 |
| 1181 context_->operation_runner()->ReadDirectory( | 1181 context_->operation_runner()->ReadDirectory( |
| 1182 url, base::Bind(&DeveloperPrivateLoadDirectoryFunction:: | 1182 url, base::Bind(&DeveloperPrivateLoadDirectoryFunction:: |
| 1183 ReadDirectoryByFileSystemAPICb, | 1183 ReadDirectoryByFileSystemAPICb, |
| 1184 this, project_path, destination_path)); | 1184 this, project_path, destination_path)); |
| 1185 } | 1185 } |
| 1186 | 1186 |
| 1187 void DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPICb( | 1187 void DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPICb( |
| 1188 const base::FilePath& project_path, | 1188 const base::FilePath& project_path, |
| 1189 const base::FilePath& destination_path, | 1189 const base::FilePath& destination_path, |
| 1190 base::File::Error status, | 1190 base::File::Error status, |
| 1191 const fileapi::FileSystemOperation::FileEntryList& file_list, | 1191 const storage::FileSystemOperation::FileEntryList& file_list, |
| 1192 bool has_more) { | 1192 bool has_more) { |
| 1193 | |
| 1194 if (status != base::File::FILE_OK) { | 1193 if (status != base::File::FILE_OK) { |
| 1195 DLOG(ERROR) << "Error in copying files from sync filesystem."; | 1194 DLOG(ERROR) << "Error in copying files from sync filesystem."; |
| 1196 return; | 1195 return; |
| 1197 } | 1196 } |
| 1198 | 1197 |
| 1199 // We add 1 to the pending copy operations for both files and directories. We | 1198 // We add 1 to the pending copy operations for both files and directories. We |
| 1200 // release the directory copy operation once all the files under the directory | 1199 // release the directory copy operation once all the files under the directory |
| 1201 // are added for copying. We do that to ensure that pendingCopyOperationsCount | 1200 // are added for copying. We do that to ensure that pendingCopyOperationsCount |
| 1202 // does not become zero before all copy operations are finished. | 1201 // does not become zero before all copy operations are finished. |
| 1203 // In case the directory happens to be executing the last copy operation it | 1202 // In case the directory happens to be executing the last copy operation it |
| 1204 // will call SendResponse to send the response to the API. The pending copy | 1203 // will call SendResponse to send the response to the API. The pending copy |
| 1205 // operations of files are released by the CopyFile function. | 1204 // operations of files are released by the CopyFile function. |
| 1206 pending_copy_operations_count_ += file_list.size(); | 1205 pending_copy_operations_count_ += file_list.size(); |
| 1207 | 1206 |
| 1208 for (size_t i = 0; i < file_list.size(); ++i) { | 1207 for (size_t i = 0; i < file_list.size(); ++i) { |
| 1209 if (file_list[i].is_directory) { | 1208 if (file_list[i].is_directory) { |
| 1210 ReadDirectoryByFileSystemAPI(project_path.Append(file_list[i].name), | 1209 ReadDirectoryByFileSystemAPI(project_path.Append(file_list[i].name), |
| 1211 destination_path.Append(file_list[i].name)); | 1210 destination_path.Append(file_list[i].name)); |
| 1212 continue; | 1211 continue; |
| 1213 } | 1212 } |
| 1214 | 1213 |
| 1215 GURL project_url = GURL(project_base_url_ + | 1214 GURL project_url = GURL(project_base_url_ + |
| 1216 destination_path.Append(file_list[i].name).AsUTF8Unsafe()); | 1215 destination_path.Append(file_list[i].name).AsUTF8Unsafe()); |
| 1217 fileapi::FileSystemURL url = context_->CrackURL(project_url); | 1216 storage::FileSystemURL url = context_->CrackURL(project_url); |
| 1218 | 1217 |
| 1219 base::FilePath target_path = project_path; | 1218 base::FilePath target_path = project_path; |
| 1220 target_path = target_path.Append(file_list[i].name); | 1219 target_path = target_path.Append(file_list[i].name); |
| 1221 | 1220 |
| 1222 context_->operation_runner()->CreateSnapshotFile( | 1221 context_->operation_runner()->CreateSnapshotFile( |
| 1223 url, | 1222 url, |
| 1224 base::Bind(&DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback, | 1223 base::Bind(&DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback, |
| 1225 this, | 1224 this, |
| 1226 target_path)); | 1225 target_path)); |
| 1227 } | 1226 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1238 success_)); | 1237 success_)); |
| 1239 } | 1238 } |
| 1240 } | 1239 } |
| 1241 } | 1240 } |
| 1242 | 1241 |
| 1243 void DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback( | 1242 void DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback( |
| 1244 const base::FilePath& target_path, | 1243 const base::FilePath& target_path, |
| 1245 base::File::Error result, | 1244 base::File::Error result, |
| 1246 const base::File::Info& file_info, | 1245 const base::File::Info& file_info, |
| 1247 const base::FilePath& src_path, | 1246 const base::FilePath& src_path, |
| 1248 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 1247 const scoped_refptr<storage::ShareableFileReference>& file_ref) { |
| 1249 if (result != base::File::FILE_OK) { | 1248 if (result != base::File::FILE_OK) { |
| 1250 SetError("Error in copying files from sync filesystem."); | 1249 SetError("Error in copying files from sync filesystem."); |
| 1251 success_ = false; | 1250 success_ = false; |
| 1252 return; | 1251 return; |
| 1253 } | 1252 } |
| 1254 | 1253 |
| 1255 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | 1254 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
| 1256 base::Bind(&DeveloperPrivateLoadDirectoryFunction::CopyFile, | 1255 base::Bind(&DeveloperPrivateLoadDirectoryFunction::CopyFile, |
| 1257 this, | 1256 this, |
| 1258 src_path, | 1257 src_path, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 } | 1396 } |
| 1398 | 1397 |
| 1399 error_ui_util::HandleOpenDevTools(dict); | 1398 error_ui_util::HandleOpenDevTools(dict); |
| 1400 | 1399 |
| 1401 return true; | 1400 return true; |
| 1402 } | 1401 } |
| 1403 | 1402 |
| 1404 } // namespace api | 1403 } // namespace api |
| 1405 | 1404 |
| 1406 } // namespace extensions | 1405 } // namespace extensions |
| OLD | NEW |