Commit 31973625 authored by Erik Chen's avatar Erik Chen Committed by Commit Bot

lacros: Provide synchronous version info for crosapi ash interfaces.

Ash now sends, at lacros startup, a map of all crosapi interfaces and
their versions to Lacros. Lacros can use this map to synchronously query
version info.

Bug: 1136652
Change-Id: I14be7f1c9c39709e342c6ab8045587f7d1245e74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2454629
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarGreg Kerr <kerrnel@chromium.org>
Auto-Submit: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816273}
parent 63a13975
......@@ -7,6 +7,7 @@
#include <utility>
#include "base/callback.h"
#include "base/containers/flat_map.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/process/process_handle.h"
......@@ -58,6 +59,12 @@ bool IsUserTypeAllowed(const User* user) {
}
}
using InterfaceVersions = base::flat_map<base::Token, uint32_t>;
template <typename T>
void AddVersion(InterfaceVersions* map) {
(*map)[T::Uuid_] = T::Version_;
}
mojom::LacrosInitParamsPtr GetLacrosInitParams(
EnvironmentProvider* environment_provider) {
auto params = mojom::LacrosInitParams::New();
......@@ -69,6 +76,8 @@ mojom::LacrosInitParamsPtr GetLacrosInitParams(
params->session_type = environment_provider->GetSessionType();
params->device_mode = environment_provider->GetDeviceMode();
params->interface_versions = GetInterfaceVersions();
return params;
}
......@@ -134,6 +143,23 @@ bool IsLacrosWindow(const aura::Window* window) {
return base::StartsWith(*app_id, kLacrosAppIdPrefix);
}
base::flat_map<base::Token, uint32_t> GetInterfaceVersions() {
static_assert(
crosapi::mojom::AshChromeService::Version_ == 4,
"if you add a new crosapi, please add it to the version map here");
InterfaceVersions versions;
AddVersion<crosapi::mojom::AccountManager>(&versions);
AddVersion<crosapi::mojom::AshChromeService>(&versions);
AddVersion<crosapi::mojom::Feedback>(&versions);
AddVersion<crosapi::mojom::KeystoreService>(&versions);
AddVersion<crosapi::mojom::MessageCenter>(&versions);
AddVersion<crosapi::mojom::ScreenManager>(&versions);
AddVersion<crosapi::mojom::SnapshotCapturer>(&versions);
AddVersion<device::mojom::HidConnection>(&versions);
AddVersion<device::mojom::HidManager>(&versions);
return versions;
}
mojo::Remote<crosapi::mojom::LacrosChromeService>
SendMojoInvitationToLacrosChrome(
EnvironmentProvider* environment_provider,
......
......@@ -6,6 +6,8 @@
#define CHROME_BROWSER_CHROMEOS_CROSAPI_BROWSER_UTIL_H_
#include "base/callback_forward.h"
#include "base/containers/flat_map.h"
#include "base/token.h"
#include "chrome/browser/chromeos/crosapi/environment_provider.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
......@@ -53,6 +55,9 @@ bool IsLacrosAllowed(version_info::Channel channel);
// browser.
bool IsLacrosWindow(const aura::Window* window);
// Returns the UUID and version for all tracked interfaces. Exposed for testing.
base::flat_map<base::Token, uint32_t> GetInterfaceVersions();
// Invite the lacros-chrome to the mojo universe.
// Queue messages to establish the mojo connection, so that the passed IPC is
// available already when lacros-chrome accepts the invitation.
......
......@@ -13,6 +13,7 @@
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/scoped_user_manager.h"
#include "components/version_info/channel.h"
......@@ -92,4 +93,18 @@ TEST_F(LacrosUtilTest, BlockedForChildUser) {
EXPECT_FALSE(browser_util::IsLacrosAllowed(Channel::UNKNOWN));
}
TEST_F(LacrosUtilTest, GetInterfaceVersions) {
base::flat_map<base::Token, uint32_t> versions =
browser_util::GetInterfaceVersions();
// Check that a known interface with version > 0 is present and has non-zero
// version.
EXPECT_GT(versions[mojom::KeystoreService::Uuid_], 0);
// Check that the empty token is not present.
base::Token token;
auto it = versions.find(token);
EXPECT_EQ(it, versions.end());
}
} // namespace crosapi
......@@ -10,6 +10,7 @@ import "chromeos/crosapi/mojom/keystore_service.mojom";
import "chromeos/crosapi/mojom/message_center.mojom";
import "chromeos/crosapi/mojom/screen_manager.mojom";
import "chromeos/crosapi/mojom/select_file.mojom";
import "mojo/public/mojom/base/token.mojom";
import "services/device/public/mojom/hid.mojom";
// LacrosInfo is a set of parameters passed to ash from lacros-chrome
......@@ -143,6 +144,14 @@ struct LacrosInitParams {
// user chooses to enroll the device).
[MinVersion=4]
DeviceMode device_mode@4;
// Ash sends all known crosapi interfaces and their versions at startup so
// that Lacros can synchronously query version info. Interfaces are identified
// by a UUID, which is manually generated and assigned via the UUID mojom
// qualifier.
// Added in M88.
[MinVersion=5]
map<mojo_base.mojom.Token, uint32>? interface_versions@5;
};
// LacrosChromeService defines the APIs that live in lacros-chrome and
......
......@@ -359,6 +359,20 @@ bool LacrosChromeServiceImpl::IsOnLacrosStartupAvailable() {
return AshChromeServiceVersion() >= 3;
}
int LacrosChromeServiceImpl::GetInterfaceVersion(
base::Token interface_uuid) const {
if (g_disable_all_crosapi_for_tests)
return -1;
if (!init_params_->interface_versions)
return -1;
const base::flat_map<base::Token, uint32_t>& versions =
init_params_->interface_versions.value();
auto it = versions.find(interface_uuid);
if (it == versions.end())
return -1;
return it->second;
}
void LacrosChromeServiceImpl::BindScreenManagerReceiver(
mojo::PendingReceiver<crosapi::mojom::ScreenManager> pending_receiver) {
DCHECK(IsScreenManagerAvailable());
......
......@@ -166,6 +166,12 @@ class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl {
return init_params_.get();
}
// Returns the version for an ash interface with a given UUID. Returns -1 if
// the interface is not found. This is a synchronous version of
// mojo::Remote::QueryVersion. It relies on Ash M88. Features that need to
// work on M87 or older should not use this.
int GetInterfaceVersion(base::Token interface_uuid) const;
private:
// LacrosChromeServiceNeverBlockingState is an implementation detail of this
// class.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment