diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-11-28 16:14:41 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-12-13 15:19:41 +0000 |
commit | 61d9742824d54be5693191fe502325a909feca59 (patch) | |
tree | cbf28e779b11338fe52eb75b915684cd8955542c /chromium/components/account_manager_core/chromeos | |
parent | 45f9ded08bb7526984b24ccb5a5327aaf6821676 (diff) | |
download | qtwebengine-chromium-61d9742824d54be5693191fe502325a909feca59.tar.gz |
BASELINE: Update Chromium to 108.0.5359.70
Change-Id: I77334ff232b819600f275bd3cfe41fbaa3619230
Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/445904
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/account_manager_core/chromeos')
15 files changed, 166 insertions, 51 deletions
diff --git a/chromium/components/account_manager_core/chromeos/access_token_fetcher.cc b/chromium/components/account_manager_core/chromeos/access_token_fetcher.cc index 5671b4ef3ae..bcc574c44f6 100644 --- a/chromium/components/account_manager_core/chromeos/access_token_fetcher.cc +++ b/chromium/components/account_manager_core/chromeos/access_token_fetcher.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/components/account_manager_core/chromeos/access_token_fetcher.h b/chromium/components/account_manager_core/chromeos/access_token_fetcher.h index 5a65db087a4..8390aa33e47 100644 --- a/chromium/components/account_manager_core/chromeos/access_token_fetcher.h +++ b/chromium/components/account_manager_core/chromeos/access_token_fetcher.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/components/account_manager_core/chromeos/account_manager.cc b/chromium/components/account_manager_core/chromeos/account_manager.cc index 1abcb26ef0c..b10b42a1ddd 100644 --- a/chromium/components/account_manager_core/chromeos/account_manager.cc +++ b/chromium/components/account_manager_core/chromeos/account_manager.cc @@ -1,10 +1,9 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/account_manager_core/chromeos/account_manager.h" -#include <algorithm> #include <memory> #include <string> #include <utility> @@ -20,6 +19,7 @@ #include "base/memory/weak_ptr.h" #include "base/metrics/histogram_functions.h" #include "base/notreached.h" +#include "base/ranges/algorithm.h" #include "base/task/sequenced_task_runner.h" #include "base/task/task_runner_util.h" #include "base/task/thread_pool.h" @@ -797,12 +797,9 @@ void AccountManager::DeletePendingTokenRevocationRequest( GaiaTokenRevocationRequest* request) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - auto it = std::find_if( - pending_token_revocation_requests_.begin(), - pending_token_revocation_requests_.end(), - [&request]( - const std::unique_ptr<GaiaTokenRevocationRequest>& pending_request) - -> bool { return pending_request.get() == request; }); + auto it = + base::ranges::find(pending_token_revocation_requests_, request, + &std::unique_ptr<GaiaTokenRevocationRequest>::get); if (it != pending_token_revocation_requests_.end()) { pending_token_revocation_requests_.erase(it); diff --git a/chromium/components/account_manager_core/chromeos/account_manager.h b/chromium/components/account_manager_core/chromeos/account_manager.h index ebb2d84c9a2..6fa111c2286 100644 --- a/chromium/components/account_manager_core/chromeos/account_manager.h +++ b/chromium/components/account_manager_core/chromeos/account_manager.h @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/components/account_manager_core/chromeos/account_manager_facade_factory.h b/chromium/components/account_manager_core/chromeos/account_manager_facade_factory.h index c205159bd23..cc0e3c2c700 100644 --- a/chromium/components/account_manager_core/chromeos/account_manager_facade_factory.h +++ b/chromium/components/account_manager_core/chromeos/account_manager_facade_factory.h @@ -1,10 +1,11 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_ACCOUNT_MANAGER_CORE_CHROMEOS_ACCOUNT_MANAGER_FACADE_FACTORY_H_ #define COMPONENTS_ACCOUNT_MANAGER_CORE_CHROMEOS_ACCOUNT_MANAGER_FACADE_FACTORY_H_ +#include <memory> #include <string> #include "base/compiler_specific.h" diff --git a/chromium/components/account_manager_core/chromeos/account_manager_facade_factory_lacros.cc b/chromium/components/account_manager_core/chromeos/account_manager_facade_factory_lacros.cc index bb1d5a1fd3f..dafab84582f 100644 --- a/chromium/components/account_manager_core/chromeos/account_manager_facade_factory_lacros.cc +++ b/chromium/components/account_manager_core/chromeos/account_manager_facade_factory_lacros.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/components/account_manager_core/chromeos/account_manager_mojo_service.cc b/chromium/components/account_manager_core/chromeos/account_manager_mojo_service.cc index d17593308a6..71b3bec0221 100644 --- a/chromium/components/account_manager_core/chromeos/account_manager_mojo_service.cc +++ b/chromium/components/account_manager_core/chromeos/account_manager_mojo_service.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,9 +11,9 @@ #include "base/bind.h" #include "base/callback.h" #include "base/callback_forward.h" +#include "base/containers/contains.h" #include "base/logging.h" #include "base/memory/weak_ptr.h" -#include "base/notreached.h" #include "chromeos/crosapi/mojom/account_manager.mojom.h" #include "components/account_manager_core/account.h" #include "components/account_manager_core/account_addition_result.h" @@ -21,6 +21,7 @@ #include "components/account_manager_core/chromeos/access_token_fetcher.h" #include "components/account_manager_core/chromeos/account_manager.h" #include "components/account_manager_core/chromeos/account_manager_ui.h" +#include "google_apis/gaia/google_service_auth_error.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/remote.h" #include "third_party/abseil-cpp/absl/types/optional.h" @@ -51,21 +52,6 @@ void ReportErrorStatusFromHasDummyGaiaToken( std::move(callback).Run(account_manager::ToMojoGoogleServiceAuthError(error)); } -#if DCHECK_IS_ON() -void VerifyThatAccountExists( - const account_manager::AccountKey& account_key, - const std::vector<account_manager::Account>& known_accounts) { - bool account_exists = false; - for (const account_manager::Account& known_account : known_accounts) { - if (known_account.key == account_key) { - account_exists = true; - break; - } - } - DCHECK(account_exists); -} -#endif // DCHECK_IS_ON() - } // namespace AccountManagerMojoService::AccountManagerMojoService( @@ -153,7 +139,18 @@ void AccountManagerMojoService::ShowReauthAccountDialog( if (account_manager_ui_->IsDialogShown()) return; - account_manager_ui_->ShowReauthAccountDialog(email, std::move(closure)); + // `closure` is used by the entity which launched the account + // re-authentication flow in the first place to know about the completion of + // the flow. The notification that we are going to chain here will inform all + // observers of `AccountManagerFacade` (see + // `AccountManagerFacade::Observer::OnSigninDialogClosed()`), that the signin + // dialog was closed. + // As of this writing, this notification is used by `AccountReconcilor` to + // force mint cookies. + account_manager_ui_->ShowReauthAccountDialog( + email, std::move(closure).Then(base::BindOnce( + &AccountManagerMojoService::NotifySigninDialogClosed, + weak_ptr_factory_.GetWeakPtr()))); } void AccountManagerMojoService::ShowManageAccountsSettings() { @@ -182,20 +179,32 @@ void AccountManagerMojoService::CreateAccessTokenFetcher( void AccountManagerMojoService::ReportAuthError( mojom::AccountKeyPtr mojo_account_key, - mojom::GoogleServiceAuthErrorPtr error) { + mojom::GoogleServiceAuthErrorPtr mojo_error) { absl::optional<account_manager::AccountKey> maybe_account_key = account_manager::FromMojoAccountKey(mojo_account_key); DCHECK(maybe_account_key) << "Can't unmarshal account of type: " << mojo_account_key->account_type; -#if DCHECK_IS_ON() - // Verify that `maybe_account_key` is known to Account Manager. - account_manager_->GetAccounts( - base::BindOnce(&VerifyThatAccountExists, maybe_account_key.value())); -#endif // DCHECK_IS_ON() + absl::optional<GoogleServiceAuthError> maybe_error = + account_manager::FromMojoGoogleServiceAuthError(mojo_error); + if (!maybe_error.has_value()) { + // Newer version of Lacros may have reported an error that older version of + // Ash doesn't understand yet. Ignore such errors. + LOG(ERROR) << "Can't unmarshal error with state: " << mojo_error->state; + return; + } - for (auto& observer : observers_) - observer->OnAuthErrorChanged(mojo_account_key.Clone(), error.Clone()); + const GoogleServiceAuthError& error = maybe_error.value(); + if (error.IsTransientError()) { + // Silently ignore transient errors reported by apps to avoid polluting + // other apps' error caches with transient errors like + // `GoogleServiceAuthError::CONNECTION_FAILED`. + return; + } + + account_manager_->GetAccounts(base::BindOnce( + &AccountManagerMojoService::MaybeNotifyAuthErrorObservers, + weak_ptr_factory_.GetWeakPtr(), maybe_account_key.value(), error)); } void AccountManagerMojoService::OnTokenUpserted( @@ -235,6 +244,7 @@ void AccountManagerMojoService::FinishAddAccount( DCHECK(!account_addition_callback_.is_null()); std::move(account_addition_callback_) .Run(ToMojoAccountAdditionResult(result)); + NotifySigninDialogClosed(); } void AccountManagerMojoService::DeletePendingAccessTokenFetchRequest( @@ -248,6 +258,31 @@ void AccountManagerMojoService::DeletePendingAccessTokenFetchRequest( pending_access_token_requests_.end()); } +void AccountManagerMojoService::MaybeNotifyAuthErrorObservers( + const account_manager::AccountKey& account_key, + const GoogleServiceAuthError& error, + const std::vector<account_manager::Account>& known_accounts) { + if (!base::Contains(known_accounts, account_key, + [](const account_manager::Account& account) { + return account.key; + })) { + // Ignore if the account is not known. + return; + } + + for (auto& observer : observers_) { + observer->OnAuthErrorChanged( + account_manager::ToMojoAccountKey(account_key), + account_manager::ToMojoGoogleServiceAuthError(error)); + } +} + +void AccountManagerMojoService::NotifySigninDialogClosed() { + for (auto& observer : observers_) { + observer->OnSigninDialogClosed(); + } +} + void AccountManagerMojoService::FlushMojoForTesting() { observers_.FlushForTesting(); } diff --git a/chromium/components/account_manager_core/chromeos/account_manager_mojo_service.h b/chromium/components/account_manager_core/chromeos/account_manager_mojo_service.h index f137036f288..0a7b9a134c0 100644 --- a/chromium/components/account_manager_core/chromeos/account_manager_mojo_service.h +++ b/chromium/components/account_manager_core/chromeos/account_manager_mojo_service.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -19,7 +19,6 @@ #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/receiver_set.h" #include "mojo/public/cpp/bindings/remote_set.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace chromeos { class SigninHelper; @@ -88,6 +87,18 @@ class COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) AccountManagerMojoService // Deletes `request` from `pending_access_token_requests_`, if present. void DeletePendingAccessTokenFetchRequest(AccessTokenFetcher* request); + // Notifies observers about a change in the error status of `account_key`. + // Does nothing if `account_key` does not correspond to any account in + // `known_accounts`. + void MaybeNotifyAuthErrorObservers( + const account_manager::AccountKey& account_key, + const GoogleServiceAuthError& error, + const std::vector<account_manager::Account>& known_accounts); + + // Notifies observers that the account addition / re-authentication dialog was + // closed (either successfully, or the user cancelled the flow). + void NotifySigninDialogClosed(); + void FlushMojoForTesting(); int GetNumPendingAccessTokenRequests() const; diff --git a/chromium/components/account_manager_core/chromeos/account_manager_mojo_service_unittest.cc b/chromium/components/account_manager_core/chromeos/account_manager_mojo_service_unittest.cc index 6d94628f1d9..3bf505a20f2 100644 --- a/chromium/components/account_manager_core/chromeos/account_manager_mojo_service_unittest.cc +++ b/chromium/components/account_manager_core/chromeos/account_manager_mojo_service_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,7 +11,6 @@ #include <vector> #include "base/bind.h" -#include "base/callback_helpers.h" #include "base/run_loop.h" #include "base/test/bind.h" #include "base/test/task_environment.h" @@ -19,7 +18,6 @@ #include "chromeos/crosapi/mojom/account_manager.mojom.h" #include "components/account_manager_core/account.h" #include "components/account_manager_core/account_manager_util.h" -#include "components/account_manager_core/chromeos/access_token_fetcher.h" #include "components/account_manager_core/chromeos/account_manager.h" #include "components/account_manager_core/chromeos/account_manager_ui.h" #include "components/account_manager_core/chromeos/fake_account_manager_ui.h" @@ -95,6 +93,10 @@ class TestAccountManagerObserver return std::make_pair(last_err_account_.value(), last_error_.value()); } + int GetNumSigninDialogClosedNotifications() const { + return num_signin_dialog_closed_notifications_; + } + private: // mojom::AccountManagerObserverInterceptorForTesting override: AccountManagerObserver* GetForwardingInterface() override { return this; } @@ -119,9 +121,15 @@ class TestAccountManagerObserver last_error_ = account_manager::FromMojoGoogleServiceAuthError(error); } + // mojom::AccountManagerObserverInterceptorForTesting override: + void OnSigninDialogClosed() override { + ++num_signin_dialog_closed_notifications_; + } + int num_token_upserted_calls_ = 0; int num_account_removed_calls_ = 0; int num_auth_errors_ = 0; + int num_signin_dialog_closed_notifications_ = 0; absl::optional<account_manager::Account> last_upserted_account_; absl::optional<account_manager::Account> last_removed_account_; absl::optional<account_manager::AccountKey> last_err_account_; @@ -278,6 +286,10 @@ class AccountManagerMojoServiceTest : public ::testing::Test { account_manager::ToMojoGoogleServiceAuthError(error)); } + void NotifySigninDialogClosed() { + account_manager_mojo_service_->NotifySigninDialogClosed(); + } + int GetNumObservers() const { return account_manager_mojo_service_->observers_.size(); } @@ -694,4 +706,63 @@ TEST_F(AccountManagerMojoServiceTest, EXPECT_EQ(error, error_info.second); } +TEST_F(AccountManagerMojoServiceTest, + ObserversAreNotNotifiedOnTransientAccountErrorUpdates) { + // Set up observer. + const account_manager::AccountKey kTestAccountKey{ + kFakeGaiaId, account_manager::AccountType::kGaia}; + ASSERT_TRUE(InitializeAccountManager()); + TestAccountManagerObserver observer; + observer.Observe(account_manager_async_waiter()); + ASSERT_EQ(1, GetNumObservers()); + account_manager()->UpsertAccount(kTestAccountKey, kFakeEmail, kFakeToken); + FlushMojoForTesting(); + + // Report an error. + EXPECT_EQ(0, observer.GetNumAuthErrors()); + const GoogleServiceAuthError error = + GoogleServiceAuthError::FromServiceUnavailable("Service Unavailable"); + ASSERT_TRUE(error.IsTransientError()); + ReportAuthError(kTestAccountKey, error); + FlushMojoForTesting(); + + // Transient errors should not be reported. + EXPECT_EQ(0, observer.GetNumAuthErrors()); +} + +TEST_F(AccountManagerMojoServiceTest, + ObserversAreNotifiedAboutAccountAdditionDialogClosure) { + TestAccountManagerObserver observer; + observer.Observe(account_manager_async_waiter()); + ASSERT_EQ(1, GetNumObservers()); + + EXPECT_EQ(0, observer.GetNumSigninDialogClosedNotifications()); + GetFakeAccountManagerUI()->SetIsDialogShown(false); + base::RunLoop run_loop; + mojom::AccountAdditionResultPtr account_addition_result = + ShowAddAccountDialog(run_loop.QuitClosure()); + // Simulate closing the dialog. + GetFakeAccountManagerUI()->CloseDialog(); + run_loop.Run(); + FlushMojoForTesting(); + EXPECT_EQ(1, observer.GetNumSigninDialogClosedNotifications()); +} + +TEST_F(AccountManagerMojoServiceTest, + ObserversAreNotifiedAboutReautDialogClosure) { + TestAccountManagerObserver observer; + observer.Observe(account_manager_async_waiter()); + ASSERT_EQ(1, GetNumObservers()); + + EXPECT_EQ(0, observer.GetNumSigninDialogClosedNotifications()); + GetFakeAccountManagerUI()->SetIsDialogShown(false); + base::RunLoop run_loop; + ShowReauthAccountDialog(kFakeEmail, run_loop.QuitClosure()); + // Simulate closing the dialog. + GetFakeAccountManagerUI()->CloseDialog(); + run_loop.Run(); + FlushMojoForTesting(); + EXPECT_EQ(1, observer.GetNumSigninDialogClosedNotifications()); +} + } // namespace crosapi diff --git a/chromium/components/account_manager_core/chromeos/account_manager_ui.cc b/chromium/components/account_manager_core/chromeos/account_manager_ui.cc index fc0c619e084..865ad9ba62d 100644 --- a/chromium/components/account_manager_core/chromeos/account_manager_ui.cc +++ b/chromium/components/account_manager_core/chromeos/account_manager_ui.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/components/account_manager_core/chromeos/account_manager_ui.h b/chromium/components/account_manager_core/chromeos/account_manager_ui.h index eb80b4f95b4..1d4dcb2ec23 100644 --- a/chromium/components/account_manager_core/chromeos/account_manager_ui.h +++ b/chromium/components/account_manager_core/chromeos/account_manager_ui.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. +// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,7 +12,7 @@ namespace account_manager { -// This interface is used by `AccountManagerFacadeImpl` to show system UI +// This interface is used by `AccountManagerMojoService` to show system UI // (system dialogs, OS Settings etc.) class COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) AccountManagerUI { public: diff --git a/chromium/components/account_manager_core/chromeos/account_manager_unittest.cc b/chromium/components/account_manager_core/chromeos/account_manager_unittest.cc index ed02814b9e0..6bdf6d06115 100644 --- a/chromium/components/account_manager_core/chromeos/account_manager_unittest.cc +++ b/chromium/components/account_manager_core/chromeos/account_manager_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/components/account_manager_core/chromeos/fake_account_manager_ui.cc b/chromium/components/account_manager_core/chromeos/fake_account_manager_ui.cc index 9561678d254..f0ce2cba6b6 100644 --- a/chromium/components/account_manager_core/chromeos/fake_account_manager_ui.cc +++ b/chromium/components/account_manager_core/chromeos/fake_account_manager_ui.cc @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/components/account_manager_core/chromeos/fake_account_manager_ui.h b/chromium/components/account_manager_core/chromeos/fake_account_manager_ui.h index ccb202d7b94..0dfd23b99ab 100644 --- a/chromium/components/account_manager_core/chromeos/fake_account_manager_ui.h +++ b/chromium/components/account_manager_core/chromeos/fake_account_manager_ui.h @@ -1,4 +1,4 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. +// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chromium/components/account_manager_core/chromeos/tokens.proto b/chromium/components/account_manager_core/chromeos/tokens.proto index d0fd5cc2044..e6dcc65e444 100644 --- a/chromium/components/account_manager_core/chromeos/tokens.proto +++ b/chromium/components/account_manager_core/chromeos/tokens.proto @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. |