Skip to content

Commit

Permalink
Support multiple receivers for Cros APIs.
Browse files Browse the repository at this point in the history
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/+/2624323
Reviewed-by: James Cook <[email protected]>
Commit-Queue: Hidehiko Abe <[email protected]>
Cr-Commit-Position: refs/heads/master@{#842869}
  • Loading branch information
Hidehiko Abe authored and Chromium LUCI CQ committed Jan 13, 2021
1 parent f03d4a9 commit 8aca3b4
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 49 deletions.
27 changes: 10 additions & 17 deletions chrome/browser/chromeos/crosapi/ash_chrome_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>()) {
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions chrome/browser/chromeos/crosapi/feedback_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions chrome/browser/chromeos/crosapi/feedback_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@

#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 {

// Implements the crosapi feedback interface. Lives in ash-chrome on the
// 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
Expand Down
9 changes: 6 additions & 3 deletions chrome/browser/chromeos/crosapi/file_manager_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions chrome/browser/chromeos/crosapi/file_manager_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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,
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions chrome/browser/chromeos/crosapi/keystore_service_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ 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);
}

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,
Expand Down
9 changes: 5 additions & 4 deletions chrome/browser/chromeos/crosapi/keystore_service_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(
Expand Down Expand Up @@ -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};
};
Expand Down
9 changes: 6 additions & 3 deletions chrome/browser/chromeos/crosapi/message_center_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions chrome/browser/chromeos/crosapi/message_center_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
9 changes: 6 additions & 3 deletions chrome/browser/chromeos/crosapi/select_file_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions chrome/browser/chromeos/crosapi/select_file_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand Down

0 comments on commit 8aca3b4

Please sign in to comment.