Commit 2ba0fb79 authored by Jochen Eisinger's avatar Jochen Eisinger Committed by Commit Bot

Add IdentityManager::Observer::On{Start,End}BatchOfRefreshTokenStateChanges

This mirrors the calls on
OAuth2TokenService::Observer::On{Start,End}BatchChanges.

Bug: 897113
Change-Id: I6a436baf28f4bf629da8a9b037cd5ab04c644fe1
Reviewed-on: https://chromium-review.googlesource.com/c/1296249
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603071}
parent e2df8d38
...@@ -305,6 +305,16 @@ void IdentityManager::OnRefreshTokensLoaded() { ...@@ -305,6 +305,16 @@ void IdentityManager::OnRefreshTokensLoaded() {
observer.OnRefreshTokensLoaded(); observer.OnRefreshTokensLoaded();
} }
void IdentityManager::OnStartBatchChanges() {
for (auto& observer : observer_list_)
observer.OnStartBatchOfRefreshTokenStateChanges();
}
void IdentityManager::OnEndBatchChanges() {
for (auto& observer : observer_list_)
observer.OnEndBatchOfRefreshTokenStateChanges();
}
void IdentityManager::OnGaiaAccountsInCookieUpdated( void IdentityManager::OnGaiaAccountsInCookieUpdated(
const std::vector<gaia::ListedAccount>& accounts, const std::vector<gaia::ListedAccount>& accounts,
const std::vector<gaia::ListedAccount>& signed_out_accounts, const std::vector<gaia::ListedAccount>& signed_out_accounts,
......
...@@ -110,6 +110,12 @@ class IdentityManager : public SigninManagerBase::Observer, ...@@ -110,6 +110,12 @@ class IdentityManager : public SigninManagerBase::Observer,
// |accounts| is ordered by the order of the accounts in the cookie. // |accounts| is ordered by the order of the accounts in the cookie.
virtual void OnAccountsInCookieUpdated( virtual void OnAccountsInCookieUpdated(
const std::vector<AccountInfo>& accounts) {} const std::vector<AccountInfo>& accounts) {}
// Called before a batch of refresh token state changes is started.
virtual void OnStartBatchOfRefreshTokenStateChanges() {}
// Called after a batch of refresh token state chagnes is completed.
virtual void OnEndBatchOfRefreshTokenStateChanges() {}
}; };
// Observer interface for classes that want to monitor status of various // Observer interface for classes that want to monitor status of various
...@@ -307,6 +313,8 @@ class IdentityManager : public SigninManagerBase::Observer, ...@@ -307,6 +313,8 @@ class IdentityManager : public SigninManagerBase::Observer,
void OnRefreshTokenAvailable(const std::string& account_id) override; void OnRefreshTokenAvailable(const std::string& account_id) override;
void OnRefreshTokenRevoked(const std::string& account_id) override; void OnRefreshTokenRevoked(const std::string& account_id) override;
void OnRefreshTokensLoaded() override; void OnRefreshTokensLoaded() override;
void OnStartBatchChanges() override;
void OnEndBatchChanges() override;
// GaiaCookieManagerService::Observer: // GaiaCookieManagerService::Observer:
void OnGaiaAccountsInCookieUpdated( void OnGaiaAccountsInCookieUpdated(
......
...@@ -255,6 +255,12 @@ class TestIdentityManagerObserver : IdentityManager::Observer { ...@@ -255,6 +255,12 @@ class TestIdentityManagerObserver : IdentityManager::Observer {
return google_signin_failed_error_; return google_signin_failed_error_;
} }
// Each element represents all the changes from an individual batch that has
// occurred, with the elements ordered from oldest to newest batch occurrence.
const std::vector<std::vector<std::string>>& batch_change_records() const {
return batch_change_records_;
}
private: private:
// IdentityManager::Observer: // IdentityManager::Observer:
void OnPrimaryAccountSet(const AccountInfo& primary_account_info) override { void OnPrimaryAccountSet(const AccountInfo& primary_account_info) override {
...@@ -276,12 +282,16 @@ class TestIdentityManagerObserver : IdentityManager::Observer { ...@@ -276,12 +282,16 @@ class TestIdentityManagerObserver : IdentityManager::Observer {
} }
void OnRefreshTokenUpdatedForAccount(const AccountInfo& account_info, void OnRefreshTokenUpdatedForAccount(const AccountInfo& account_info,
bool is_valid) override { bool is_valid) override {
EXPECT_TRUE(is_inside_batch_);
batch_change_records_.rbegin()->emplace_back(account_info.account_id);
account_from_refresh_token_updated_callback_ = account_info; account_from_refresh_token_updated_callback_ = account_info;
validity_from_refresh_token_updated_callback_ = is_valid; validity_from_refresh_token_updated_callback_ = is_valid;
if (on_refresh_token_updated_callback_) if (on_refresh_token_updated_callback_)
std::move(on_refresh_token_updated_callback_).Run(); std::move(on_refresh_token_updated_callback_).Run();
} }
void OnRefreshTokenRemovedForAccount(const std::string& account_id) override { void OnRefreshTokenRemovedForAccount(const std::string& account_id) override {
EXPECT_TRUE(is_inside_batch_);
batch_change_records_.rbegin()->emplace_back(account_id);
account_from_refresh_token_removed_callback_ = account_id; account_from_refresh_token_removed_callback_ = account_id;
if (on_refresh_token_removed_callback_) if (on_refresh_token_removed_callback_)
on_refresh_token_removed_callback_.Run(account_id); on_refresh_token_removed_callback_.Run(account_id);
...@@ -296,6 +306,17 @@ class TestIdentityManagerObserver : IdentityManager::Observer { ...@@ -296,6 +306,17 @@ class TestIdentityManagerObserver : IdentityManager::Observer {
if (on_accounts_in_cookie_updated_callback_) if (on_accounts_in_cookie_updated_callback_)
std::move(on_accounts_in_cookie_updated_callback_).Run(); std::move(on_accounts_in_cookie_updated_callback_).Run();
} }
void OnStartBatchOfRefreshTokenStateChanges() override {
EXPECT_FALSE(is_inside_batch_);
is_inside_batch_ = true;
// Start a new batch.
batch_change_records_.emplace_back(std::vector<std::string>());
}
void OnEndBatchOfRefreshTokenStateChanges() override {
EXPECT_TRUE(is_inside_batch_);
is_inside_batch_ = false;
}
IdentityManager* identity_manager_; IdentityManager* identity_manager_;
base::OnceClosure on_primary_account_set_callback_; base::OnceClosure on_primary_account_set_callback_;
...@@ -313,6 +334,8 @@ class TestIdentityManagerObserver : IdentityManager::Observer { ...@@ -313,6 +334,8 @@ class TestIdentityManagerObserver : IdentityManager::Observer {
std::string account_from_refresh_token_removed_callback_; std::string account_from_refresh_token_removed_callback_;
std::vector<AccountInfo> accounts_from_cookie_change_callback_; std::vector<AccountInfo> accounts_from_cookie_change_callback_;
GoogleServiceAuthError google_signin_failed_error_; GoogleServiceAuthError google_signin_failed_error_;
bool is_inside_batch_ = false;
std::vector<std::vector<std::string>> batch_change_records_;
}; };
class TestIdentityManagerDiagnosticsObserver class TestIdentityManagerDiagnosticsObserver
...@@ -1982,4 +2005,17 @@ TEST_F(IdentityManagerTest, GetAccountsInCookieJarWithTwoAccounts) { ...@@ -1982,4 +2005,17 @@ TEST_F(IdentityManagerTest, GetAccountsInCookieJarWithTwoAccounts) {
EXPECT_EQ(kTestEmail2, account_info2.email); EXPECT_EQ(kTestEmail2, account_info2.email);
} }
TEST_F(IdentityManagerTest,
BatchChangeObserversAreNotifiedOnCredentialsUpdate) {
signin_manager()->SetAuthenticatedAccountInfo(kTestGaiaId, kTestEmail);
std::string account_id = signin_manager()->GetAuthenticatedAccountId();
token_service()->UpdateCredentials(account_id, "refresh_token");
EXPECT_EQ(1ul, identity_manager_observer()->batch_change_records().size());
EXPECT_EQ(1ul,
identity_manager_observer()->batch_change_records().at(0).size());
EXPECT_EQ(account_id,
identity_manager_observer()->batch_change_records().at(0).at(0));
}
} // namespace identity } // namespace identity
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