Commit 8aca3b4d authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Chromium LUCI CQ

Support multiple receivers for Cros APIs.

With this CL, most of Cros API starts to support multiple receivers.
AshChromeService and LacrosChromeService are exceptions.

Bug: 1148448
Test: Build and run Lacros on a DUT.
Change-Id: I1d1a0be111108ae15657d81ea747750a760bd2f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2624323Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842869}
parent f03d4a9b
......@@ -44,12 +44,17 @@ namespace crosapi {
AshChromeServiceImpl::AshChromeServiceImpl(
mojo::PendingReceiver<mojom::AshChromeService> pending_receiver)
: receiver_(this, std::move(pending_receiver)),
file_manager_ash_(std::make_unique<FileManagerAsh>()),
keystore_service_ash_(std::make_unique<KeystoreServiceAsh>()),
message_center_ash_(std::make_unique<MessageCenterAsh>()),
metrics_reporting_ash_(std::make_unique<MetricsReportingAsh>(
g_browser_process->local_state())),
prefs_ash_(std::make_unique<PrefsAsh>(
g_browser_process->local_state(),
ProfileManager::GetPrimaryUserProfile()->GetPrefs())),
screen_manager_ash_(std::make_unique<ScreenManagerAsh>()),
select_file_ash_(std::make_unique<SelectFileAsh>()),
feedback_ash_(std::make_unique<FeedbackAsh>()),
cert_database_ash_(std::make_unique<CertDatabaseAsh>()),
test_controller_ash_(std::make_unique<TestControllerAsh>()),
clipboard_ash_(std::make_unique<ClipboardAsh>()) {
......@@ -98,25 +103,17 @@ void AshChromeServiceImpl::BindAccountManager(
void AshChromeServiceImpl::BindFileManager(
mojo::PendingReceiver<crosapi::mojom::FileManager> receiver) {
// TODO(https://crbug.com/1148448): Convert this to allow multiple,
// simultaneous crosapi clients. See BindScreenManager for an example.
file_manager_ash_ =
std::make_unique<crosapi::FileManagerAsh>(std::move(receiver));
file_manager_ash_->BindReceiver(std::move(receiver));
}
void AshChromeServiceImpl::BindKeystoreService(
mojo::PendingReceiver<crosapi::mojom::KeystoreService> receiver) {
// TODO(https://crbug.com/1148448): Convert this to allow multiple,
// simultaneous crosapi clients. See BindScreenManager for an example.
keystore_service_ash_ =
std::make_unique<crosapi::KeystoreServiceAsh>(std::move(receiver));
keystore_service_ash_->BindReceiver(std::move(receiver));
}
void AshChromeServiceImpl::BindMessageCenter(
mojo::PendingReceiver<mojom::MessageCenter> receiver) {
// TODO(https://crbug.com/1148448): Convert this to allow multiple,
// simultaneous crosapi clients. See BindScreenManager for an example.
message_center_ash_ = std::make_unique<MessageCenterAsh>(std::move(receiver));
message_center_ash_->BindReceiver(std::move(receiver));
}
void AshChromeServiceImpl::BindMetricsReporting(
......@@ -126,9 +123,7 @@ void AshChromeServiceImpl::BindMetricsReporting(
void AshChromeServiceImpl::BindSelectFile(
mojo::PendingReceiver<mojom::SelectFile> receiver) {
// TODO(https://crbug.com/1148448): Convert this to allow multiple,
// simultaneous crosapi clients. See BindScreenManager for an example.
select_file_ash_ = std::make_unique<SelectFileAsh>(std::move(receiver));
select_file_ash_->BindReceiver(std::move(receiver));
}
void AshChromeServiceImpl::BindScreenManager(
......@@ -143,9 +138,7 @@ void AshChromeServiceImpl::BindHidManager(
void AshChromeServiceImpl::BindFeedback(
mojo::PendingReceiver<mojom::Feedback> receiver) {
// TODO(https://crbug.com/1148448): Convert this to allow multiple,
// simultaneous crosapi clients. See BindScreenManager for an example.
feedback_ash_ = std::make_unique<FeedbackAsh>(std::move(receiver));
feedback_ash_->BindReceiver(std::move(receiver));
}
void AshChromeServiceImpl::BindMediaSessionController(
......
......@@ -23,11 +23,15 @@ chrome::FeedbackSource FromMojo(mojom::LacrosFeedbackSource source) {
} // namespace
FeedbackAsh::FeedbackAsh(mojo::PendingReceiver<mojom::Feedback> receiver)
: receiver_(this, std::move(receiver)) {}
FeedbackAsh::FeedbackAsh() = default;
FeedbackAsh::~FeedbackAsh() = default;
void FeedbackAsh::BindReceiver(
mojo::PendingReceiver<mojom::Feedback> receiver) {
receivers_.Add(this, std::move(receiver));
}
void FeedbackAsh::ShowFeedbackPage(mojom::FeedbackInfoPtr feedback_info) {
const user_manager::User* user =
user_manager::UserManager::Get()->GetPrimaryUser();
......
......@@ -7,7 +7,7 @@
#include "chromeos/crosapi/mojom/feedback.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace crosapi {
......@@ -15,16 +15,18 @@ namespace crosapi {
// UI thread. Shows feedback page in response to mojo IPCs from lacros-chrome.
class FeedbackAsh : public mojom::Feedback {
public:
explicit FeedbackAsh(mojo::PendingReceiver<mojom::Feedback> receiver);
FeedbackAsh();
FeedbackAsh(const FeedbackAsh&) = delete;
FeedbackAsh& operator=(const FeedbackAsh&) = delete;
~FeedbackAsh() override;
void BindReceiver(mojo::PendingReceiver<mojom::Feedback> receiver);
// crosapi::mojom::Feedback:
void ShowFeedbackPage(mojom::FeedbackInfoPtr feedback_info) override;
private:
mojo::Receiver<mojom::Feedback> receiver_;
mojo::ReceiverSet<mojom::Feedback> receivers_;
};
} // namespace crosapi
......
......@@ -67,12 +67,15 @@ void OpenItem(const base::FilePath& path,
} // namespace
FileManagerAsh::FileManagerAsh(
mojo::PendingReceiver<mojom::FileManager> receiver)
: receiver_(this, std::move(receiver)) {}
FileManagerAsh::FileManagerAsh() = default;
FileManagerAsh::~FileManagerAsh() = default;
void FileManagerAsh::BindReceiver(
mojo::PendingReceiver<mojom::FileManager> receiver) {
receivers_.Add(this, std::move(receiver));
}
void FileManagerAsh::DeprecatedShowItemInFolder(const base::FilePath& path) {
Profile* primary_profile = ProfileManager::GetPrimaryUserProfile();
base::FilePath final_path = ExpandPath(primary_profile, path);
......
......@@ -7,7 +7,7 @@
#include "chromeos/crosapi/mojom/file_manager.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace crosapi {
......@@ -16,11 +16,13 @@ namespace crosapi {
// manager, for example to open a folder or highlight a file.
class FileManagerAsh : public mojom::FileManager {
public:
explicit FileManagerAsh(mojo::PendingReceiver<mojom::FileManager> receiver);
FileManagerAsh();
FileManagerAsh(const FileManagerAsh&) = delete;
FileManagerAsh& operator=(const FileManagerAsh&) = delete;
~FileManagerAsh() override;
void BindReceiver(mojo::PendingReceiver<mojom::FileManager> receiver);
// crosapi::mojom::FileManager:
void DeprecatedShowItemInFolder(const base::FilePath& path) override;
void ShowItemInFolder(const base::FilePath& path,
......@@ -30,7 +32,7 @@ class FileManagerAsh : public mojom::FileManager {
void OpenFile(const base::FilePath& path, OpenFileCallback callback) override;
private:
mojo::Receiver<mojom::FileManager> receiver_;
mojo::ReceiverSet<mojom::FileManager> receivers_;
};
} // namespace crosapi
......
......@@ -62,9 +62,7 @@ base::Optional<TokenId> KeystoreToToken(mojom::KeystoreType type) {
} // namespace
KeystoreServiceAsh::KeystoreServiceAsh(
mojo::PendingReceiver<mojom::KeystoreService> receiver)
: receiver_(this, std::move(receiver)) {
KeystoreServiceAsh::KeystoreServiceAsh() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
}
......@@ -72,6 +70,11 @@ KeystoreServiceAsh::~KeystoreServiceAsh() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
}
void KeystoreServiceAsh::BindReceiver(
mojo::PendingReceiver<mojom::KeystoreService> receiver) {
receivers_.Add(this, std::move(receiver));
}
void KeystoreServiceAsh::ChallengeAttestationOnlyKeystore(
const std::string& challenge,
mojom::KeystoreType type,
......
......@@ -12,7 +12,7 @@
#include "chrome/browser/chromeos/platform_keys/platform_keys.h"
#include "chromeos/crosapi/mojom/keystore_service.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace chromeos {
namespace attestation {
......@@ -28,12 +28,13 @@ namespace crosapi {
// system keystores. This class is affine to the UI thread.
class KeystoreServiceAsh : public mojom::KeystoreService {
public:
explicit KeystoreServiceAsh(
mojo::PendingReceiver<mojom::KeystoreService> receiver);
KeystoreServiceAsh();
KeystoreServiceAsh(const KeystoreServiceAsh&) = delete;
KeystoreServiceAsh& operator=(const KeystoreServiceAsh&) = delete;
~KeystoreServiceAsh() override;
void BindReceiver(mojo::PendingReceiver<mojom::KeystoreService> receiver);
// mojom::KeystoreService:
using KeystoreType = mojom::KeystoreType;
void ChallengeAttestationOnlyKeystore(
......@@ -81,7 +82,7 @@ class KeystoreServiceAsh : public mojom::KeystoreService {
// Container to keep outstanding challenges alive.
std::vector<std::unique_ptr<chromeos::attestation::TpmChallengeKey>>
outstanding_challenges_;
mojo::Receiver<mojom::KeystoreService> receiver_;
mojo::ReceiverSet<mojom::KeystoreService> receivers_;
base::WeakPtrFactory<KeystoreServiceAsh> weak_factory_{this};
};
......
......@@ -156,12 +156,15 @@ class ForwardingDelegate : public message_center::NotificationDelegate {
} // namespace
MessageCenterAsh::MessageCenterAsh(
mojo::PendingReceiver<mojom::MessageCenter> receiver)
: receiver_(this, std::move(receiver)) {}
MessageCenterAsh::MessageCenterAsh() = default;
MessageCenterAsh::~MessageCenterAsh() = default;
void MessageCenterAsh::BindReceiver(
mojo::PendingReceiver<mojom::MessageCenter> receiver) {
receivers_.Add(this, std::move(receiver));
}
void MessageCenterAsh::DisplayNotification(
mojom::NotificationPtr notification,
mojo::PendingRemote<mojom::NotificationDelegate> delegate) {
......
......@@ -7,7 +7,7 @@
#include "chromeos/crosapi/mojom/message_center.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace crosapi {
......@@ -16,12 +16,13 @@ namespace crosapi {
// Sends reply IPCs when the user interacts with the notifications.
class MessageCenterAsh : public mojom::MessageCenter {
public:
explicit MessageCenterAsh(
mojo::PendingReceiver<mojom::MessageCenter> receiver);
MessageCenterAsh();
MessageCenterAsh(const MessageCenterAsh&) = delete;
MessageCenterAsh& operator=(const MessageCenterAsh&) = delete;
~MessageCenterAsh() override;
void BindReceiver(mojo::PendingReceiver<mojom::MessageCenter> receiver);
// crosapi::mojom::MessageCenter:
void DisplayNotification(
mojom::NotificationPtr notification,
......@@ -31,7 +32,7 @@ class MessageCenterAsh : public mojom::MessageCenter {
GetDisplayedNotificationsCallback callback) override;
private:
mojo::Receiver<mojom::MessageCenter> receiver_;
mojo::ReceiverSet<mojom::MessageCenter> receivers_;
};
} // namespace crosapi
......
......@@ -84,7 +84,8 @@ class MessageCenterAshTest : public testing::Test {
// testing::Test:
void SetUp() override {
message_center::MessageCenter::Initialize();
message_center_ash_ = std::make_unique<MessageCenterAsh>(
message_center_ash_ = std::make_unique<MessageCenterAsh>();
message_center_ash_->BindReceiver(
message_center_remote_.BindNewPipeAndPassReceiver());
}
......
......@@ -167,12 +167,15 @@ class SelectFileDialogHolder : public ui::SelectFileDialog::Listener {
} // namespace
// TODO(https://crbug.com/1090587): Connection error handling.
SelectFileAsh::SelectFileAsh(mojo::PendingReceiver<mojom::SelectFile> receiver)
: receiver_(this, std::move(receiver)) {}
SelectFileAsh::SelectFileAsh() = default;
SelectFileAsh::~SelectFileAsh() = default;
void SelectFileAsh::BindReceiver(
mojo::PendingReceiver<mojom::SelectFile> receiver) {
receivers_.Add(this, std::move(receiver));
}
void SelectFileAsh::Select(mojom::SelectFileOptionsPtr options,
SelectCallback callback) {
aura::Window* owner_window = nullptr;
......
......@@ -7,7 +7,7 @@
#include "chromeos/crosapi/mojom/select_file.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace crosapi {
......@@ -16,17 +16,19 @@ namespace crosapi {
// file manager to provide the dialogs. Lives on the UI thread.
class SelectFileAsh : public mojom::SelectFile {
public:
explicit SelectFileAsh(mojo::PendingReceiver<mojom::SelectFile> receiver);
SelectFileAsh();
SelectFileAsh(const SelectFileAsh&) = delete;
SelectFileAsh& operator=(const SelectFileAsh&) = delete;
~SelectFileAsh() override;
void BindReceiver(mojo::PendingReceiver<mojom::SelectFile> receiver);
// crosapi::mojom::SelectFile:
void Select(mojom::SelectFileOptionsPtr options,
SelectCallback callback) override;
private:
mojo::Receiver<mojom::SelectFile> receiver_;
mojo::ReceiverSet<mojom::SelectFile> receivers_;
};
} // namespace crosapi
......
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