Chromium Code Reviews| Index: chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api.cc b/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| index 37209587209b437962148edb436f489f77838167..5291efd55f7bb88088640a62915817ec290515a4 100644 |
| --- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| +++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc |
| @@ -66,6 +66,7 @@ |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/base/webui/web_ui_util.h" |
| +#include "webkit/browser/fileapi/external_mount_points.h" |
| #include "webkit/browser/fileapi/file_system_context.h" |
| #include "webkit/browser/fileapi/file_system_operation.h" |
| #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| @@ -961,63 +962,98 @@ DeveloperPrivatePackDirectoryFunction::~DeveloperPrivatePackDirectoryFunction() |
| DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} |
| -bool DeveloperPrivateExportSyncfsFolderToLocalfsFunction::RunImpl() { |
| +bool DeveloperPrivateLoadDirectoryFunction::RunImpl() { |
| // TODO(grv) : add unittests. |
| - base::FilePath::StringType project_name; |
| - EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &project_name)); |
| - if (!ValidateFolderName(project_name)) { |
| - DVLOG(0) << "Invalid project_name : [" << project_name << "]"; |
| - return false; |
| - } |
| + std::string directory_url_str; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &directory_url_str)); |
| + size_t pos = 0; |
| + |
| + bool syncfs = true; |
|
Gaurav
2014/01/16 02:07:07
Will update with syncfs folder check.
|
| + if (syncfs) { |
| + |
| + base::FilePath::StringType project_name; |
| + // Parse the project directory name from the project url. The project url is |
| + // expected to have project name as the suffix. |
| + if ((pos = directory_url_str.rfind("/")) == std::string::npos) { |
| + SetError("Invalid Directory entry."); |
| + return false; |
| + } |
| - context_ = content::BrowserContext::GetStoragePartition( |
| - GetProfile(), render_view_host()->GetSiteInstance()) |
| - ->GetFileSystemContext(); |
| + project_name = directory_url_str.substr(pos + 1); |
| + project_base_url_ = directory_url_str.substr(0, pos + 1); |
| - base::FilePath project_path(GetProfile()->GetPath()); |
| - project_path = project_path.Append(kUnpackedAppsFolder); |
| - project_path = project_path.Append(project_name); |
| + if (!ValidateFolderName(project_name)) { |
| + DVLOG(0) << "Invalid project_name : [" << project_name << "]"; |
| + return false; |
| + } |
| - content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| - ClearPrexistingDirectoryContent, |
| - this, |
| - project_path)); |
| + context_ = content::BrowserContext::GetStoragePartition( |
| + GetProfile(), render_view_host()->GetSiteInstance()) |
| + ->GetFileSystemContext(); |
| + |
| + base::FilePath project_path(GetProfile()->GetPath()); |
| + project_path = project_path.Append(kUnpackedAppsFolder); |
| + project_path = project_path.Append(project_name); |
| + |
| + path_ = project_path; |
| + |
| + content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
| + base::Bind(&DeveloperPrivateLoadDirectoryFunction:: |
| + ClearExistingDirectoryContent, |
| + this, |
| + path_)); |
| + } else { |
| + |
| + base::FilePath::StringType path_str(directory_url_str); |
| + path_ = path_.Append(path_str); |
| + Load(); |
| + } |
| return true; |
| } |
| -void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| - ClearPrexistingDirectoryContent(const base::FilePath& project_path) { |
| +void DeveloperPrivateLoadDirectoryFunction::Load() { |
| + |
| + ExtensionService* service = GetProfile()->GetExtensionService(); |
| + UnpackedInstaller::Create(service)->Load(path_); |
| + |
| + // TODO(grv) : The unpacked installer should fire an event when complete |
| + // and return the extension_id. |
| + SetResult(new base::StringValue("-1")); |
| + SendResponse(true); |
| +} |
| + |
| +void DeveloperPrivateLoadDirectoryFunction::ClearExistingDirectoryContent( |
| + const base::FilePath& project_path) { |
| // Clear the project directory before copying new files. |
| base::DeleteFile(project_path, true/*recursive*/); |
| - pendingCopyOperationsCount_ = 1; |
| + pending_copy_operations_count_ = 1; |
| content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
| - base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| + base::Bind(&DeveloperPrivateLoadDirectoryFunction:: |
| ReadSyncFileSystemDirectory, |
| this, project_path, project_path.BaseName())); |
| } |
| -void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| - ReadSyncFileSystemDirectory(const base::FilePath& project_path, |
| - const base::FilePath& destination_path) { |
| - std::string origin_url( |
| - Extension::GetBaseURLFromExtensionId(extension_id()).spec()); |
| - fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( |
| - GURL(origin_url), |
| - destination_path)); |
| +void DeveloperPrivateLoadDirectoryFunction::ReadSyncFileSystemDirectory( |
| + const base::FilePath& project_path, |
| + const base::FilePath& destination_path) { |
| + |
| + project_path_ = context_->CrackURL(GURL(project_base_url_)).path(); |
| + |
| + GURL project_url = GURL(project_base_url_ + destination_path.MaybeAsASCII()); |
| + |
| + fileapi::FileSystemURL url = context_->CrackURL(project_url); |
| context_->operation_runner()->ReadDirectory( |
| - url, base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| + url, base::Bind(&DeveloperPrivateLoadDirectoryFunction:: |
| ReadSyncFileSystemDirectoryCb, |
| this, project_path, destination_path)); |
| } |
| -void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| - ReadSyncFileSystemDirectoryCb( |
| +void DeveloperPrivateLoadDirectoryFunction::ReadSyncFileSystemDirectoryCb( |
| const base::FilePath& project_path, |
| const base::FilePath& destination_path, |
| base::PlatformFileError status, |
| @@ -1036,7 +1072,7 @@ void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| // In case the directory happens to be executing the last copy operation it |
| // will call SendResponse to send the response to the API. The pending copy |
| // operations of files are released by the CopyFile function. |
| - pendingCopyOperationsCount_ += file_list.size(); |
| + pending_copy_operations_count_ += file_list.size(); |
| for (size_t i = 0; i < file_list.size(); ++i) { |
| if (file_list[i].is_directory) { |
| @@ -1049,33 +1085,30 @@ void DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| Extension::GetBaseURLFromExtensionId(extension_id()).spec()); |
| fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL( |
| GURL(origin_url), |
| - destination_path.Append(file_list[i].name))); |
| + project_path_.Append(destination_path.Append(file_list[i].name)))); |
| base::FilePath target_path = project_path; |
| target_path = target_path.Append(file_list[i].name); |
| context_->operation_runner()->CreateSnapshotFile( |
| url, |
| - base::Bind( |
| - &DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| - SnapshotFileCallback, |
| + base::Bind(&DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback, |
| this, |
| target_path)); |
| } |
| // Directory copy operation released here. |
| - pendingCopyOperationsCount_--; |
| + pending_copy_operations_count_--; |
| - if (!pendingCopyOperationsCount_) { |
| + if (!pending_copy_operations_count_) { |
| content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| - base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| - SendResponse, |
| + base::Bind(&DeveloperPrivateLoadDirectoryFunction::SendResponse, |
| this, |
| success_)); |
| } |
| } |
| -void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::SnapshotFileCallback( |
| +void DeveloperPrivateLoadDirectoryFunction::SnapshotFileCallback( |
| const base::FilePath& target_path, |
| base::PlatformFileError result, |
| const base::PlatformFileInfo& file_info, |
| @@ -1088,13 +1121,13 @@ void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::SnapshotFileCallback( |
| } |
| content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction::CopyFile, |
| + base::Bind(&DeveloperPrivateLoadDirectoryFunction::CopyFile, |
| this, |
| src_path, |
| target_path)); |
| } |
| -void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::CopyFile( |
| +void DeveloperPrivateLoadDirectoryFunction::CopyFile( |
| const base::FilePath& src_path, |
| const base::FilePath& target_path) { |
| if (!base::CreateDirectory(target_path.DirName())) { |
| @@ -1105,71 +1138,21 @@ void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::CopyFile( |
| if (success_) |
| base::CopyFile(src_path, target_path); |
| - CHECK(pendingCopyOperationsCount_ > 0); |
| - pendingCopyOperationsCount_--; |
| + CHECK(pending_copy_operations_count_ > 0); |
| + pending_copy_operations_count_--; |
| - if (!pendingCopyOperationsCount_) { |
| + if (!pending_copy_operations_count_) { |
| content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| - base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| - SendResponse, |
| - this, |
| - success_)); |
| - } |
| -} |
| - |
| -DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| - DeveloperPrivateExportSyncfsFolderToLocalfsFunction() |
| - : pendingCopyOperationsCount_(0), success_(true) {} |
| - |
| -DeveloperPrivateExportSyncfsFolderToLocalfsFunction:: |
| - ~DeveloperPrivateExportSyncfsFolderToLocalfsFunction() {} |
| - |
| -bool DeveloperPrivateLoadProjectFunction::RunImpl() { |
| - // TODO(grv) : add unit tests. |
| - base::FilePath::StringType project_name; |
| - EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &project_name)); |
| - if (!ValidateFolderName(project_name)) { |
| - DVLOG(0) << "Invalid project_name : [" << project_name << "]"; |
| - return false; |
| - } |
| - |
| - base::FilePath path(GetProfile()->GetPath()); |
| - path = path.Append(kUnpackedAppsFolder); |
| - // TODO(grv) : Sanitize / check project_name. |
| - path = path.Append(project_name); |
| - ExtensionService* service = GetProfile()->GetExtensionService(); |
| - UnpackedInstaller::Create(service)->Load(path); |
| - |
| - const extensions::ExtensionSet* extensions = service->extensions(); |
| - // Released by GetUnpackedExtension. |
| - AddRef(); |
| - content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&DeveloperPrivateLoadProjectFunction::GetUnpackedExtension, |
| - this, path, extensions)); |
| - return true; |
| -} |
| - |
| -void DeveloperPrivateLoadProjectFunction::GetUnpackedExtension( |
| - const base::FilePath& path, |
| - const extensions::ExtensionSet* extensions) { |
| - const Extension* extension = GetExtensionByPath(extensions, path); |
| - bool success = true; |
| - if (extension) { |
| - SetResult(new base::StringValue(extension->id())); |
| - } else { |
| - SetError("unable to load the project"); |
| - success = false; |
| + base::Bind(&DeveloperPrivateLoadDirectoryFunction::Load, |
| + this)); |
| } |
| - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| - base::Bind(&DeveloperPrivateLoadProjectFunction::SendResponse, |
| - this, |
| - success)); |
| - Release(); |
| } |
| -DeveloperPrivateLoadProjectFunction::DeveloperPrivateLoadProjectFunction() {} |
| +DeveloperPrivateLoadDirectoryFunction::DeveloperPrivateLoadDirectoryFunction() |
| + : pending_copy_operations_count_(0), success_(true) {} |
| -DeveloperPrivateLoadProjectFunction::~DeveloperPrivateLoadProjectFunction() {} |
| +DeveloperPrivateLoadDirectoryFunction::~DeveloperPrivateLoadDirectoryFunction() |
| + {} |
| bool DeveloperPrivateChoosePathFunction::RunImpl() { |