Commit 6984959b authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

Retire ScopedObserver in /components/signin.

ScopedObserver is being deprecated in favor of two new classes:
- base::ScopedObservation for observers that only ever observe
  a single source.
- base::ScopedMultiSourceObservation for observers that do or may
  observe more than a single source.

This CL was uploaded by git cl split.

R=sdefresne@chromium.org

Bug: 1145565
Change-Id: I6079224aa98f835cd8913977b157e02b0a679f90
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533136Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Auto-Submit: Sigurður Ásgeirsson <siggi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826863}
parent d5b81872
......@@ -11,7 +11,7 @@
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
......@@ -2478,9 +2478,9 @@ TEST_F(AccountReconcilorMirrorTest, Lock) {
};
TestAccountReconcilorObserver observer;
ScopedObserver<AccountReconcilor, AccountReconcilor::Observer>
scoped_observer(&observer);
scoped_observer.Add(reconcilor);
base::ScopedObservation<AccountReconcilor, AccountReconcilor::Observer>
scoped_observation(&observer);
scoped_observation.Observe(reconcilor);
// Lock prevents reconcile from starting, as long as one instance is alive.
std::unique_ptr<AccountReconcilor::Lock> lock_1 =
......
......@@ -13,7 +13,7 @@ SigninErrorController::SigninErrorController(
identity_manager_(identity_manager),
auth_error_(GoogleServiceAuthError::AuthErrorNone()) {
DCHECK(identity_manager_);
scoped_identity_manager_observer_.Add(identity_manager_);
scoped_identity_manager_observation_.Observe(identity_manager_);
Update();
}
......@@ -21,7 +21,7 @@ SigninErrorController::SigninErrorController(
SigninErrorController::~SigninErrorController() = default;
void SigninErrorController::Shutdown() {
scoped_identity_manager_observer_.RemoveAll();
scoped_identity_manager_observation_.RemoveObservation();
}
void SigninErrorController::Update() {
......
......@@ -9,7 +9,7 @@
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "google_apis/gaia/google_service_auth_error.h"
......@@ -86,8 +86,9 @@ class SigninErrorController : public KeyedService,
const AccountMode account_mode_;
signin::IdentityManager* identity_manager_;
ScopedObserver<signin::IdentityManager, signin::IdentityManager::Observer>
scoped_identity_manager_observer_{this};
base::ScopedObservation<signin::IdentityManager,
signin::IdentityManager::Observer>
scoped_identity_manager_observation_{this};
// The account that generated the last auth error.
CoreAccountId error_account_id_;
......
......@@ -9,7 +9,7 @@
#include <functional>
#include <memory>
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "base/stl_util.h"
#include "base/test/task_environment.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
......@@ -40,9 +40,10 @@ TEST(SigninErrorControllerTest, SingleAccount) {
SigninErrorController error_controller(
SigninErrorController::AccountMode::ANY_ACCOUNT,
identity_test_env.identity_manager());
ScopedObserver<SigninErrorController, SigninErrorController::Observer>
scoped_observer(&observer);
scoped_observer.Add(&error_controller);
base::ScopedObservation<SigninErrorController,
SigninErrorController::Observer>
scoped_observation(&observer);
scoped_observation.Observe(&error_controller);
ASSERT_FALSE(error_controller.HasError());
::testing::Mock::VerifyAndClearExpectations(&observer);
......
......@@ -17,7 +17,6 @@ SigninStatusMetricsProvider::SigninStatusMetricsProvider(
std::unique_ptr<SigninStatusMetricsProviderDelegate> delegate,
bool is_test)
: delegate_(std::move(delegate)),
scoped_observer_(this),
is_test_(is_test) {
DCHECK(delegate_ || is_test_);
if (is_test_)
......@@ -56,7 +55,7 @@ void SigninStatusMetricsProvider::OnIdentityManagerCreated(
// Whenever a new profile is created, a new IdentityManager will be created
// for it. This ensures that all sign-in or sign-out actions of all opened
// profiles are being monitored.
scoped_observer_.Add(identity_manager);
scoped_observations_.AddObservation(identity_manager);
// If the status is unknown, it means this is the first created
// IdentityManager and the corresponding profile should be the only opened
......@@ -69,8 +68,8 @@ void SigninStatusMetricsProvider::OnIdentityManagerCreated(
void SigninStatusMetricsProvider::OnIdentityManagerShutdown(
signin::IdentityManager* identity_manager) {
if (scoped_observer_.IsObserving(identity_manager))
scoped_observer_.Remove(identity_manager);
if (scoped_observations_.IsObservingSource(identity_manager))
scoped_observations_.RemoveObservation(identity_manager);
}
void SigninStatusMetricsProvider::OnPrimaryAccountSet(
......@@ -103,8 +102,8 @@ void SigninStatusMetricsProvider::Initialize() {
// Start observing all already-created IdentityManagers.
for (signin::IdentityManager* manager :
delegate_->GetIdentityManagersForAllAccounts()) {
DCHECK(!scoped_observer_.IsObserving(manager));
scoped_observer_.Add(manager);
DCHECK(!scoped_observations_.IsObservingSource(manager));
scoped_observations_.AddObservation(manager);
}
// It is possible that when this object is created, no IdentityManager is
......
......@@ -12,7 +12,7 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "base/scoped_multi_source_observation.h"
#include "build/build_config.h"
#include "components/signin/core/browser/signin_status_metrics_provider_base.h"
#include "components/signin/core/browser/signin_status_metrics_provider_delegate.h"
......@@ -90,8 +90,9 @@ class SigninStatusMetricsProvider : public SigninStatusMetricsProviderBase,
// Used to track the IdentityManagers that this instance is observing so that
// this instance can be removed as an observer on its destruction.
ScopedObserver<signin::IdentityManager, signin::IdentityManager::Observer>
scoped_observer_;
base::ScopedMultiSourceObservation<signin::IdentityManager,
signin::IdentityManager::Observer>
scoped_observations_{this};
// Whether the instance is for testing or not.
bool is_test_;
......
......@@ -93,7 +93,7 @@ AccessTokenFetcher::AccessTokenFetcher(
// Start observing the IdentityManager. This observer will be removed either
// when a refresh token is obtained and an access token request is started or
// when this object is destroyed.
token_service_observer_.Add(token_service_);
token_service_observation_.Observe(token_service_);
}
AccessTokenFetcher::~AccessTokenFetcher() {}
......@@ -109,7 +109,7 @@ void AccessTokenFetcher::StartAccessTokenRequest() {
// By the time of starting an access token request, we should no longer be
// listening for signin-related events.
DCHECK(!token_service_observer_.IsObserving(token_service_));
DCHECK(!token_service_observation_.IsObservingSource(token_service_));
// Note: We might get here even in cases where we know that there's no refresh
// token. We're requesting an access token anyway, so that the token service
......@@ -144,7 +144,8 @@ void AccessTokenFetcher::OnRefreshTokenAvailable(
if (!IsRefreshTokenAvailable())
return;
token_service_observer_.Remove(token_service_);
DCHECK(token_service_observation_.IsObservingSource(token_service_));
token_service_observation_.RemoveObservation();
StartAccessTokenRequest();
}
......
......@@ -11,7 +11,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "components/signin/internal/identity_manager/profile_oauth2_token_service.h"
#include "components/signin/internal/identity_manager/profile_oauth2_token_service_observer.h"
#include "components/signin/public/identity_manager/scope_set.h"
......@@ -245,8 +245,9 @@ class AccessTokenFetcher : public ProfileOAuth2TokenServiceObserver,
// contract.
TokenCallback callback_;
ScopedObserver<ProfileOAuth2TokenService, ProfileOAuth2TokenServiceObserver>
token_service_observer_{this};
base::ScopedObservation<ProfileOAuth2TokenService,
ProfileOAuth2TokenServiceObserver>
token_service_observation_{this};
std::unique_ptr<OAuth2AccessTokenManager::Request> access_token_request_;
......
......@@ -54,8 +54,8 @@ IdentityManager::IdentityManager(IdentityManager::InitParameters&& parameters)
DCHECK(account_fetcher_service_);
DCHECK(diagnostics_provider_);
primary_account_manager_observer_.Add(primary_account_manager_.get());
token_service_observer_.Add(token_service_.get());
primary_account_manager_observation_.Observe(primary_account_manager_.get());
token_service_observation_.Observe(token_service_.get());
token_service_->AddAccessTokenDiagnosticsObserver(this);
// IdentityManager owns the ATS, GCMS and PO2TS instances and will outlive
......@@ -325,11 +325,11 @@ DeviceAccountsSynchronizer* IdentityManager::GetDeviceAccountsSynchronizer() {
}
void IdentityManager::AddDiagnosticsObserver(DiagnosticsObserver* observer) {
diagnostics_observer_list_.AddObserver(observer);
diagnostics_observation_list_.AddObserver(observer);
}
void IdentityManager::RemoveDiagnosticsObserver(DiagnosticsObserver* observer) {
diagnostics_observer_list_.RemoveObserver(observer);
diagnostics_observation_list_.RemoveObserver(observer);
}
void IdentityManager::OnNetworkInitialized() {
......@@ -584,7 +584,7 @@ void IdentityManager::OnGaiaCookieDeletedByUserAction() {
void IdentityManager::OnAccessTokenRequested(const CoreAccountId& account_id,
const std::string& consumer_id,
const ScopeSet& scopes) {
for (auto& observer : diagnostics_observer_list_) {
for (auto& observer : diagnostics_observation_list_) {
observer.OnAccessTokenRequested(account_id, consumer_id, scopes);
}
}
......@@ -595,14 +595,14 @@ void IdentityManager::OnFetchAccessTokenComplete(
const ScopeSet& scopes,
GoogleServiceAuthError error,
base::Time expiration_time) {
for (auto& observer : diagnostics_observer_list_)
for (auto& observer : diagnostics_observation_list_)
observer.OnAccessTokenRequestCompleted(account_id, consumer_id, scopes,
error, expiration_time);
}
void IdentityManager::OnAccessTokenRemoved(const CoreAccountId& account_id,
const ScopeSet& scopes) {
for (auto& observer : diagnostics_observer_list_)
for (auto& observer : diagnostics_observation_list_)
observer.OnAccessTokenRemovedFromCache(account_id, scopes);
}
......@@ -610,7 +610,7 @@ void IdentityManager::OnRefreshTokenAvailableFromSource(
const CoreAccountId& account_id,
bool is_refresh_token_valid,
const std::string& source) {
for (auto& observer : diagnostics_observer_list_)
for (auto& observer : diagnostics_observation_list_)
observer.OnRefreshTokenUpdatedForAccountFromSource(
account_id, is_refresh_token_valid, source);
}
......@@ -618,7 +618,7 @@ void IdentityManager::OnRefreshTokenAvailableFromSource(
void IdentityManager::OnRefreshTokenRevokedFromSource(
const CoreAccountId& account_id,
const std::string& source) {
for (auto& observer : diagnostics_observer_list_)
for (auto& observer : diagnostics_observation_list_)
observer.OnRefreshTokenRemovedForAccountFromSource(account_id, source);
}
......
......@@ -10,7 +10,7 @@
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "build/build_config.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/signin/internal/identity_manager/primary_account_manager.h"
......@@ -682,16 +682,18 @@ class IdentityManager : public KeyedService,
std::unique_ptr<DiagnosticsProvider> diagnostics_provider_;
// Scoped observers.
ScopedObserver<PrimaryAccountManager, PrimaryAccountManager::Observer>
primary_account_manager_observer_{this};
ScopedObserver<ProfileOAuth2TokenService, ProfileOAuth2TokenServiceObserver>
token_service_observer_{this};
base::ScopedObservation<PrimaryAccountManager,
PrimaryAccountManager::Observer>
primary_account_manager_observation_{this};
base::ScopedObservation<ProfileOAuth2TokenService,
ProfileOAuth2TokenServiceObserver>
token_service_observation_{this};
// Lists of observers.
// Makes sure lists are empty on destruction.
base::ObserverList<Observer, true>::Unchecked observer_list_;
base::ObserverList<DiagnosticsObserver, true>::Unchecked
diagnostics_observer_list_;
diagnostics_observation_list_;
#if defined(OS_ANDROID)
// Java-side IdentityManager object.
......
......@@ -13,7 +13,7 @@
#include "base/containers/flat_set.h"
#include "base/files/scoped_temp_dir.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "base/stl_util.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
......
......@@ -36,7 +36,7 @@ PrimaryAccountAccessTokenFetcher::PrimaryAccountAccessTokenFetcher(
// Start observing the IdentityManager. This observer will be removed either
// when credentials are obtained and an access token request is started or
// when this object is destroyed.
identity_manager_observer_.Add(identity_manager_);
identity_manager_observation_.Observe(identity_manager_);
}
PrimaryAccountAccessTokenFetcher::~PrimaryAccountAccessTokenFetcher() = default;
......@@ -56,7 +56,7 @@ void PrimaryAccountAccessTokenFetcher::StartAccessTokenRequest() {
// By the time of starting an access token request, we should no longer be
// listening for signin-related events.
DCHECK(!identity_manager_observer_.IsObserving(identity_manager_));
DCHECK(!identity_manager_observation_.IsObservingSource(identity_manager_));
// Note: We might get here even in cases where we know that there's no refresh
// token. We're requesting an access token anyway, so that the token service
......@@ -110,7 +110,8 @@ void PrimaryAccountAccessTokenFetcher::ProcessSigninStateChange() {
if (!AreCredentialsAvailable())
return;
identity_manager_observer_.Remove(identity_manager_);
DCHECK(identity_manager_observation_.IsObservingSource(identity_manager_));
identity_manager_observation_.RemoveObservation();
StartAccessTokenRequest();
}
......
......@@ -9,7 +9,7 @@
#include <string>
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "components/signin/public/identity_manager/access_token_fetcher.h"
#include "components/signin/public/identity_manager/consent_level.h"
#include "components/signin/public/identity_manager/identity_manager.h"
......@@ -202,8 +202,8 @@ class PrimaryAccountAccessTokenFetcher : public IdentityManager::Observer {
// code.
AccessTokenFetcher::TokenCallback callback_;
ScopedObserver<IdentityManager, IdentityManager::Observer>
identity_manager_observer_{this};
base::ScopedObservation<IdentityManager, IdentityManager::Observer>
identity_manager_observation_{this};
// Internal fetcher that does the actual access token request.
std::unique_ptr<AccessTokenFetcher> access_token_fetcher_;
......
......@@ -7,7 +7,7 @@
#include "base/bind.h"
#include "base/containers/flat_set.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
#include "base/scoped_observation.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "components/signin/public/base/signin_metrics.h"
......@@ -63,10 +63,10 @@ class ClearPrimaryAccountTestObserver
RefreshTokenRemovedCallback on_refresh_token_removed)
: on_primary_account_cleared_(std::move(on_primary_account_cleared)),
on_refresh_token_removed_(std::move(on_refresh_token_removed)),
scoped_observer_(this) {
scoped_observation_(this) {
DCHECK(on_primary_account_cleared_);
DCHECK(on_refresh_token_removed_);
scoped_observer_.Add(identity_manager);
scoped_observation_.Observe(identity_manager);
}
// signin::IdentityManager::Observer implementation.
......@@ -82,8 +82,9 @@ class ClearPrimaryAccountTestObserver
private:
PrimaryAccountClearedCallback on_primary_account_cleared_;
RefreshTokenRemovedCallback on_refresh_token_removed_;
ScopedObserver<signin::IdentityManager, signin::IdentityManager::Observer>
scoped_observer_;
base::ScopedObservation<signin::IdentityManager,
signin::IdentityManager::Observer>
scoped_observation_{this};
DISALLOW_COPY_AND_ASSIGN(ClearPrimaryAccountTestObserver);
};
......@@ -166,7 +167,7 @@ void RunClearPrimaryAccountTest(
},
&observed_removals);
ClearPrimaryAccountTestObserver scoped_observer(
ClearPrimaryAccountTestObserver scoped_observation(
identity_manager, primary_account_cleared_callback,
refresh_token_removed_callback);
......
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