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

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

Issue 13885007: Add API to load a unpacked project to developerPrivate. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 7 years, 8 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 "base/base64.h" 7 #include "base/base64.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "webkit/fileapi/file_system_context.h" 49 #include "webkit/fileapi/file_system_context.h"
50 #include "webkit/fileapi/file_system_operation.h" 50 #include "webkit/fileapi/file_system_operation.h"
51 #include "webkit/fileapi/syncable/syncable_file_system_util.h" 51 #include "webkit/fileapi/syncable/syncable_file_system_util.h"
52 52
53 using content::RenderViewHost; 53 using content::RenderViewHost;
54 54
55 namespace extensions { 55 namespace extensions {
56 56
57 namespace { 57 namespace {
58 58
59 const base::FilePath::CharType kUnpackedAppsFolder[]
60 = FILE_PATH_LITERAL("apps_target");
61
59 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { 62 ExtensionUpdater* GetExtensionUpdater(Profile* profile) {
60 return profile->GetExtensionService()->updater(); 63 return profile->GetExtensionService()->updater();
61 } 64 }
62 65
63 GURL ToDataURL(const base::FilePath& path) { 66 GURL ToDataURL(const base::FilePath& path) {
64 std::string contents; 67 std::string contents;
65 if (!file_util::ReadFileToString(path, &contents)) 68 if (!file_util::ReadFileToString(path, &contents))
66 return GURL(); 69 return GURL();
67 70
68 std::string contents_base64; 71 std::string contents_base64;
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 812
810 for (size_t i = 0; i < file_list.size(); ++i) { 813 for (size_t i = 0; i < file_list.size(); ++i) {
811 std::string origin_url( 814 std::string origin_url(
812 Extension::GetBaseURLFromExtensionId(extension_id()).spec()); 815 Extension::GetBaseURLFromExtensionId(extension_id()).spec());
813 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( 816 fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL(
814 GURL(origin_url), 817 GURL(origin_url),
815 sync_file_system::DriveFileSyncService::kServiceName, 818 sync_file_system::DriveFileSyncService::kServiceName,
816 base::FilePath(file_list[i].name))); 819 base::FilePath(file_list[i].name)));
817 base::FilePath target_path(profile()->GetPath()); 820 base::FilePath target_path(profile()->GetPath());
818 target_path = 821 target_path =
819 target_path.Append(FILE_PATH_LITERAL("apps_target")); 822 target_path.Append(kUnpackedAppsFolder);
820 target_path = target_path.Append(project_name); 823 target_path = target_path.Append(project_name);
821 target_path = target_path.Append(file_list[i].name); 824 target_path = target_path.Append(file_list[i].name);
822 825
823 base::PlatformFileError error_code; 826 base::PlatformFileError error_code;
824 fileapi::FileSystemOperation* op = 827 fileapi::FileSystemOperation* op =
825 context_->CreateFileSystemOperation(url, &error_code); 828 context_->CreateFileSystemOperation(url, &error_code);
826 DCHECK(op); 829 DCHECK(op);
827 830
828 if (error_code != base::PLATFORM_FILE_OK) { 831 if (error_code != base::PLATFORM_FILE_OK) {
829 DLOG(ERROR) << "Error in copying files from sync filesystem."; 832 DLOG(ERROR) << "Error in copying files from sync filesystem.";
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 file_util::CopyFile(src_path, target_path); 873 file_util::CopyFile(src_path, target_path);
871 } 874 }
872 875
873 DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 876 DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
874 DeveloperPrivateExportSyncfsFolderToLocalfsFunction() 877 DeveloperPrivateExportSyncfsFolderToLocalfsFunction()
875 {} 878 {}
876 879
877 DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: 880 DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
878 ~DeveloperPrivateExportSyncfsFolderToLocalfsFunction() {} 881 ~DeveloperPrivateExportSyncfsFolderToLocalfsFunction() {}
879 882
883 bool DeveloperPrivateLoadProjectToSyncfsFunction::RunImpl() {
884 // TODO(grv) : implement
885 return true;
886 }
887
888 DeveloperPrivateLoadProjectToSyncfsFunction::
889 DeveloperPrivateLoadProjectToSyncfsFunction() {}
890
891 DeveloperPrivateLoadProjectToSyncfsFunction::
892 ~DeveloperPrivateLoadProjectToSyncfsFunction() {}
893
894 bool DeveloperPrivateGetProjectsInfoFunction::RunImpl() {
895 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
896 base::Bind(&DeveloperPrivateGetProjectsInfoFunction::ReadFolder,
897 this));
898
899 // Released by ReadFolder
900 AddRef();
901 return true;
902 }
903
904 void DeveloperPrivateGetProjectsInfoFunction::ReadFolder() {
905 base::FilePath path(profile()->GetPath());
906 path = path.Append(kUnpackedAppsFolder);
907
908 file_util::FileEnumerator files(
909 path, false, file_util::FileEnumerator::DIRECTORIES);
910 ProjectInfoList info_list;
911 for (base::FilePath current_path = files.Next(); !current_path.empty();
912 current_path = files.Next()) {
913 scoped_ptr<developer::ProjectInfo> info(new developer::ProjectInfo());
914 info->name = current_path.BaseName().MaybeAsASCII();
915 info_list.push_back(
916 make_linked_ptr<developer::ProjectInfo>(info.release()));
917 }
918 results_ = developer::GetProjectsInfo::Results::Create(info_list);
919 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
920 base::Bind(&DeveloperPrivateGetProjectsInfoFunction::SendResponse,
921 this,
922 true));
923 Release();
924 }
925
926 DeveloperPrivateGetProjectsInfoFunction::
927 DeveloperPrivateGetProjectsInfoFunction() {}
928
929 DeveloperPrivateGetProjectsInfoFunction::
930 ~DeveloperPrivateGetProjectsInfoFunction() {}
931
932 bool DeveloperPrivateLoadProjectFunction::RunImpl() {
933 // TODO(grv) : add unit tests.
934 base::FilePath::StringType project_name;
935 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &project_name));
936 base::FilePath path(profile()->GetPath());
937 path = path.Append(kUnpackedAppsFolder);
938 // TODO(grv) : Sanitize / check project_name.
939 path = path.Append(project_name);
940 ExtensionService* service = profile()->GetExtensionService();
941 UnpackedInstaller::Create(service)->Load(path);
942 SendResponse(true);
943 return true;
944 }
945
946 DeveloperPrivateLoadProjectFunction::DeveloperPrivateLoadProjectFunction() {}
947
948 DeveloperPrivateLoadProjectFunction::~DeveloperPrivateLoadProjectFunction() {}
949
880 bool DeveloperPrivateChoosePathFunction::RunImpl() { 950 bool DeveloperPrivateChoosePathFunction::RunImpl() {
881 951
882 scoped_ptr<developer::ChoosePath::Params> params( 952 scoped_ptr<developer::ChoosePath::Params> params(
883 developer::ChoosePath::Params::Create(*args_)); 953 developer::ChoosePath::Params::Create(*args_));
884 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 954 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
885 955
886 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; 956 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER;
887 ui::SelectFileDialog::FileTypeInfo info; 957 ui::SelectFileDialog::FileTypeInfo info;
888 if (params->select_type == developer::SELECT_TYPE_FILE) { 958 if (params->select_type == developer::SELECT_TYPE_FILE) {
889 type = ui::SelectFileDialog::SELECT_OPEN_FILE; 959 type = ui::SelectFileDialog::SELECT_OPEN_FILE;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 1079
1010 #undef SET_STRING 1080 #undef SET_STRING
1011 return true; 1081 return true;
1012 } 1082 }
1013 1083
1014 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} 1084 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {}
1015 1085
1016 } // namespace api 1086 } // namespace api
1017 1087
1018 } // namespace extensions 1088 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698