Commit d2efb8a3 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert IdentityAccessor to new Mojo types

This CL converts IdentityAccessorPtr and BindingSet<IdentityAccessor>
in chromeos and services to the new Mojo type.

Bug: 955171
Change-Id: Icb122470713bd84a6718483853f50aff45df1b8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1810449Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#698654}
parent 11e14a7c
......@@ -52,7 +52,7 @@ void DriveFsAuth::GetAccessToken(
timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(30),
base::BindOnce(&DriveFsAuth::AuthTimeout,
weak_ptr_factory_.GetWeakPtr()));
GetIdentityAccessor().GetPrimaryAccountWhenAvailable(base::BindOnce(
GetIdentityAccessor()->GetPrimaryAccountWhenAvailable(base::BindOnce(
&DriveFsAuth::AccountReady, weak_ptr_factory_.GetWeakPtr()));
}
......@@ -63,7 +63,7 @@ void DriveFsAuth::AccountReady(const CoreAccountId& account_id,
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
weak_ptr_factory_.InvalidateWeakPtrs();
timer_->Stop();
GetIdentityAccessor().GetAccessToken(
GetIdentityAccessor()->GetAccessToken(
account_id, {"https://www.googleapis.com/auth/drive"},
kIdentityConsumerId,
base::BindOnce(&DriveFsAuth::GotChromeAccessToken,
......@@ -108,11 +108,13 @@ void DriveFsAuth::AuthTimeout() {
.Run(mojom::AccessTokenStatus::kAuthError, "");
}
identity::mojom::IdentityAccessor& DriveFsAuth::GetIdentityAccessor() {
identity::mojom::IdentityAccessor* DriveFsAuth::GetIdentityAccessor() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!identity_accessor_)
delegate_->BindIdentityAccessor(mojo::MakeRequest(&identity_accessor_));
return *identity_accessor_;
if (!identity_accessor_) {
delegate_->BindIdentityAccessor(
identity_accessor_.BindNewPipeAndPassReceiver());
}
return identity_accessor_.get();
}
} // namespace drivefs
......@@ -16,6 +16,7 @@
#include "base/timer/timer.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/identity/public/mojom/identity_accessor.mojom.h"
class AccountId;
......@@ -85,7 +86,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsAuth {
void AuthTimeout();
identity::mojom::IdentityAccessor& GetIdentityAccessor();
identity::mojom::IdentityAccessor* GetIdentityAccessor();
SEQUENCE_CHECKER(sequence_checker_);
const base::Clock* const clock_;
......@@ -94,7 +95,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsAuth {
Delegate* const delegate_;
// The connection to the identity service. Access via |GetIdentityAccessor()|.
identity::mojom::IdentityAccessorPtr identity_accessor_;
mojo::Remote<identity::mojom::IdentityAccessor> identity_accessor_;
// Pending callback for an in-flight GetAccessToken request.
mojom::DriveFsDelegate::GetAccessTokenCallback get_access_token_callback_;
......
......@@ -13,7 +13,7 @@
#include "base/test/task_environment.h"
#include "base/timer/mock_timer.h"
#include "components/account_id/account_id.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/identity/public/mojom/identity_accessor.mojom-test-utils.h"
#include "services/identity/public/mojom/identity_service.mojom.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
......@@ -66,7 +66,7 @@ class MockIdentityAccessor {
const ::identity::ScopeSet& scopes,
const std::string& consumer_id));
mojo::BindingSet<identity::mojom::IdentityAccessor>* bindings_ = nullptr;
mojo::ReceiverSet<identity::mojom::IdentityAccessor>* receivers_ = nullptr;
};
class FakeIdentityService
......@@ -76,10 +76,10 @@ class FakeIdentityService
explicit FakeIdentityService(MockIdentityAccessor* mock,
const base::Clock* clock)
: mock_(mock), clock_(clock) {
mock_->bindings_ = &bindings_;
mock_->receivers_ = &receivers_;
}
~FakeIdentityService() override { mock_->bindings_ = nullptr; }
~FakeIdentityService() override { mock_->receivers_ = nullptr; }
void set_auth_enabled(bool enabled) { auth_enabled_ = enabled; }
......@@ -88,7 +88,7 @@ class FakeIdentityService
void BindIdentityAccessor(
mojo::PendingReceiver<identity::mojom::IdentityAccessor> receiver)
override {
bindings_.AddBinding(this, std::move(receiver));
receivers_.Add(this, std::move(receiver));
}
// identity::mojom::IdentityAccessorInterceptorForTesting overrides:
......@@ -120,7 +120,7 @@ class FakeIdentityService
MockIdentityAccessor* const mock_;
const base::Clock* const clock_;
mojo::BindingSet<identity::mojom::IdentityAccessor> bindings_;
mojo::ReceiverSet<identity::mojom::IdentityAccessor> receivers_;
bool auth_enabled_ = true;
DISALLOW_COPY_AND_ASSIGN(FakeIdentityService);
......
......@@ -27,7 +27,7 @@
#include "components/drive/drive_notification_observer.h"
#include "components/invalidation/impl/fake_invalidation_service.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/identity/public/mojom/identity_accessor.mojom-test-utils.h"
#include "services/identity/public/mojom/identity_service.mojom.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
......@@ -190,7 +190,7 @@ class MockIdentityAccessor {
bool pause_requests_ = false;
std::vector<identity::mojom::IdentityAccessor::GetAccessTokenCallback>
callbacks_;
mojo::BindingSet<identity::mojom::IdentityAccessor>* bindings_ = nullptr;
mojo::ReceiverSet<identity::mojom::IdentityAccessor>* receivers_ = nullptr;
};
class FakeIdentityService
......@@ -198,17 +198,17 @@ class FakeIdentityService
public identity::mojom::IdentityService {
public:
explicit FakeIdentityService(MockIdentityAccessor* mock) : mock_(mock) {
mock_->bindings_ = &bindings_;
mock_->receivers_ = &receivers_;
}
~FakeIdentityService() override { mock_->bindings_ = nullptr; }
~FakeIdentityService() override { mock_->receivers_ = nullptr; }
private:
// identity::mojom::IdentityService:
void BindIdentityAccessor(
mojo::PendingReceiver<identity::mojom::IdentityAccessor> receiver)
override {
bindings_.AddBinding(this, std::move(receiver));
receivers_.Add(this, std::move(receiver));
}
// identity::mojom::IdentityAccessorInterceptorForTesting overrides:
......@@ -234,7 +234,7 @@ class FakeIdentityService
}
MockIdentityAccessor* const mock_;
mojo::BindingSet<identity::mojom::IdentityAccessor> bindings_;
mojo::ReceiverSet<identity::mojom::IdentityAccessor> receivers_;
DISALLOW_COPY_AND_ASSIGN(FakeIdentityService);
};
......@@ -544,8 +544,8 @@ TEST_F(DriveFsHostTest, GetAccessToken_UnmountDuringMojoRequest) {
run_loop.Run();
EXPECT_FALSE(host_->IsMounted());
// Wait for the response to reach the InterfacePtr if it's still open.
mock_identity_accessor_.bindings_->FlushForTesting();
// Wait for the response to reach the remote if it's still open.
mock_identity_accessor_.receivers_->FlushForTesting();
}
ACTION_P(CloneStruct, output) {
......@@ -748,7 +748,7 @@ TEST_F(DriveFsHostTest, Remount_RequestInflight) {
std::move(mock_identity_accessor_.callbacks().front())
.Run("auth token", clock_.Now() + base::TimeDelta::FromHours(1),
GoogleServiceAuthError(GoogleServiceAuthError::NONE));
mock_identity_accessor_.bindings_->FlushForTesting();
mock_identity_accessor_.receivers_->FlushForTesting();
// Second mount will reuse previous token.
ASSERT_NO_FATAL_FAILURE(DoMount());
......@@ -779,7 +779,7 @@ TEST_F(DriveFsHostTest, Remount_RequestInflightCompleteAfterMount) {
std::move(mock_identity_accessor_.callbacks().front())
.Run("auth token", clock_.Now() + base::TimeDelta::FromHours(1),
GoogleServiceAuthError(GoogleServiceAuthError::NONE));
mock_identity_accessor_.bindings_->FlushForTesting();
mock_identity_accessor_.receivers_->FlushForTesting();
// A new request will reuse the cached token.
ExpectAccessToken(mojom::AccessTokenStatus::kSuccess, "auth token");
......
......@@ -150,8 +150,8 @@ void Service::OverrideSettingsManagerForTesting(
}
void Service::SetIdentityAccessorForTesting(
identity::mojom::IdentityAccessorPtr identity_accessor) {
identity_accessor_ = std::move(identity_accessor);
mojo::PendingRemote<identity::mojom::IdentityAccessor> identity_accessor) {
identity_accessor_.Bind(std::move(identity_accessor));
}
void Service::SetTimerForTesting(std::unique_ptr<base::OneShotTimer> timer) {
......@@ -341,7 +341,8 @@ void Service::UpdateAssistantManagerState() {
identity::mojom::IdentityAccessor* Service::GetIdentityAccessor() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!identity_accessor_)
client_->RequestIdentityAccessor(mojo::MakeRequest(&identity_accessor_));
client_->RequestIdentityAccessor(
identity_accessor_.BindNewPipeAndPassReceiver());
return identity_accessor_.get();
}
......
......@@ -27,6 +27,7 @@
#include "components/account_id/account_id.h"
#include "components/prefs/pref_registry_simple.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
......@@ -78,7 +79,7 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service
AssistantSettingsManager* manager);
void SetIdentityAccessorForTesting(
identity::mojom::IdentityAccessorPtr identity_accessor);
mojo::PendingRemote<identity::mojom::IdentityAccessor> identity_accessor);
void SetTimerForTesting(std::unique_ptr<base::OneShotTimer> timer);
......@@ -160,7 +161,7 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) Service
mojo::Remote<mojom::Client> client_;
mojo::Remote<mojom::DeviceActions> device_actions_;
identity::mojom::IdentityAccessorPtr identity_accessor_;
mojo::Remote<identity::mojom::IdentityAccessor> identity_accessor_;
AccountId account_id_;
std::unique_ptr<AssistantManagerService> assistant_manager_service_;
......
......@@ -70,13 +70,11 @@ class FakePrefConnectionDelegate : public PrefConnectionDelegate {
class FakeIdentityAccessor : identity::mojom::IdentityAccessor {
public:
FakeIdentityAccessor()
: binding_(this),
access_token_expriation_delay_(kDefaultTokenExpirationDelay) {}
: access_token_expriation_delay_(kDefaultTokenExpirationDelay) {}
identity::mojom::IdentityAccessorPtr CreateInterfacePtrAndBind() {
identity::mojom::IdentityAccessorPtr ptr;
binding_.Bind(mojo::MakeRequest(&ptr));
return ptr;
mojo::PendingRemote<identity::mojom::IdentityAccessor>
CreatePendingRemoteAndBind() {
return receiver_.BindNewPipeAndPassRemote();
}
void SetAccessTokenExpirationDelay(base::TimeDelta delay) {
......@@ -117,7 +115,7 @@ class FakeIdentityAccessor : identity::mojom::IdentityAccessor {
++get_access_token_count_;
}
mojo::Binding<identity::mojom::IdentityAccessor> binding_;
mojo::Receiver<identity::mojom::IdentityAccessor> receiver_{this};
base::TimeDelta access_token_expriation_delay_;
......@@ -133,7 +131,7 @@ class FakeAssistantClient : public FakeClient {
explicit FakeAssistantClient(ash::AssistantState* assistant_state)
: assistant_state_(assistant_state) {}
mojom::ClientPtr CreateInterfacePtrAndBind() {
mojom::ClientPtr CreatePendingRemoteAndBind() {
mojom::ClientPtr ptr;
binding_.Bind(mojo::MakeRequest(&ptr));
return ptr;
......@@ -230,7 +228,7 @@ class AssistantServiceTest : public testing::Test {
service_->SetTimerForTesting(std::move(mock_timer));
service_->SetIdentityAccessorForTesting(
fake_identity_accessor_.CreateInterfacePtrAndBind());
fake_identity_accessor_.CreatePendingRemoteAndBind());
remote_service_->Init(fake_assistant_client_.MakeRemote(),
fake_device_actions_.CreatePendingRemoteAndBind(),
......
......@@ -11,6 +11,7 @@
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "google_apis/gaia/core_account_id.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/identity/identity_service.h"
#include "services/identity/public/cpp/account_state.h"
#include "services/identity/public/cpp/scope_set.h"
......@@ -87,7 +88,7 @@ class IdentityAccessorImplTest : public testing::Test {
mojom::IdentityAccessor* GetIdentityAccessorImpl() {
if (!identity_accessor_) {
remote_service_->BindIdentityAccessor(
mojo::MakeRequest(&identity_accessor_));
identity_accessor_.BindNewPipeAndPassReceiver());
}
return identity_accessor_.get();
}
......@@ -102,12 +103,12 @@ class IdentityAccessorImplTest : public testing::Test {
void SetIdentityAccessorImplConnectionErrorHandler(
base::RepeatingClosure handler) {
GetIdentityAccessorImpl();
identity_accessor_.set_connection_error_handler(handler);
identity_accessor_.set_disconnect_handler(handler);
}
base::test::TaskEnvironment task_environemnt_;
mojom::IdentityAccessorPtr identity_accessor_;
mojo::Remote<mojom::IdentityAccessor> identity_accessor_;
base::Optional<CoreAccountInfo> primary_account_info_;
AccountState primary_account_state_;
base::Optional<CoreAccountInfo> account_info_from_gaia_id_;
......
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