Skip to content

Commit

Permalink
guest_os: Add a DBus front-end for vmc launch
Browse files Browse the repository at this point in the history
This front-end will be used by vmc to launch VMs through chrome. The
purpose of which is to allow chrome to be a central authority on the
correct way to launch a given vm product.

See go/vmc-launch "phase 2" for details.

Bug: b/200896773
Change-Id: I26587482160afd4b8a850c077eb44b6d9ec6d854
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3527900
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: David Munro <davidmunro@google.com>
Commit-Queue: Nic Hollingum <hollingum@google.com>
Cr-Commit-Position: refs/heads/main@{#988802}
  • Loading branch information
Nicholas Hollingum authored and Chromium LUCI CQ committed Apr 5, 2022
1 parent 8db4a99 commit 44e1d45
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chrome/browser/ash/dbus/vm/org.chromium.VmLaunchService.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
<allow send_destination="org.chromium.VmLaunchService"
send_interface="org.chromium.VmLaunchService"
send_member="ProvideVmToken"/>
<allow send_destination="org.chromium.VmLaunchService"
send_interface="org.chromium.VmLaunchService"
send_member="EnsureVmLaunched"/>
</policy>
</busconfig>
41 changes: 41 additions & 0 deletions chrome/browser/ash/dbus/vm/vm_launch_service_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "chrome/browser/ash/borealis/borealis_service.h"
#include "chrome/browser/ash/borealis/borealis_util.h"
#include "chrome/browser/ash/borealis/borealis_wayland_interface.h"
#include "chrome/browser/ash/guest_os/guest_os_launcher.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
Expand Down Expand Up @@ -68,6 +69,22 @@ void OnTokenChecked(Profile* profile,
ss.str()));
}

void OnLaunchEnsured(dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender,
guest_os::launcher::ResponseType response) {
if (!response) {
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(method_call, DBUS_ERROR_FAILED,
response.Error()));
return;
}
std::unique_ptr<dbus::Response> dbus_response =
dbus::Response::FromMethodCall(method_call);
dbus::MessageWriter writer(dbus_response.get());
writer.AppendProtoAsArrayOfBytes(response.Value());
std::move(response_sender).Run(std::move(dbus_response));
}

} // namespace

VmLaunchServiceProvider::VmLaunchServiceProvider() = default;
Expand Down Expand Up @@ -96,6 +113,13 @@ void VmLaunchServiceProvider::Start(
base::BindRepeating(&VmLaunchServiceProvider::ProvideVmToken,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&OnExported));

exported_object->ExportMethod(
vm_tools::launch::kVmLaunchServiceInterface,
vm_tools::launch::kVmLaunchServiceEnsureVmLaunchedMethod,
base::BindRepeating(&VmLaunchServiceProvider::EnsureVmLaunched,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&OnExported));
}

void VmLaunchServiceProvider::StartWaylandServer(
Expand Down Expand Up @@ -208,4 +232,21 @@ void VmLaunchServiceProvider::ProvideVmToken(
std::move(response_sender), launch));
}

void VmLaunchServiceProvider::EnsureVmLaunched(
dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender) {
vm_tools::launch::EnsureVmLaunchedRequest request;
if (!dbus::MessageReader(method_call).PopArrayOfBytesAsProto(&request)) {
std::move(response_sender)
.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS,
"Unable to parse EnsureVmLaunchedRequest from message"));
return;
}

guest_os::launcher::EnsureLaunched(
request, base::BindOnce(&OnLaunchEnsured, method_call,
std::move(response_sender)));
}

} // namespace ash
3 changes: 3 additions & 0 deletions chrome/browser/ash/dbus/vm/vm_launch_service_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class VmLaunchServiceProvider
void ProvideVmToken(dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender);

void EnsureVmLaunched(dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender);

base::WeakPtrFactory<VmLaunchServiceProvider> weak_ptr_factory_{this};
};

Expand Down
14 changes: 14 additions & 0 deletions chrome/browser/ash/guest_os/guest_os_launcher.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/guest_os/guest_os_launcher.h"

namespace guest_os::launcher {

void EnsureLaunched(const vm_tools::launch::EnsureVmLaunchedRequest& request,
LaunchCallback response_callback) {
std::move(response_callback).Run(ResponseType::Unexpected("Not Implemented"));
}

} // namespace guest_os::launcher
23 changes: 23 additions & 0 deletions chrome/browser/ash/guest_os/guest_os_launcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_GUEST_OS_GUEST_OS_LAUNCHER_H_
#define CHROME_BROWSER_ASH_GUEST_OS_GUEST_OS_LAUNCHER_H_

#include "chrome/browser/ash/borealis/infra/expected.h"
#include "chromeos/dbus/vm_launch/launch.pb.h"

namespace guest_os::launcher {

using ResponseType =
borealis::Expected<vm_tools::launch::EnsureVmLaunchedResponse, std::string>;

using LaunchCallback = base::OnceCallback<void(ResponseType)>;

void EnsureLaunched(const vm_tools::launch::EnsureVmLaunchedRequest& request,
LaunchCallback response_callback);

} // namespace guest_os::launcher

#endif // CHROME_BROWSER_ASH_GUEST_OS_GUEST_OS_LAUNCHER_H_
2 changes: 2 additions & 0 deletions chrome/browser/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,8 @@ source_set("chromeos") {
"../ash/guest_os/guest_os_diagnostics_builder.h",
"../ash/guest_os/guest_os_external_protocol_handler.cc",
"../ash/guest_os/guest_os_external_protocol_handler.h",
"../ash/guest_os/guest_os_launcher.cc",
"../ash/guest_os/guest_os_launcher.h",
"../ash/guest_os/guest_os_mime_types_service.cc",
"../ash/guest_os/guest_os_mime_types_service.h",
"../ash/guest_os/guest_os_mime_types_service_factory.cc",
Expand Down

0 comments on commit 44e1d45

Please sign in to comment.