Skip to content

Commit

Permalink
Display .deb package info in install dialog
Browse files Browse the repository at this point in the history
This CL adds a details pane in the file manager's .deb install dialog
to provide package name, version, and a description of the package.

Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I43833f2ce83645ea45d6c9a30f7bd3acd89a9cb4
Reviewed-on: https://chromium-review.googlesource.com/c/1167005
Reviewed-by: Ben Wells <benwells@chromium.org>
Reviewed-by: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: Ryo Hashimoto <hashimoto@chromium.org>
Reviewed-by: Nicholas Verne <nverne@chromium.org>
Commit-Queue: Timothy Loh <timloh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601812}
  • Loading branch information
tim-loh authored and Commit Bot committed Oct 23, 2018
1 parent e34a52f commit 3358dab
Show file tree
Hide file tree
Showing 31 changed files with 573 additions and 6 deletions.
18 changes: 18 additions & 0 deletions chrome/app/file_manager_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,24 @@
<message name="IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_TITLE" desc="In the File Manager, the title shown in the dialog for installing a Linux application.">
Install app with Linux (Beta)
</message>
<message name="IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_LABEL" desc="In the File Manager, the label shown above the app information (name, version, etc.) in the dialog for installing a Linux application.">
Details
</message>
<message name="IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_APPLICATION_LABEL" desc="In the File Manager, the label shown next to the application name in the dialog for installing a Linux application.">
Application
</message>
<message name="IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_VERSION_LABEL" desc="In the File Manager, the label shown next to the version string in the dialog for installing a Linux application.">
Version
</message>
<message name="IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_DESCRIPTION_LABEL" desc="In the File Manager, the label shown next to a block of text describing the application in the dialog for installing a Linux application.">
Description
</message>
<message name="IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_LOADING" desc="In the File Manager, the message shown to indicate we are loading information about the application (name, version, etc.) in the dialog for installing a Linux application.">
Loading information...
</message>
<message name="IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_NOT_AVAILABLE" desc="In the File Manager, the message shown to indicate we failed to load information about the application in the dialog for installing a Linux application.">
Failed to retrieve app info.
</message>
<message name="IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DESCRIPTION" desc="In the File Manager, the message shown in the dialog for installing a Linux application.">
The Linux application will be available within your Terminal and may also show an icon in your Launcher.
</message>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c79718de6f51228c5f981504e46590cc506fb4e0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c79718de6f51228c5f981504e46590cc506fb4e0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c79718de6f51228c5f981504e46590cc506fb4e0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dea09d18d811d796902e9aef5bae74f16879771e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2f412562b317672ce971650e26c5e9ef8d16e3f7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c79718de6f51228c5f981504e46590cc506fb4e0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c79718de6f51228c5f981504e46590cc506fb4e0
68 changes: 68 additions & 0 deletions chrome/browser/chromeos/crostini/crostini_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "base/bind.h"
#include "base/no_destructor.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
#include "base/task/post_task.h"
Expand Down Expand Up @@ -422,6 +423,9 @@ void CrostiniManager::AddRunningVmForTesting(
std::make_pair(VmState::STARTED, std::move(vm_info));
}

LinuxPackageInfo::LinuxPackageInfo() = default;
LinuxPackageInfo::~LinuxPackageInfo() = default;

bool CrostiniManager::IsContainerRunning(std::string vm_name,
std::string container_name) {
if (!IsVmRunning(vm_name)) {
Expand Down Expand Up @@ -946,6 +950,24 @@ void CrostiniManager::GetContainerAppIcons(
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}

void CrostiniManager::GetLinuxPackageInfo(
Profile* profile,
std::string vm_name,
std::string container_name,
std::string package_path,
GetLinuxPackageInfoCallback callback) {
vm_tools::cicerone::LinuxPackageInfoRequest request;
request.set_owner_id(CryptohomeIdForProfile(profile));
request.set_vm_name(std::move(vm_name));
request.set_container_name(std::move(container_name));
request.set_file_path(std::move(package_path));

GetCiceroneClient()->GetLinuxPackageInfo(
std::move(request),
base::BindOnce(&CrostiniManager::OnGetLinuxPackageInfo,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}

void CrostiniManager::InstallLinuxPackage(
std::string vm_name,
std::string container_name,
Expand Down Expand Up @@ -1563,6 +1585,52 @@ void CrostiniManager::OnGetContainerAppIcons(
std::move(callback).Run(CrostiniResult::SUCCESS, icons);
}

void CrostiniManager::OnGetLinuxPackageInfo(
GetLinuxPackageInfoCallback callback,
base::Optional<vm_tools::cicerone::LinuxPackageInfoResponse> reply) {
LinuxPackageInfo result;
if (!reply.has_value()) {
LOG(ERROR) << "Failed to get Linux package info. Empty response.";
result.success = false;
// The error message is currently only used in a console message. If we
// want to display it to the user, we'd need to localize this.
result.failure_reason = "D-Bus response was empty.";
std::move(callback).Run(result);
return;
}
vm_tools::cicerone::LinuxPackageInfoResponse response = reply.value();

if (!response.success()) {
LOG(ERROR) << "Failed to get Linux package info: "
<< response.failure_reason();
result.success = false;
result.failure_reason = response.failure_reason();
std::move(callback).Run(result);
return;
}

// The |package_id| field is formatted like "name;version;arch;data". We're
// currently only interested in name and version.
std::vector<std::string> split = base::SplitString(
response.package_id(), ";", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
if (split.size() < 2 || split[0].empty() || split[1].empty()) {
LOG(ERROR) << "Linux package info contained invalid package id: \""
<< response.package_id() << '"';
result.success = false;
result.failure_reason = "Linux package info contained invalid package id.";
std::move(callback).Run(result);
return;
}

result.success = true;
result.name = split[0];
result.version = split[1];
result.description = response.description();
result.summary = response.summary();

std::move(callback).Run(result);
}

void CrostiniManager::OnInstallLinuxPackage(
InstallLinuxPackageCallback callback,
base::Optional<vm_tools::cicerone::InstallLinuxPackageResponse> reply) {
Expand Down
32 changes: 32 additions & 0 deletions chrome/browser/chromeos/crostini/crostini_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ struct Icon {
std::string content;
};

struct LinuxPackageInfo {
LinuxPackageInfo();
~LinuxPackageInfo();

bool success;

// A textual reason for the failure, only set when success is false.
std::string failure_reason;

// The remaining fields are only set when success is true.
std::string name;
std::string version;
std::string summary;
std::string description;
};

class InstallLinuxPackageProgressObserver {
public:
// A successfully started package install will continually fire progress
Expand Down Expand Up @@ -130,6 +146,9 @@ class CrostiniManager : public KeyedService,
using GetContainerAppIconsCallback =
base::OnceCallback<void(CrostiniResult result,
const std::vector<Icon>& icons)>;
// The type of the callback for CrostiniManager::GetLinuxPackageInfo.
using GetLinuxPackageInfoCallback =
base::OnceCallback<void(const LinuxPackageInfo&)>;
// The type of the callback for CrostiniManager::InstallLinuxPackage.
// |failure_reason| is returned from the container upon failure
// (INSTALL_LINUX_PACKAGE_FAILED), and not necessarily localized.
Expand Down Expand Up @@ -283,6 +302,14 @@ class CrostiniManager : public KeyedService,
int scale,
GetContainerAppIconsCallback callback);

// Asynchronously retrieve information about a Linux Package (.deb) inside the
// container.
void GetLinuxPackageInfo(Profile* profile,
std::string vm_name,
std::string container_name,
std::string package_path,
GetLinuxPackageInfoCallback callback);

// Begin installation of a Linux Package inside the container. If the
// installation is successfully started, further updates will be sent to
// added InstallLinuxPackageProgressObservers.
Expand Down Expand Up @@ -486,6 +513,11 @@ class CrostiniManager : public KeyedService,
GetContainerAppIconsCallback callback,
base::Optional<vm_tools::cicerone::ContainerAppIconResponse> reply);

// Callback for CrostiniManager::GetLinuxPackageInfo.
void OnGetLinuxPackageInfo(
GetLinuxPackageInfoCallback callback,
base::Optional<vm_tools::cicerone::LinuxPackageInfoResponse> reply);

// Callback for CrostiniManager::InstallLinuxPackage.
void OnInstallLinuxPackage(
InstallLinuxPackageCallback callback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ void CrostiniPackageInstallerService::NotificationClosed(
NOTREACHED();
}

void CrostiniPackageInstallerService::GetLinuxPackageInfo(
const std::string& vm_name,
const std::string& container_name,
const std::string& package_path,
CrostiniManager::GetLinuxPackageInfoCallback callback) {
CrostiniManager::GetForProfile(profile_)->GetLinuxPackageInfo(
profile_, vm_name, container_name, package_path,
base::BindOnce(&CrostiniPackageInstallerService::OnGetLinuxPackageInfo,
weak_ptr_factory_.GetWeakPtr(), vm_name, container_name,
std::move(callback)));
}

void CrostiniPackageInstallerService::InstallLinuxPackage(
const std::string& vm_name,
const std::string& container_name,
Expand Down Expand Up @@ -122,6 +134,16 @@ void CrostiniPackageInstallerService::OnInstallLinuxPackageProgress(
}
}

void CrostiniPackageInstallerService::OnGetLinuxPackageInfo(
const std::string& vm_name,
const std::string& container_name,
CrostiniManager::GetLinuxPackageInfoCallback callback,
const LinuxPackageInfo& linux_package_info) {
std::move(callback).Run(linux_package_info);
if (!linux_package_info.success)
return;
}

void CrostiniPackageInstallerService::OnInstallLinuxPackage(
const std::string& vm_name,
const std::string& container_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class CrostiniPackageInstallerService

void NotificationClosed(CrostiniPackageInstallerNotification* notification);

// The package installer service caches the most recent retrieved package
// info, for use in a package install notification.
// TODO(timloh): Actually cache the values.
void GetLinuxPackageInfo(
const std::string& vm_name,
const std::string& container_name,
const std::string& package_path,
CrostiniManager::GetLinuxPackageInfoCallback callback);

// Install a Linux package. If successfully started, a system notification
// will be used to display further updates.
void InstallLinuxPackage(
Expand All @@ -47,6 +56,13 @@ class CrostiniPackageInstallerService
const std::string& failure_reason) override;

private:
// Wraps the callback provided in GetLinuxPackageInfo().
void OnGetLinuxPackageInfo(
const std::string& vm_name,
const std::string& container_name,
CrostiniManager::GetLinuxPackageInfoCallback callback,
const LinuxPackageInfo& linux_package_info);

// Wraps the callback provided in InstallLinuxPackage().
void OnInstallLinuxPackage(
const std::string& vm_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,50 @@ void FileManagerPrivateInternalGetCrostiniSharedPathsFunction::
*entry_definition_list)));
}

ExtensionFunction::ResponseAction
FileManagerPrivateInternalGetLinuxPackageInfoFunction::Run() {
using api::file_manager_private_internal::GetLinuxPackageInfo::Params;
const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);

Profile* profile = Profile::FromBrowserContext(browser_context());
const scoped_refptr<storage::FileSystemContext> file_system_context =
file_manager::util::GetFileSystemContextForRenderFrameHost(
profile, render_frame_host());

std::string url =
file_manager::util::ConvertFileSystemURLToPathInsideCrostini(
profile, file_system_context->CrackURL(GURL(params->url)));
crostini::CrostiniPackageInstallerService::GetForProfile(profile)
->GetLinuxPackageInfo(
crostini::kCrostiniDefaultVmName,
crostini::kCrostiniDefaultContainerName, url,
base::BindOnce(
&FileManagerPrivateInternalGetLinuxPackageInfoFunction::
OnGetLinuxPackageInfo,
this));
return RespondLater();
}

void FileManagerPrivateInternalGetLinuxPackageInfoFunction::
OnGetLinuxPackageInfo(
const crostini::LinuxPackageInfo& linux_package_info) {
api::file_manager_private::LinuxPackageInfo result;
if (!linux_package_info.success) {
Respond(Error(linux_package_info.failure_reason));
return;
}

result.name = linux_package_info.name;
result.version = linux_package_info.version;
result.summary = std::make_unique<std::string>(linux_package_info.summary);
result.description =
std::make_unique<std::string>(linux_package_info.description);

Respond(ArgumentList(extensions::api::file_manager_private_internal::
GetLinuxPackageInfo::Results::Create(result)));
}

ExtensionFunction::ResponseAction
FileManagerPrivateInternalInstallLinuxPackageFunction::Run() {
using extensions::api::file_manager_private_internal::InstallLinuxPackage::
Expand Down
21 changes: 21 additions & 0 deletions chrome/browser/chromeos/extensions/file_manager/private_api_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class RecentFile;

namespace crostini {
enum class CrostiniResult;
struct LinuxPackageInfo;
}

namespace file_manager {
Expand Down Expand Up @@ -344,6 +345,26 @@ class FileManagerPrivateInternalGetCrostiniSharedPathsFunction
FileManagerPrivateInternalGetCrostiniSharedPathsFunction);
};

// Implements the chrome.fileManagerPrivate.getLinuxPackageInfo method.
// Retrieves information about a Linux package.
class FileManagerPrivateInternalGetLinuxPackageInfoFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getLinuxPackageInfo",
FILEMANAGERPRIVATEINTERNAL_GETLINUXPACKAGEINFO)
FileManagerPrivateInternalGetLinuxPackageInfoFunction() = default;

protected:
~FileManagerPrivateInternalGetLinuxPackageInfoFunction() override = default;

private:
ResponseAction Run() override;
void OnGetLinuxPackageInfo(
const crostini::LinuxPackageInfo& linux_package_info);
DISALLOW_COPY_AND_ASSIGN(
FileManagerPrivateInternalGetLinuxPackageInfoFunction);
};

// Implements the chrome.fileManagerPrivate.installLinuxPackage method.
// Starts installation of a Linux package.
class FileManagerPrivateInternalInstallLinuxPackageFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,18 @@ ExtensionFunction::ResponseAction FileManagerPrivateGetStringsFunction::Run() {
IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_TITLE);
SET_STRING("INSTALL_LINUX_PACKAGE_DESCRIPTION",
IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DESCRIPTION);
SET_STRING("INSTALL_LINUX_PACKAGE_DETAILS_LABEL",
IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_LABEL);
SET_STRING("INSTALL_LINUX_PACKAGE_DETAILS_APPLICATION_LABEL",
IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_APPLICATION_LABEL);
SET_STRING("INSTALL_LINUX_PACKAGE_DETAILS_VERSION_LABEL",
IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_VERSION_LABEL);
SET_STRING("INSTALL_LINUX_PACKAGE_DETAILS_DESCRIPTION_LABEL",
IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_DESCRIPTION_LABEL);
SET_STRING("INSTALL_LINUX_PACKAGE_DETAILS_LOADING",
IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_LOADING);
SET_STRING("INSTALL_LINUX_PACKAGE_DETAILS_NOT_AVAILABLE",
IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_DETAILS_NOT_AVAILABLE);
SET_STRING("INSTALL_LINUX_PACKAGE_INSTALL_BUTTON",
IDS_FILE_BROWSER_INSTALL_LINUX_PACKAGE_INSTALL_BUTTON);
SET_STRING("INSTALL_LINUX_PACKAGE_INSTALLATION_STARTED",
Expand Down
Loading

0 comments on commit 3358dab

Please sign in to comment.