Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api.cc

Issue 132313009: New API to copy syncfs folder to localfs. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "apps/shell_window.h" 10 #include "apps/shell_window.h"
11 #include "apps/shell_window_registry.h" 11 #include "apps/shell_window_registry.h"
12 #include "base/base64.h" 12 #include "base/base64.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/files/file_enumerator.h" 15 #include "base/files/file_enumerator.h"
16 #include "base/i18n/file_util_icu.h" 16 #include "base/i18n/file_util_icu.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/devtools/devtools_window.h" 21 #include "chrome/browser/devtools/devtools_window.h"
22 #include "chrome/browser/extensions/api/developer_private/developer_private_api_ factory.h" 22 #include "chrome/browser/extensions/api/developer_private/developer_private_api_ factory.h"
23 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" 23 #include "chrome/browser/extensions/api/developer_private/entry_picker.h"
24 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 24 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
25 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
25 #include "chrome/browser/extensions/devtools_util.h" 26 #include "chrome/browser/extensions/devtools_util.h"
26 #include "chrome/browser/extensions/extension_disabled_ui.h" 27 #include "chrome/browser/extensions/extension_disabled_ui.h"
27 #include "chrome/browser/extensions/extension_error_reporter.h" 28 #include "chrome/browser/extensions/extension_error_reporter.h"
28 #include "chrome/browser/extensions/extension_service.h" 29 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/extensions/extension_system.h" 30 #include "chrome/browser/extensions/extension_system.h"
30 #include "chrome/browser/extensions/extension_util.h" 31 #include "chrome/browser/extensions/extension_util.h"
31 #include "chrome/browser/extensions/unpacked_installer.h" 32 #include "chrome/browser/extensions/unpacked_installer.h"
32 #include "chrome/browser/extensions/updater/extension_updater.h" 33 #include "chrome/browser/extensions/updater/extension_updater.h"
33 #include "chrome/browser/platform_util.h" 34 #include "chrome/browser/platform_util.h"
34 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
(...skipping 24 matching lines...) Expand all
59 #include "extensions/common/manifest_handlers/incognito_info.h" 60 #include "extensions/common/manifest_handlers/incognito_info.h"
60 #include "extensions/common/manifest_handlers/offline_enabled_info.h" 61 #include "extensions/common/manifest_handlers/offline_enabled_info.h"
61 #include "extensions/common/switches.h" 62 #include "extensions/common/switches.h"
62 #include "grit/chromium_strings.h" 63 #include "grit/chromium_strings.h"
63 #include "grit/generated_resources.h" 64 #include "grit/generated_resources.h"
64 #include "grit/theme_resources.h" 65 #include "grit/theme_resources.h"
65 #include "net/base/net_util.h" 66 #include "net/base/net_util.h"
66 #include "ui/base/l10n/l10n_util.h" 67 #include "ui/base/l10n/l10n_util.h"
67 #include "ui/base/resource/resource_bundle.h" 68 #include "ui/base/resource/resource_bundle.h"
68 #include "ui/base/webui/web_ui_util.h" 69 #include "ui/base/webui/web_ui_util.h"
70 #include "webkit/browser/fileapi/external_mount_points.h"
69 #include "webkit/browser/fileapi/file_system_context.h" 71 #include "webkit/browser/fileapi/file_system_context.h"
70 #include "webkit/browser/fileapi/file_system_operation.h" 72 #include "webkit/browser/fileapi/file_system_operation.h"
71 #include "webkit/browser/fileapi/file_system_operation_runner.h" 73 #include "webkit/browser/fileapi/file_system_operation_runner.h"
72 #include "webkit/common/blob/shareable_file_reference.h" 74 #include "webkit/common/blob/shareable_file_reference.h"
73 75
74 using apps::ShellWindow; 76 using apps::ShellWindow;
75 using apps::ShellWindowRegistry; 77 using apps::ShellWindowRegistry;
76 using content::RenderViewHost; 78 using content::RenderViewHost;
77 79
78 namespace extensions { 80 namespace extensions {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // extensions::ImageLoader. Also a resize should be performed to avoid 121 // extensions::ImageLoader. Also a resize should be performed to avoid
120 // potential huge URLs: crbug/297298. 122 // potential huge URLs: crbug/297298.
121 GURL ToDataURL(const base::FilePath& path, developer_private::ItemType type) { 123 GURL ToDataURL(const base::FilePath& path, developer_private::ItemType type) {
122 std::string contents; 124 std::string contents;
123 if (path.empty() || !base::ReadFileToString(path, &contents)) 125 if (path.empty() || !base::ReadFileToString(path, &contents))
124 return GetDefaultImageURL(type); 126 return GetDefaultImageURL(type);
125 127
126 return GetImageURLFromData(contents); 128 return GetImageURLFromData(contents);
127 } 129 }
128 130
129 bool ValidateFolderName(const base::FilePath::StringType& name) {
130 base::FilePath::StringType name_sanitized(name);
131 file_util::ReplaceIllegalCharactersInPath(&name_sanitized, '_');
132 return name == name_sanitized;
133 }
134
135 const Extension* GetExtensionByPath(const extensions::ExtensionSet* extensions,
136 const base::FilePath& path) {
137 base::FilePath extension_path = base::MakeAbsoluteFilePath(path);
138 for (extensions::ExtensionSet::const_iterator iter = extensions->begin();
139 iter != extensions->end(); ++iter) {
140 if ((*iter)->path() == extension_path)
141 return iter->get();
142 }
143 return NULL;
144 }
145
146 std::string GetExtensionID(const RenderViewHost* render_view_host) { 131 std::string GetExtensionID(const RenderViewHost* render_view_host) {
147 if (!render_view_host->GetSiteInstance()) 132 if (!render_view_host->GetSiteInstance())
148 return std::string(); 133 return std::string();
149 134
150 return render_view_host->GetSiteInstance()->GetSiteURL().host(); 135 return render_view_host->GetSiteInstance()->GetSiteURL().host();
151 } 136 }
152 137
153 } // namespace 138 } // namespace
154 139
155 namespace AllowFileAccess = api::developer_private::AllowFileAccess; 140 namespace AllowFileAccess = api::developer_private::AllowFileAccess;
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 } 939 }
955 940
956 DeveloperPrivatePackDirectoryFunction::DeveloperPrivatePackDirectoryFunction() 941 DeveloperPrivatePackDirectoryFunction::DeveloperPrivatePackDirectoryFunction()
957 {} 942 {}
958 943
959 DeveloperPrivatePackDirectoryFunction::~DeveloperPrivatePackDirectoryFunction() 944 DeveloperPrivatePackDirectoryFunction::~DeveloperPrivatePackDirectoryFunction()
960 {} 945 {}
961 946
962 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} 947 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {}
963 948
964 bool DeveloperPrivateExportSyncfsFolderToLocalfsFunction::RunImpl() { 949 bool DeveloperPrivateLoadDirectoryFunction::RunImpl() {
965 // TODO(grv) : add unittests. 950 // TODO(grv) : add unittests.
966 base::FilePath::StringType project_name; 951 std::string directory_url_str;
967 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &project_name)); 952 std::string filesystem_name;
968 if (!ValidateFolderName(project_name)) { 953 std::string filesystem_path;
969 DVLOG(0) << "Invalid project_name : [" << project_name << "]"; 954
955 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name));
956 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path));
957 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &directory_url_str));
958
959 // Directory url is non empty only for syncfilesystem.
960 if (directory_url_str != "") {
961
962 context_ = content::BrowserContext::GetStoragePartition(
963 GetProfile(), render_view_host()->GetSiteInstance())
964 ->GetFileSystemContext();
965
966 fileapi::FileSystemURL directory_url =
967 context_->CrackURL(GURL(directory_url_str));
968
969 if (!directory_url.is_valid() && directory_url.type() ==
970 fileapi::kFileSystemTypeSyncable) {
971 SetError("DirectoryEntry of unsupported filesystem.");
972 return false;
973 }
974
975 size_t pos = 0;
976 // Parse the project directory name from the project url. The project url is
977 // expected to have project name as the suffix.
978 if ((pos = directory_url_str.rfind("/")) == std::string::npos) {
979 SetError("Invalid Directory entry.");
980 return false;
981 }
982
983 std::string project_name;
984 project_name = directory_url_str.substr(pos + 1);
985 project_base_url_ = directory_url_str.substr(0, pos + 1);
986
987 base::FilePath project_path(GetProfile()->GetPath());
988 project_path = project_path.Append(kUnpackedAppsFolder);
989 project_path = project_path.Append(
990 base::FilePath::FromUTF8Unsafe(project_name));
991
992 project_base_path_ = project_path;
993
994 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
995 base::Bind(&DeveloperPrivateLoadDirectoryFunction::
996 ClearExistingDirectoryContent,
997 this,
998 project_base_path_));
999 } else {
1000
1001 // Check if the DirecotryEntry is the instace of chrome filesystem..
1002 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name,
1003 filesystem_path,
1004 render_view_host_,
1005 &project_base_path_,
1006 &error_))
970 return false; 1007 return false;
1008
1009 Load();
971 } 1010 }
972 1011
973 context_ = content::BrowserContext::GetStoragePartition(
974 GetProfile(), render_view_host()->GetSiteInstance())
975 ->GetFileSystemContext();
976
977 base::FilePath project_path(GetProfile()->GetPath());
978 project_path = project_path.Append(kUnpackedAppsFolder);
979 project_path = project_path.Append(project_name);
980
981 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
982 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
983 ClearPrexistingDirectoryContent,
984 this,
985 project_path));
986
987 return true; 1012 return true;
988 } 1013 }
989 1014
990 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 1015 void DeveloperPrivateLoadDirectoryFunction::Load() {
991 ClearPrexistingDirectoryContent(const base::FilePath& project_path) { 1016
1017 ExtensionService* service = GetProfile()->GetExtensionService();
1018 UnpackedInstaller::Create(service)->Load(project_base_path_);
1019
1020 // TODO(grv) : The unpacked installer should fire an event when complete
1021 // and return the extension_id.
1022 SetResult(new base::StringValue("-1"));
1023 SendResponse(true);
1024 }
1025
1026 void DeveloperPrivateLoadDirectoryFunction::ClearExistingDirectoryContent(
1027 const base::FilePath& project_path) {
992 1028
993 // Clear the project directory before copying new files. 1029 // Clear the project directory before copying new files.
994 base::DeleteFile(project_path, true/*recursive*/); 1030 base::DeleteFile(project_path, true/*recursive*/);
995 1031
996 pendingCopyOperationsCount_ = 1; 1032 pending_copy_operations_count_ = 1;
997 1033
998 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, 1034 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
999 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 1035 base::Bind(&DeveloperPrivateLoadDirectoryFunction::
1000 ReadSyncFileSystemDirectory, 1036 ReadSyncFileSystemDirectory,
1001 this, project_path, project_path.BaseName())); 1037 this, project_path, project_path.BaseName()));
1002 } 1038 }
1003 1039
1004 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 1040 void DeveloperPrivateLoadDirectoryFunction::ReadSyncFileSystemDirectory(
1005 ReadSyncFileSystemDirectory(const base::FilePath& project_path, 1041 const base::FilePath& project_path,
1006 const base::FilePath& destination_path) { 1042 const base::FilePath& destination_path) {
1007 std::string origin_url( 1043
1008 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); 1044 current_path_ = context_->CrackURL(GURL(project_base_url_)).path();
1009 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( 1045
1010 GURL(origin_url), 1046 GURL project_url = GURL(project_base_url_ + destination_path.MaybeAsASCII());
1011 destination_path)); 1047
1048 fileapi::FileSystemURL url = context_->CrackURL(project_url);
1012 1049
1013 context_->operation_runner()->ReadDirectory( 1050 context_->operation_runner()->ReadDirectory(
1014 url, base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 1051 url, base::Bind(&DeveloperPrivateLoadDirectoryFunction::
1015 ReadSyncFileSystemDirectoryCb, 1052 ReadSyncFileSystemDirectoryCb,
1016 this, project_path, destination_path)); 1053 this, project_path, destination_path));
1017 } 1054 }
1018 1055
1019 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 1056 void DeveloperPrivateLoadDirectoryFunction::ReadSyncFileSystemDirectoryCb(
1020 ReadSyncFileSystemDirectoryCb(
1021 const base::FilePath& project_path, 1057 const base::FilePath& project_path,
1022 const base::FilePath& destination_path, 1058 const base::FilePath& destination_path,
1023 base::PlatformFileError status, 1059 base::PlatformFileError status,
1024 const fileapi::FileSystemOperation::FileEntryList& file_list, 1060 const fileapi::FileSystemOperation::FileEntryList& file_list,
1025 bool has_more) { 1061 bool has_more) {
1026 1062
1027 if (status != base::PLATFORM_FILE_OK) { 1063 if (status != base::PLATFORM_FILE_OK) {
1028 DLOG(ERROR) << "Error in copying files from sync filesystem."; 1064 DLOG(ERROR) << "Error in copying files from sync filesystem.";
1029 return; 1065 return;
1030 } 1066 }
1031 1067
1032 // We add 1 to the pending copy operations for both files and directories. We 1068 // We add 1 to the pending copy operations for both files and directories. We
1033 // release the directory copy operation once all the files under the directory 1069 // release the directory copy operation once all the files under the directory
1034 // are added for copying. We do that to ensure that pendingCopyOperationsCount 1070 // are added for copying. We do that to ensure that pendingCopyOperationsCount
1035 // does not become zero before all copy operations are finished. 1071 // does not become zero before all copy operations are finished.
1036 // In case the directory happens to be executing the last copy operation it 1072 // In case the directory happens to be executing the last copy operation it
1037 // will call SendResponse to send the response to the API. The pending copy 1073 // will call SendResponse to send the response to the API. The pending copy
1038 // operations of files are released by the CopyFile function. 1074 // operations of files are released by the CopyFile function.
1039 pendingCopyOperationsCount_ += file_list.size(); 1075 pending_copy_operations_count_ += file_list.size();
1040 1076
1041 for (size_t i = 0; i < file_list.size(); ++i) { 1077 for (size_t i = 0; i < file_list.size(); ++i) {
1042 if (file_list[i].is_directory) { 1078 if (file_list[i].is_directory) {
1043 ReadSyncFileSystemDirectory(project_path.Append(file_list[i].name), 1079 ReadSyncFileSystemDirectory(project_path.Append(file_list[i].name),
1044 destination_path.Append(file_list[i].name)); 1080 destination_path.Append(file_list[i].name));
1045 continue; 1081 continue;
1046 } 1082 }
1047 1083
1048 std::string origin_url( 1084 std::string origin_url(
1049 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); 1085 Extension::GetBaseURLFromExtensionId(extension_id()).spec());
1050 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( 1086 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL(
1051 GURL(origin_url), 1087 GURL(origin_url),
1052 destination_path.Append(file_list[i].name))); 1088 current_path_.Append(destination_path.Append(file_list[i].name))));
1053 base::FilePath target_path = project_path; 1089 base::FilePath target_path = project_path;
1054 target_path = target_path.Append(file_list[i].name); 1090 target_path = target_path.Append(file_list[i].name);
1055 1091
1056 context_->operation_runner()->CreateSnapshotFile( 1092 context_->operation_runner()->CreateSnapshotFile(
1057 url, 1093 url,
1058 base::Bind( 1094 base::Bind(&DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback,
1059 &DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
1060 SnapshotFileCallback,
1061 this, 1095 this,
1062 target_path)); 1096 target_path));
1063 1097
1064 } 1098 }
1065 1099
1066 // Directory copy operation released here. 1100 // Directory copy operation released here.
1067 pendingCopyOperationsCount_--; 1101 pending_copy_operations_count_--;
1068 1102
1069 if (!pendingCopyOperationsCount_) { 1103 if (!pending_copy_operations_count_) {
1070 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 1104 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
1071 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 1105 base::Bind(&DeveloperPrivateLoadDirectoryFunction::SendResponse,
1072 SendResponse,
1073 this, 1106 this,
1074 success_)); 1107 success_));
1075 } 1108 }
1076 } 1109 }
1077 1110
1078 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::SnapshotFileCallback( 1111 void DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback(
1079 const base::FilePath& target_path, 1112 const base::FilePath& target_path,
1080 base::PlatformFileError result, 1113 base::PlatformFileError result,
1081 const base::PlatformFileInfo& file_info, 1114 const base::PlatformFileInfo& file_info,
1082 const base::FilePath& src_path, 1115 const base::FilePath& src_path,
1083 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { 1116 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
1084 if (result != base::PLATFORM_FILE_OK) { 1117 if (result != base::PLATFORM_FILE_OK) {
1085 SetError("Error in copying files from sync filesystem."); 1118 SetError("Error in copying files from sync filesystem.");
1086 success_ = false; 1119 success_ = false;
1087 return; 1120 return;
1088 } 1121 }
1089 1122
1090 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, 1123 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
1091 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction::CopyFile, 1124 base::Bind(&DeveloperPrivateLoadDirectoryFunction::CopyFile,
1092 this, 1125 this,
1093 src_path, 1126 src_path,
1094 target_path)); 1127 target_path));
1095 } 1128 }
1096 1129
1097 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::CopyFile( 1130 void DeveloperPrivateLoadDirectoryFunction::CopyFile(
1098 const base::FilePath& src_path, 1131 const base::FilePath& src_path,
1099 const base::FilePath& target_path) { 1132 const base::FilePath& target_path) {
1100 if (!base::CreateDirectory(target_path.DirName())) { 1133 if (!base::CreateDirectory(target_path.DirName())) {
1101 SetError("Error in copying files from sync filesystem."); 1134 SetError("Error in copying files from sync filesystem.");
1102 success_ = false; 1135 success_ = false;
1103 } 1136 }
1104 1137
1105 if (success_) 1138 if (success_)
1106 base::CopyFile(src_path, target_path); 1139 base::CopyFile(src_path, target_path);
1107 1140
1108 CHECK(pendingCopyOperationsCount_ > 0); 1141 CHECK(pending_copy_operations_count_ > 0);
1109 pendingCopyOperationsCount_--; 1142 pending_copy_operations_count_--;
1110 1143
1111 if (!pendingCopyOperationsCount_) { 1144 if (!pending_copy_operations_count_) {
1112 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 1145 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
1113 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 1146 base::Bind(&DeveloperPrivateLoadDirectoryFunction::Load,
1114 SendResponse, 1147 this));
1115 this,
1116 success_));
1117 } 1148 }
1118 } 1149 }
1119 1150
1120 DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 1151 DeveloperPrivateLoadDirectoryFunction::DeveloperPrivateLoadDirectoryFunction()
1121 DeveloperPrivateExportSyncfsFolderToLocalfsFunction() 1152 : pending_copy_operations_count_(0), success_(true) {}
1122 : pendingCopyOperationsCount_(0), success_(true) {}
1123 1153
1124 DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 1154 DeveloperPrivateLoadDirectoryFunction::~DeveloperPrivateLoadDirectoryFunction()
1125 ~DeveloperPrivateExportSyncfsFolderToLocalfsFunction() {} 1155 {}
1126
1127 bool DeveloperPrivateLoadProjectFunction::RunImpl() {
1128 // TODO(grv) : add unit tests.
1129 base::FilePath::StringType project_name;
1130 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &project_name));
1131 if (!ValidateFolderName(project_name)) {
1132 DVLOG(0) << "Invalid project_name : [" << project_name << "]";
1133 return false;
1134 }
1135
1136 base::FilePath path(GetProfile()->GetPath());
1137 path = path.Append(kUnpackedAppsFolder);
1138 // TODO(grv) : Sanitize / check project_name.
1139 path = path.Append(project_name);
1140 ExtensionService* service = GetProfile()->GetExtensionService();
1141 UnpackedInstaller::Create(service)->Load(path);
1142
1143 const extensions::ExtensionSet* extensions = service->extensions();
1144 // Released by GetUnpackedExtension.
1145 AddRef();
1146 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
1147 base::Bind(&DeveloperPrivateLoadProjectFunction::GetUnpackedExtension,
1148 this, path, extensions));
1149 return true;
1150 }
1151
1152 void DeveloperPrivateLoadProjectFunction::GetUnpackedExtension(
1153 const base::FilePath& path,
1154 const extensions::ExtensionSet* extensions) {
1155 const Extension* extension = GetExtensionByPath(extensions, path);
1156 bool success = true;
1157 if (extension) {
1158 SetResult(new base::StringValue(extension->id()));
1159 } else {
1160 SetError("unable to load the project");
1161 success = false;
1162 }
1163 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
1164 base::Bind(&DeveloperPrivateLoadProjectFunction::SendResponse,
1165 this,
1166 success));
1167 Release();
1168 }
1169
1170 DeveloperPrivateLoadProjectFunction::DeveloperPrivateLoadProjectFunction() {}
1171
1172 DeveloperPrivateLoadProjectFunction::~DeveloperPrivateLoadProjectFunction() {}
1173 1156
1174 bool DeveloperPrivateChoosePathFunction::RunImpl() { 1157 bool DeveloperPrivateChoosePathFunction::RunImpl() {
1175 1158
1176 scoped_ptr<developer::ChoosePath::Params> params( 1159 scoped_ptr<developer::ChoosePath::Params> params(
1177 developer::ChoosePath::Params::Create(*args_)); 1160 developer::ChoosePath::Params::Create(*args_));
1178 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 1161 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
1179 1162
1180 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; 1163 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER;
1181 ui::SelectFileDialog::FileTypeInfo info; 1164 ui::SelectFileDialog::FileTypeInfo info;
1182 if (params->select_type == developer::SELECT_TYPE_FILE) { 1165 if (params->select_type == developer::SELECT_TYPE_FILE) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 return true; 1328 return true;
1346 } 1329 }
1347 1330
1348 DeveloperPrivateIsProfileManagedFunction:: 1331 DeveloperPrivateIsProfileManagedFunction::
1349 ~DeveloperPrivateIsProfileManagedFunction() { 1332 ~DeveloperPrivateIsProfileManagedFunction() {
1350 } 1333 }
1351 1334
1352 } // namespace api 1335 } // namespace api
1353 1336
1354 } // namespace extensions 1337 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698