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