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 "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 Loading... | |
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 | 127 |
126 return GetImageURLFromData(contents); | 128 return GetImageURLFromData(contents); |
127 } | 129 } |
128 | 130 |
129 bool ValidateFolderName(const base::FilePath::StringType& name) { | 131 bool ValidateFolderName(const base::FilePath::StringType& name) { |
130 base::FilePath::StringType name_sanitized(name); | 132 base::FilePath::StringType name_sanitized(name); |
131 file_util::ReplaceIllegalCharactersInPath(&name_sanitized, '_'); | 133 file_util::ReplaceIllegalCharactersInPath(&name_sanitized, '_'); |
132 return name == name_sanitized; | 134 return name == name_sanitized; |
133 } | 135 } |
134 | 136 |
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) { | 137 std::string GetExtensionID(const RenderViewHost* render_view_host) { |
147 if (!render_view_host->GetSiteInstance()) | 138 if (!render_view_host->GetSiteInstance()) |
148 return std::string(); | 139 return std::string(); |
149 | 140 |
150 return render_view_host->GetSiteInstance()->GetSiteURL().host(); | 141 return render_view_host->GetSiteInstance()->GetSiteURL().host(); |
151 } | 142 } |
152 | 143 |
153 } // namespace | 144 } // namespace |
154 | 145 |
155 namespace AllowFileAccess = api::developer_private::AllowFileAccess; | 146 namespace AllowFileAccess = api::developer_private::AllowFileAccess; |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 } | 945 } |
955 | 946 |
956 DeveloperPrivatePackDirectoryFunction::DeveloperPrivatePackDirectoryFunction() | 947 DeveloperPrivatePackDirectoryFunction::DeveloperPrivatePackDirectoryFunction() |
957 {} | 948 {} |
958 | 949 |
959 DeveloperPrivatePackDirectoryFunction::~DeveloperPrivatePackDirectoryFunction() | 950 DeveloperPrivatePackDirectoryFunction::~DeveloperPrivatePackDirectoryFunction() |
960 {} | 951 {} |
961 | 952 |
962 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} | 953 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} |
963 | 954 |
964 bool DeveloperPrivateExportSyncfsFolderToLocalfsFunction::RunImpl() { | 955 bool DeveloperPrivateLoadDirectoryFunction::RunImpl() { |
965 // TODO(grv) : add unittests. | 956 // TODO(grv) : add unittests. |
966 base::FilePath::StringType project_name; | 957 std::string directory_url_str; |
967 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &project_name)); | 958 std::string filesystem_name; |
968 if (!ValidateFolderName(project_name)) { | 959 std::string filesystem_path; |
969 DVLOG(0) << "Invalid project_name : [" << project_name << "]"; | 960 |
961 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); | |
962 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); | |
963 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &directory_url_str)); | |
964 size_t pos = 0; | |
asargent_no_longer_on_chrome
2014/01/16 22:57:33
nit: it might be good to move this down to line 98
Gaurav
2014/01/17 00:21:27
Done.
| |
965 | |
966 // Directory url is non empty only for syncfilesystem. | |
967 if (directory_url_str != "") { | |
968 | |
969 context_ = content::BrowserContext::GetStoragePartition( | |
970 GetProfile(), render_view_host()->GetSiteInstance()) | |
971 ->GetFileSystemContext(); | |
972 | |
973 fileapi::FileSystemURL directory_url = | |
974 context_->CrackURL(GURL(directory_url_str)); | |
975 | |
976 if (!directory_url.is_valid() && directory_url.type() == | |
977 fileapi::kFileSystemTypeSyncable) { | |
978 SetError("DirectoryEntry of unsupported filesystem."); | |
979 return false; | |
980 } | |
981 | |
982 base::FilePath::StringType project_name; | |
983 // Parse the project directory name from the project url. The project url is | |
984 // expected to have project name as the suffix. | |
985 if ((pos = directory_url_str.rfind("/")) == std::string::npos) { | |
986 SetError("Invalid Directory entry."); | |
987 return false; | |
988 } | |
989 | |
990 project_name = directory_url_str.substr(pos + 1); | |
991 project_base_url_ = directory_url_str.substr(0, pos + 1); | |
992 | |
993 if (!ValidateFolderName(project_name)) { | |
994 DVLOG(0) << "Invalid project_name : [" << project_name << "]"; | |
995 return false; | |
996 } | |
997 | |
998 base::FilePath project_path(GetProfile()->GetPath()); | |
999 project_path = project_path.Append(kUnpackedAppsFolder); | |
1000 project_path = project_path.Append(project_name); | |
1001 | |
1002 path_ = project_path; | |
1003 | |
1004 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | |
1005 base::Bind(&DeveloperPrivateLoadDirectoryFunction:: | |
1006 ClearExistingDirectoryContent, | |
1007 this, | |
1008 path_)); | |
1009 } else { | |
1010 | |
1011 // Check if the DirecotryEntry is the instace of chrome filesystem.. | |
1012 if (!app_file_handler_util::ValidateFileEntryAndGetPath(filesystem_name, | |
1013 filesystem_path, | |
1014 render_view_host_, | |
1015 &path_, | |
1016 &error_)) | |
970 return false; | 1017 return false; |
1018 | |
1019 Load(); | |
971 } | 1020 } |
972 | 1021 |
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; | 1022 return true; |
988 } | 1023 } |
989 | 1024 |
990 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 1025 void DeveloperPrivateLoadDirectoryFunction::Load() { |
991 ClearPrexistingDirectoryContent(const base::FilePath& project_path) { | 1026 |
1027 ExtensionService* service = GetProfile()->GetExtensionService(); | |
1028 UnpackedInstaller::Create(service)->Load(path_); | |
1029 | |
1030 // TODO(grv) : The unpacked installer should fire an event when complete | |
1031 // and return the extension_id. | |
1032 SetResult(new base::StringValue("-1")); | |
asargent_no_longer_on_chrome
2014/01/16 22:57:33
nit: instead of passing a meaningless piece of dat
Gaurav
2014/01/17 00:21:27
This API should actually return the extension_id o
| |
1033 SendResponse(true); | |
asargent_no_longer_on_chrome
2014/01/16 22:57:33
nit: indentation looks wrong here
Gaurav
2014/01/17 00:21:27
Done.
| |
1034 } | |
1035 | |
1036 void DeveloperPrivateLoadDirectoryFunction::ClearExistingDirectoryContent( | |
1037 const base::FilePath& project_path) { | |
992 | 1038 |
993 // Clear the project directory before copying new files. | 1039 // Clear the project directory before copying new files. |
994 base::DeleteFile(project_path, true/*recursive*/); | 1040 base::DeleteFile(project_path, true/*recursive*/); |
995 | 1041 |
996 pendingCopyOperationsCount_ = 1; | 1042 pending_copy_operations_count_ = 1; |
997 | 1043 |
998 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 1044 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
999 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 1045 base::Bind(&DeveloperPrivateLoadDirectoryFunction:: |
1000 ReadSyncFileSystemDirectory, | 1046 ReadSyncFileSystemDirectory, |
1001 this, project_path, project_path.BaseName())); | 1047 this, project_path, project_path.BaseName())); |
1002 } | 1048 } |
1003 | 1049 |
1004 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 1050 void DeveloperPrivateLoadDirectoryFunction::ReadSyncFileSystemDirectory( |
1005 ReadSyncFileSystemDirectory(const base::FilePath& project_path, | 1051 const base::FilePath& project_path, |
1006 const base::FilePath& destination_path) { | 1052 const base::FilePath& destination_path) { |
1007 std::string origin_url( | 1053 |
1008 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); | 1054 project_path_ = context_->CrackURL(GURL(project_base_url_)).path(); |
1009 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( | 1055 |
1010 GURL(origin_url), | 1056 GURL project_url = GURL(project_base_url_ + destination_path.MaybeAsASCII()); |
1011 destination_path)); | 1057 |
1058 fileapi::FileSystemURL url = context_->CrackURL(project_url); | |
1012 | 1059 |
1013 context_->operation_runner()->ReadDirectory( | 1060 context_->operation_runner()->ReadDirectory( |
1014 url, base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 1061 url, base::Bind(&DeveloperPrivateLoadDirectoryFunction:: |
1015 ReadSyncFileSystemDirectoryCb, | 1062 ReadSyncFileSystemDirectoryCb, |
1016 this, project_path, destination_path)); | 1063 this, project_path, destination_path)); |
1017 } | 1064 } |
1018 | 1065 |
1019 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 1066 void DeveloperPrivateLoadDirectoryFunction::ReadSyncFileSystemDirectoryCb( |
1020 ReadSyncFileSystemDirectoryCb( | |
1021 const base::FilePath& project_path, | 1067 const base::FilePath& project_path, |
1022 const base::FilePath& destination_path, | 1068 const base::FilePath& destination_path, |
1023 base::PlatformFileError status, | 1069 base::PlatformFileError status, |
1024 const fileapi::FileSystemOperation::FileEntryList& file_list, | 1070 const fileapi::FileSystemOperation::FileEntryList& file_list, |
1025 bool has_more) { | 1071 bool has_more) { |
1026 | 1072 |
1027 if (status != base::PLATFORM_FILE_OK) { | 1073 if (status != base::PLATFORM_FILE_OK) { |
1028 DLOG(ERROR) << "Error in copying files from sync filesystem."; | 1074 DLOG(ERROR) << "Error in copying files from sync filesystem."; |
1029 return; | 1075 return; |
1030 } | 1076 } |
1031 | 1077 |
1032 // We add 1 to the pending copy operations for both files and directories. We | 1078 // 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 | 1079 // release the directory copy operation once all the files under the directory |
1034 // are added for copying. We do that to ensure that pendingCopyOperationsCount | 1080 // are added for copying. We do that to ensure that pendingCopyOperationsCount |
1035 // does not become zero before all copy operations are finished. | 1081 // does not become zero before all copy operations are finished. |
1036 // In case the directory happens to be executing the last copy operation it | 1082 // 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 | 1083 // will call SendResponse to send the response to the API. The pending copy |
1038 // operations of files are released by the CopyFile function. | 1084 // operations of files are released by the CopyFile function. |
1039 pendingCopyOperationsCount_ += file_list.size(); | 1085 pending_copy_operations_count_ += file_list.size(); |
1040 | 1086 |
1041 for (size_t i = 0; i < file_list.size(); ++i) { | 1087 for (size_t i = 0; i < file_list.size(); ++i) { |
1042 if (file_list[i].is_directory) { | 1088 if (file_list[i].is_directory) { |
1043 ReadSyncFileSystemDirectory(project_path.Append(file_list[i].name), | 1089 ReadSyncFileSystemDirectory(project_path.Append(file_list[i].name), |
1044 destination_path.Append(file_list[i].name)); | 1090 destination_path.Append(file_list[i].name)); |
1045 continue; | 1091 continue; |
1046 } | 1092 } |
1047 | 1093 |
1048 std::string origin_url( | 1094 std::string origin_url( |
1049 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); | 1095 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); |
1050 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( | 1096 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( |
1051 GURL(origin_url), | 1097 GURL(origin_url), |
1052 destination_path.Append(file_list[i].name))); | 1098 project_path_.Append(destination_path.Append(file_list[i].name)))); |
1053 base::FilePath target_path = project_path; | 1099 base::FilePath target_path = project_path; |
1054 target_path = target_path.Append(file_list[i].name); | 1100 target_path = target_path.Append(file_list[i].name); |
1055 | 1101 |
1056 context_->operation_runner()->CreateSnapshotFile( | 1102 context_->operation_runner()->CreateSnapshotFile( |
1057 url, | 1103 url, |
1058 base::Bind( | 1104 base::Bind(&DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback, |
1059 &DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | |
1060 SnapshotFileCallback, | |
1061 this, | 1105 this, |
1062 target_path)); | 1106 target_path)); |
1063 | 1107 |
1064 } | 1108 } |
1065 | 1109 |
1066 // Directory copy operation released here. | 1110 // Directory copy operation released here. |
1067 pendingCopyOperationsCount_--; | 1111 pending_copy_operations_count_--; |
1068 | 1112 |
1069 if (!pendingCopyOperationsCount_) { | 1113 if (!pending_copy_operations_count_) { |
1070 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 1114 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
1071 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 1115 base::Bind(&DeveloperPrivateLoadDirectoryFunction::SendResponse, |
1072 SendResponse, | |
1073 this, | 1116 this, |
1074 success_)); | 1117 success_)); |
1075 } | 1118 } |
1076 } | 1119 } |
1077 | 1120 |
1078 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::SnapshotFileCallback( | 1121 void DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback( |
1079 const base::FilePath& target_path, | 1122 const base::FilePath& target_path, |
1080 base::PlatformFileError result, | 1123 base::PlatformFileError result, |
1081 const base::PlatformFileInfo& file_info, | 1124 const base::PlatformFileInfo& file_info, |
1082 const base::FilePath& src_path, | 1125 const base::FilePath& src_path, |
1083 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 1126 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
1084 if (result != base::PLATFORM_FILE_OK) { | 1127 if (result != base::PLATFORM_FILE_OK) { |
1085 SetError("Error in copying files from sync filesystem."); | 1128 SetError("Error in copying files from sync filesystem."); |
1086 success_ = false; | 1129 success_ = false; |
1087 return; | 1130 return; |
1088 } | 1131 } |
1089 | 1132 |
1090 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | 1133 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
1091 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction::CopyFile, | 1134 base::Bind(&DeveloperPrivateLoadDirectoryFunction::CopyFile, |
1092 this, | 1135 this, |
1093 src_path, | 1136 src_path, |
1094 target_path)); | 1137 target_path)); |
1095 } | 1138 } |
1096 | 1139 |
1097 void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::CopyFile( | 1140 void DeveloperPrivateLoadDirectoryFunction::CopyFile( |
1098 const base::FilePath& src_path, | 1141 const base::FilePath& src_path, |
1099 const base::FilePath& target_path) { | 1142 const base::FilePath& target_path) { |
1100 if (!base::CreateDirectory(target_path.DirName())) { | 1143 if (!base::CreateDirectory(target_path.DirName())) { |
1101 SetError("Error in copying files from sync filesystem."); | 1144 SetError("Error in copying files from sync filesystem."); |
1102 success_ = false; | 1145 success_ = false; |
1103 } | 1146 } |
1104 | 1147 |
1105 if (success_) | 1148 if (success_) |
1106 base::CopyFile(src_path, target_path); | 1149 base::CopyFile(src_path, target_path); |
1107 | 1150 |
1108 CHECK(pendingCopyOperationsCount_ > 0); | 1151 CHECK(pending_copy_operations_count_ > 0); |
1109 pendingCopyOperationsCount_--; | 1152 pending_copy_operations_count_--; |
1110 | 1153 |
1111 if (!pendingCopyOperationsCount_) { | 1154 if (!pending_copy_operations_count_) { |
1112 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 1155 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
1113 base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 1156 base::Bind(&DeveloperPrivateLoadDirectoryFunction::Load, |
1114 SendResponse, | 1157 this)); |
1115 this, | |
1116 success_)); | |
1117 } | 1158 } |
1118 } | 1159 } |
1119 | 1160 |
1120 DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 1161 DeveloperPrivateLoadDirectoryFunction::DeveloperPrivateLoadDirectoryFunction() |
1121 DeveloperPrivateExportSyncfsFolderToLocalfsFunction() | 1162 : pending_copy_operations_count_(0), success_(true) {} |
1122 : pendingCopyOperationsCount_(0), success_(true) {} | |
1123 | 1163 |
1124 DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: | 1164 DeveloperPrivateLoadDirectoryFunction::~DeveloperPrivateLoadDirectoryFunction() |
1125 ~DeveloperPrivateExportSyncfsFolderToLocalfsFunction() {} | 1165 {} |
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 | 1166 |
1174 bool DeveloperPrivateChoosePathFunction::RunImpl() { | 1167 bool DeveloperPrivateChoosePathFunction::RunImpl() { |
1175 | 1168 |
1176 scoped_ptr<developer::ChoosePath::Params> params( | 1169 scoped_ptr<developer::ChoosePath::Params> params( |
1177 developer::ChoosePath::Params::Create(*args_)); | 1170 developer::ChoosePath::Params::Create(*args_)); |
1178 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 1171 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
1179 | 1172 |
1180 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; | 1173 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; |
1181 ui::SelectFileDialog::FileTypeInfo info; | 1174 ui::SelectFileDialog::FileTypeInfo info; |
1182 if (params->select_type == developer::SELECT_TYPE_FILE) { | 1175 if (params->select_type == developer::SELECT_TYPE_FILE) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1345 return true; | 1338 return true; |
1346 } | 1339 } |
1347 | 1340 |
1348 DeveloperPrivateIsProfileManagedFunction:: | 1341 DeveloperPrivateIsProfileManagedFunction:: |
1349 ~DeveloperPrivateIsProfileManagedFunction() { | 1342 ~DeveloperPrivateIsProfileManagedFunction() { |
1350 } | 1343 } |
1351 | 1344 |
1352 } // namespace api | 1345 } // namespace api |
1353 | 1346 |
1354 } // namespace extensions | 1347 } // namespace extensions |
OLD | NEW |