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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 project_name = directory_url_str.substr(pos + 1); | 1065 project_name = directory_url_str.substr(pos + 1); |
1066 project_base_url_ = directory_url_str.substr(0, pos + 1); | 1066 project_base_url_ = directory_url_str.substr(0, pos + 1); |
1067 | 1067 |
1068 base::FilePath project_path(GetProfile()->GetPath()); | 1068 base::FilePath project_path(GetProfile()->GetPath()); |
1069 project_path = project_path.AppendASCII(kUnpackedAppsFolder); | 1069 project_path = project_path.AppendASCII(kUnpackedAppsFolder); |
1070 project_path = project_path.Append( | 1070 project_path = project_path.Append( |
1071 base::FilePath::FromUTF8Unsafe(project_name)); | 1071 base::FilePath::FromUTF8Unsafe(project_name)); |
1072 | 1072 |
1073 project_base_path_ = project_path; | 1073 project_base_path_ = project_path; |
1074 | 1074 |
1075 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | 1075 content::BrowserThread::PostTask( |
1076 base::Bind(&DeveloperPrivateLoadDirectoryFunction:: | 1076 content::BrowserThread::FILE, FROM_HERE, |
1077 ClearExistingDirectoryContent, | 1077 base::BindOnce( |
1078 this, | 1078 &DeveloperPrivateLoadDirectoryFunction::ClearExistingDirectoryContent, |
1079 project_base_path_)); | 1079 this, project_base_path_)); |
1080 return true; | 1080 return true; |
1081 } | 1081 } |
1082 | 1082 |
1083 void DeveloperPrivateLoadDirectoryFunction::Load() { | 1083 void DeveloperPrivateLoadDirectoryFunction::Load() { |
1084 ExtensionService* service = GetExtensionService(GetProfile()); | 1084 ExtensionService* service = GetExtensionService(GetProfile()); |
1085 UnpackedInstaller::Create(service)->Load(project_base_path_); | 1085 UnpackedInstaller::Create(service)->Load(project_base_path_); |
1086 | 1086 |
1087 // TODO(grv) : The unpacked installer should fire an event when complete | 1087 // TODO(grv) : The unpacked installer should fire an event when complete |
1088 // and return the extension_id. | 1088 // and return the extension_id. |
1089 SetResult(base::MakeUnique<base::Value>("-1")); | 1089 SetResult(base::MakeUnique<base::Value>("-1")); |
1090 SendResponse(true); | 1090 SendResponse(true); |
1091 } | 1091 } |
1092 | 1092 |
1093 void DeveloperPrivateLoadDirectoryFunction::ClearExistingDirectoryContent( | 1093 void DeveloperPrivateLoadDirectoryFunction::ClearExistingDirectoryContent( |
1094 const base::FilePath& project_path) { | 1094 const base::FilePath& project_path) { |
1095 | 1095 |
1096 // Clear the project directory before copying new files. | 1096 // Clear the project directory before copying new files. |
1097 base::DeleteFile(project_path, true /*recursive*/); | 1097 base::DeleteFile(project_path, true /*recursive*/); |
1098 | 1098 |
1099 pending_copy_operations_count_ = 1; | 1099 pending_copy_operations_count_ = 1; |
1100 | 1100 |
1101 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 1101 content::BrowserThread::PostTask( |
1102 base::Bind(&DeveloperPrivateLoadDirectoryFunction:: | 1102 content::BrowserThread::IO, FROM_HERE, |
1103 ReadDirectoryByFileSystemAPI, | 1103 base::BindOnce( |
1104 this, project_path, project_path.BaseName())); | 1104 &DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPI, |
| 1105 this, project_path, project_path.BaseName())); |
1105 } | 1106 } |
1106 | 1107 |
1107 void DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPI( | 1108 void DeveloperPrivateLoadDirectoryFunction::ReadDirectoryByFileSystemAPI( |
1108 const base::FilePath& project_path, | 1109 const base::FilePath& project_path, |
1109 const base::FilePath& destination_path) { | 1110 const base::FilePath& destination_path) { |
1110 GURL project_url = GURL(project_base_url_ + destination_path.AsUTF8Unsafe()); | 1111 GURL project_url = GURL(project_base_url_ + destination_path.AsUTF8Unsafe()); |
1111 storage::FileSystemURL url = context_->CrackURL(project_url); | 1112 storage::FileSystemURL url = context_->CrackURL(project_url); |
1112 | 1113 |
1113 context_->operation_runner()->ReadDirectory( | 1114 context_->operation_runner()->ReadDirectory( |
1114 url, base::Bind(&DeveloperPrivateLoadDirectoryFunction:: | 1115 url, base::Bind(&DeveloperPrivateLoadDirectoryFunction:: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 target_path)); | 1158 target_path)); |
1158 } | 1159 } |
1159 | 1160 |
1160 if (!has_more) { | 1161 if (!has_more) { |
1161 // Directory copy operation released here. | 1162 // Directory copy operation released here. |
1162 pending_copy_operations_count_--; | 1163 pending_copy_operations_count_--; |
1163 | 1164 |
1164 if (!pending_copy_operations_count_) { | 1165 if (!pending_copy_operations_count_) { |
1165 content::BrowserThread::PostTask( | 1166 content::BrowserThread::PostTask( |
1166 content::BrowserThread::UI, FROM_HERE, | 1167 content::BrowserThread::UI, FROM_HERE, |
1167 base::Bind(&DeveloperPrivateLoadDirectoryFunction::SendResponse, | 1168 base::BindOnce(&DeveloperPrivateLoadDirectoryFunction::SendResponse, |
1168 this, | 1169 this, success_)); |
1169 success_)); | |
1170 } | 1170 } |
1171 } | 1171 } |
1172 } | 1172 } |
1173 | 1173 |
1174 void DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback( | 1174 void DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback( |
1175 const base::FilePath& target_path, | 1175 const base::FilePath& target_path, |
1176 base::File::Error result, | 1176 base::File::Error result, |
1177 const base::File::Info& file_info, | 1177 const base::File::Info& file_info, |
1178 const base::FilePath& src_path, | 1178 const base::FilePath& src_path, |
1179 const scoped_refptr<storage::ShareableFileReference>& file_ref) { | 1179 const scoped_refptr<storage::ShareableFileReference>& file_ref) { |
1180 if (result != base::File::FILE_OK) { | 1180 if (result != base::File::FILE_OK) { |
1181 SetError("Error in copying files from sync filesystem."); | 1181 SetError("Error in copying files from sync filesystem."); |
1182 success_ = false; | 1182 success_ = false; |
1183 return; | 1183 return; |
1184 } | 1184 } |
1185 | 1185 |
1186 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | 1186 content::BrowserThread::PostTask( |
1187 base::Bind(&DeveloperPrivateLoadDirectoryFunction::CopyFile, | 1187 content::BrowserThread::FILE, FROM_HERE, |
1188 this, | 1188 base::BindOnce(&DeveloperPrivateLoadDirectoryFunction::CopyFile, this, |
1189 src_path, | 1189 src_path, target_path)); |
1190 target_path)); | |
1191 } | 1190 } |
1192 | 1191 |
1193 void DeveloperPrivateLoadDirectoryFunction::CopyFile( | 1192 void DeveloperPrivateLoadDirectoryFunction::CopyFile( |
1194 const base::FilePath& src_path, | 1193 const base::FilePath& src_path, |
1195 const base::FilePath& target_path) { | 1194 const base::FilePath& target_path) { |
1196 if (!base::CreateDirectory(target_path.DirName())) { | 1195 if (!base::CreateDirectory(target_path.DirName())) { |
1197 SetError("Error in copying files from sync filesystem."); | 1196 SetError("Error in copying files from sync filesystem."); |
1198 success_ = false; | 1197 success_ = false; |
1199 } | 1198 } |
1200 | 1199 |
1201 if (success_) | 1200 if (success_) |
1202 base::CopyFile(src_path, target_path); | 1201 base::CopyFile(src_path, target_path); |
1203 | 1202 |
1204 CHECK(pending_copy_operations_count_ > 0); | 1203 CHECK(pending_copy_operations_count_ > 0); |
1205 pending_copy_operations_count_--; | 1204 pending_copy_operations_count_--; |
1206 | 1205 |
1207 if (!pending_copy_operations_count_) { | 1206 if (!pending_copy_operations_count_) { |
1208 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 1207 content::BrowserThread::PostTask( |
1209 base::Bind(&DeveloperPrivateLoadDirectoryFunction::Load, | 1208 content::BrowserThread::UI, FROM_HERE, |
1210 this)); | 1209 base::BindOnce(&DeveloperPrivateLoadDirectoryFunction::Load, this)); |
1211 } | 1210 } |
1212 } | 1211 } |
1213 | 1212 |
1214 DeveloperPrivateLoadDirectoryFunction::DeveloperPrivateLoadDirectoryFunction() | 1213 DeveloperPrivateLoadDirectoryFunction::DeveloperPrivateLoadDirectoryFunction() |
1215 : pending_copy_operations_count_(0), success_(true) {} | 1214 : pending_copy_operations_count_(0), success_(true) {} |
1216 | 1215 |
1217 DeveloperPrivateLoadDirectoryFunction::~DeveloperPrivateLoadDirectoryFunction() | 1216 DeveloperPrivateLoadDirectoryFunction::~DeveloperPrivateLoadDirectoryFunction() |
1218 {} | 1217 {} |
1219 | 1218 |
1220 ExtensionFunction::ResponseAction DeveloperPrivateChoosePathFunction::Run() { | 1219 ExtensionFunction::ResponseAction DeveloperPrivateChoosePathFunction::Run() { |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1578 update.extension_id, update.command_name, *update.keybinding); | 1577 update.extension_id, update.command_name, *update.keybinding); |
1579 } | 1578 } |
1580 | 1579 |
1581 return RespondNow(NoArguments()); | 1580 return RespondNow(NoArguments()); |
1582 } | 1581 } |
1583 | 1582 |
1584 | 1583 |
1585 } // namespace api | 1584 } // namespace api |
1586 | 1585 |
1587 } // namespace extensions | 1586 } // namespace extensions |
OLD | NEW |