Commit 0bf2044b authored by James Cook's avatar James Cook Committed by Commit Bot

chromeos: Establish Mojo connection for Lacros part 2.

This CL introduces AshChromeService, which is a set of APIs that
lacros-chrome will call into.
With this CL, Mojo connection between ash-chrome and lacros-chrome
is now bidirectional.

Bug: 1094106
Test: Ran locally.
Change-Id: I169d55ad964073e8faebe069917a6a3a67ed5c84
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2254638Reviewed-by: default avatarGreg Kerr <kerrnel@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781662}
parent af957654
...@@ -1352,6 +1352,8 @@ source_set("chromeos") { ...@@ -1352,6 +1352,8 @@ source_set("chromeos") {
"kerberos/kerberos_credentials_manager_factory.h", "kerberos/kerberos_credentials_manager_factory.h",
"kerberos/kerberos_ticket_expiry_notification.cc", "kerberos/kerberos_ticket_expiry_notification.cc",
"kerberos/kerberos_ticket_expiry_notification.h", "kerberos/kerberos_ticket_expiry_notification.h",
"lacros/ash_chrome_service_impl.cc",
"lacros/ash_chrome_service_impl.h",
"lacros/lacros_loader.cc", "lacros/lacros_loader.cc",
"lacros/lacros_loader.h", "lacros/lacros_loader.h",
"lacros/lacros_manager.cc", "lacros/lacros_manager.cc",
......
// Copyright 2020 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/chromeos/lacros/ash_chrome_service_impl.h"
#include <utility>
#include "base/logging.h"
namespace chromeos {
AshChromeServiceImpl::AshChromeServiceImpl(
mojo::PendingReceiver<lacros::mojom::AshChromeService> pending_receiver)
: receiver_(this, std::move(pending_receiver)) {
// TODO(hidehiko): Remove non-critical log from here.
// Currently this is the signal that the connection is established.
LOG(WARNING) << "AshChromeService connected.";
}
AshChromeServiceImpl::~AshChromeServiceImpl() = default;
} // namespace chromeos
// Copyright 2020 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_CHROMEOS_LACROS_ASH_CHROME_SERVICE_IMPL_H_
#define CHROME_BROWSER_CHROMEOS_LACROS_ASH_CHROME_SERVICE_IMPL_H_
#include "chromeos/lacros/mojom/lacros.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace chromeos {
// Implementation of AshChromeService. It provides a set of APIs that
// lacros-chrome can call into.
class AshChromeServiceImpl : public lacros::mojom::AshChromeService {
public:
explicit AshChromeServiceImpl(
mojo::PendingReceiver<lacros::mojom::AshChromeService> pending_receiver);
~AshChromeServiceImpl() override;
private:
mojo::Receiver<lacros::mojom::AshChromeService> receiver_;
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LACROS_ASH_CHROME_SERVICE_IMPL_H_
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "chrome/browser/chromeos/lacros/ash_chrome_service_impl.h"
#include "chrome/browser/chromeos/lacros/lacros_loader.h" #include "chrome/browser/chromeos/lacros/lacros_loader.h"
#include "chrome/browser/chromeos/lacros/lacros_util.h" #include "chrome/browser/chromeos/lacros/lacros_util.h"
#include "chrome/browser/component_updater/cros_component_manager.h" #include "chrome/browser/component_updater/cros_component_manager.h"
...@@ -238,11 +239,20 @@ void LacrosManager::StartForeground(bool already_running) { ...@@ -238,11 +239,20 @@ void LacrosManager::StartForeground(bool already_running) {
lacros_process_.Handle(), lacros_process_.Handle(),
channel.TakeLocalEndpoint()); channel.TakeLocalEndpoint());
binder->Bind(lacros_chrome_service_.BindNewPipeAndPassReceiver()); binder->Bind(lacros_chrome_service_.BindNewPipeAndPassReceiver());
lacros_chrome_service_->RequestAshChromeServiceReceiver(
base::BindOnce(&LacrosManager::OnAshChromeServiceReceiverReceived,
weak_factory_.GetWeakPtr()));
} }
} }
LOG(WARNING) << "Launched lacros-chrome with pid " << lacros_process_.Pid(); LOG(WARNING) << "Launched lacros-chrome with pid " << lacros_process_.Pid();
} }
void LacrosManager::OnAshChromeServiceReceiverReceived(
mojo::PendingReceiver<lacros::mojom::AshChromeService> pending_receiver) {
ash_chrome_service_ =
std::make_unique<AshChromeServiceImpl>(std::move(pending_receiver));
}
void LacrosManager::OnUserSessionStarted(bool is_primary_user) { void LacrosManager::OnUserSessionStarted(bool is_primary_user) {
// Ensure this isn't called multiple times. // Ensure this isn't called multiple times.
session_manager::SessionManager::Get()->RemoveObserver(this); session_manager::SessionManager::Get()->RemoveObserver(this);
......
...@@ -22,6 +22,7 @@ class CrOSComponentManager; ...@@ -22,6 +22,7 @@ class CrOSComponentManager;
namespace chromeos { namespace chromeos {
class AshChromeServiceImpl;
class LacrosLoader; class LacrosLoader;
// Manages the lifetime of lacros-chrome, and its loading status. // Manages the lifetime of lacros-chrome, and its loading status.
...@@ -63,6 +64,11 @@ class LacrosManager : public session_manager::SessionManagerObserver { ...@@ -63,6 +64,11 @@ class LacrosManager : public session_manager::SessionManagerObserver {
// already launched and running. // already launched and running.
void StartForeground(bool already_running); void StartForeground(bool already_running);
// Called when PendingReceiver of AshChromeService is passed from
// lacros-chrome.
void OnAshChromeServiceReceiverReceived(
mojo::PendingReceiver<lacros::mojom::AshChromeService> pending_receiver);
// session_manager::SessionManagerObserver: // session_manager::SessionManagerObserver:
// Starts to load the lacros-chrome executable. // Starts to load the lacros-chrome executable.
void OnUserSessionStarted(bool is_primary_user) override; void OnUserSessionStarted(bool is_primary_user) override;
...@@ -91,6 +97,10 @@ class LacrosManager : public session_manager::SessionManagerObserver { ...@@ -91,6 +97,10 @@ class LacrosManager : public session_manager::SessionManagerObserver {
// Available during lacros-chrome is running. // Available during lacros-chrome is running.
mojo::Remote<lacros::mojom::LacrosChromeService> lacros_chrome_service_; mojo::Remote<lacros::mojom::LacrosChromeService> lacros_chrome_service_;
// Implementation of AshChromeService Mojo APIs.
// Instantiated on receiving the PendingReceiver from lacros-chrome.
std::unique_ptr<AshChromeServiceImpl> ash_chrome_service_;
base::WeakPtrFactory<LacrosManager> weak_factory_{this}; base::WeakPtrFactory<LacrosManager> weak_factory_{this};
}; };
......
...@@ -4,15 +4,23 @@ ...@@ -4,15 +4,23 @@
#include "chromeos/lacros/browser/lacros_chrome_service_impl.h" #include "chromeos/lacros/browser/lacros_chrome_service_impl.h"
#include <utility>
#include "base/logging.h"
namespace chromeos { namespace chromeos {
LacrosChromeServiceImpl::LacrosChromeServiceImpl() { LacrosChromeServiceImpl::LacrosChromeServiceImpl()
// TODO(hidehiko): Remove non-error logging from here. : pending_ash_chrome_service_receiver_(
// Currently, LacrosChromeService interface is empty, so ash_chrome_service_.BindNewPipeAndPassReceiver()) {}
// this is only way to make sure the connection is established.
LOG(WARNING) << "LacrosChromeService is connected";
}
LacrosChromeServiceImpl::~LacrosChromeServiceImpl() = default; LacrosChromeServiceImpl::~LacrosChromeServiceImpl() = default;
void LacrosChromeServiceImpl::RequestAshChromeServiceReceiver(
RequestAshChromeServiceReceiverCallback callback) {
// TODO(hidehiko): Remove non-error logging from here.
LOG(WARNING) << "AshChromeServiceReceiver requested.";
std::move(callback).Run(std::move(pending_ash_chrome_service_receiver_));
}
} // namespace chromeos } // namespace chromeos
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/component_export.h" #include "base/component_export.h"
#include "chromeos/lacros/mojom/lacros.mojom.h" #include "chromeos/lacros/mojom/lacros.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace chromeos { namespace chromeos {
...@@ -14,8 +15,30 @@ namespace chromeos { ...@@ -14,8 +15,30 @@ namespace chromeos {
class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl class COMPONENT_EXPORT(CHROMEOS_LACROS) LacrosChromeServiceImpl
: public lacros::mojom::LacrosChromeService { : public lacros::mojom::LacrosChromeService {
public: public:
// TODO(hidehiko): Add static getter of the instance.
// The instance of this class should be globally unique.
LacrosChromeServiceImpl(); LacrosChromeServiceImpl();
~LacrosChromeServiceImpl() override; ~LacrosChromeServiceImpl() override;
// lacros::mojom::LacrosChromeService:
void RequestAshChromeServiceReceiver(
RequestAshChromeServiceReceiverCallback callback) override;
private:
// Proxy to AshChromeService in ash-chrome.
// TODO(hidehiko): Add getter for Remote<AshChromeService>.
mojo::Remote<lacros::mojom::AshChromeService> ash_chrome_service_;
// Pending receiver of AshChromeService.
// AshChromeService is bound to mojo::Remote on construction, then
// when AshChromeService requests via RequestAshChromeServiceReceiver,
// its PendingReceiver is returned.
// This member holds the PendingReceiver between them. Note that even
// during the period, calling a method on AshChromeService via Remote
// should be available.
mojo::PendingReceiver<lacros::mojom::AshChromeService>
pending_ash_chrome_service_receiver_;
}; };
} // namespace chromeos } // namespace chromeos
......
...@@ -4,9 +4,19 @@ ...@@ -4,9 +4,19 @@
module lacros.mojom; module lacros.mojom;
// AshChromeService defines the APIs that live in ash-chrome and are
// accessed from lacros-chrome.
interface AshChromeService {
};
// LacrosChromeService defines the APIs that live in lacros-chrome and // LacrosChromeService defines the APIs that live in lacros-chrome and
// are accessed from ash-chrome. // are accessed from ash-chrome.
interface LacrosChromeService { interface LacrosChromeService {
// TODO(hidehiko): Add API to return pending_receiver for // Returns the pending_receiver of AshChromeService.
// ash-chrome interface. // Ash-chrome is expected to call this method on initialization.
// Lacros-chrome may call AshChromeService APIs earlier than this
// invocation. In the case, the calls are queued, and processed
// sequentially, when ash-chrome binds the receiver to the service.
RequestAshChromeServiceReceiver@0() => (
pending_receiver<AshChromeService> receiver);
}; };
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