Skip to content

Commit

Permalink
Handle onIconChanged.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 709170088
  • Loading branch information
suetfei authored and copybara-github committed Dec 24, 2024
1 parent c9fbf6b commit e091ad6
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 3 deletions.
5 changes: 4 additions & 1 deletion internal/platform/implementation/account_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class AccountManager {
// |credential_error| is true if the logout is due to critical auth error.
virtual void OnLogoutSucceeded(absl::string_view account_id,
bool credential_error) = 0;
// Only needed by certificate manager.
virtual void OnIconChanged() {};
};

virtual ~AccountManager() = default;
Expand Down Expand Up @@ -83,7 +85,8 @@ class AccountManager {

virtual void SaveAccountPrefs(absl::string_view user_id,
absl::string_view client_id,
absl::string_view client_secret) = 0;
absl::string_view client_secret,
absl::string_view picture_url) = 0;
};

} // namespace nearby
Expand Down
6 changes: 6 additions & 0 deletions internal/test/fake_account_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,10 @@ void FakeAccountManager::NotifyLogout(absl::string_view account_id,
}
}

void FakeAccountManager::NotifyIconChanged() {
for (const auto& observer : observers_.GetObservers()) {
observer->OnIconChanged();
}
}

} // namespace nearby
4 changes: 3 additions & 1 deletion internal/test/fake_account_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class FakeAccountManager : public AccountManager {
void RemoveObserver(Observer* observer) override;

void SaveAccountPrefs(absl::string_view user_id, absl::string_view client_id,
absl::string_view client_secret) override {}
absl::string_view client_secret,
absl::string_view picture_url) override {}

// Methods to set API response.
void SetAccount(std::optional<Account> account);
Expand All @@ -67,6 +68,7 @@ class FakeAccountManager : public AccountManager {

void NotifyLogin(absl::string_view account_id);
void NotifyLogout(absl::string_view account_id, bool credential_error);
void NotifyIconChanged();

private:
// Login will fail when account_ is empty.
Expand Down
2 changes: 1 addition & 1 deletion internal/test/mock_account_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MockAccountManager : public AccountManager {
MOCK_METHOD(void, RemoveObserver, (Observer * observer), (override));
MOCK_METHOD(void, SaveAccountPrefs,
(absl::string_view user_id, absl::string_view client_id,
absl::string_view client_secret),
absl::string_view client_secret, absl::string_view picture_url),
(override));
};

Expand Down
1 change: 1 addition & 0 deletions internal/test/mock_account_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MockAccountObserver : public AccountManager::Observer {
MOCK_METHOD(void, OnLogoutSucceeded,
(absl::string_view account_id, bool credential_error),
(override));
MOCK_METHOD(void, OnIconChanged, (), (override));
};

} // namespace nearby
Expand Down
11 changes: 11 additions & 0 deletions sharing/certificates/nearby_share_certificate_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ NearbyShareCertificateManagerImpl::NearbyShareCertificateManagerImpl(
executor_(context->CreateSequencedTaskRunner()) {
local_device_data_manager_->AddObserver(this);
contact_manager_->AddObserver(this);
account_manager_.AddObserver(this);
}

NearbyShareCertificateManagerImpl::~NearbyShareCertificateManagerImpl() {
local_device_data_manager_->RemoveObserver(this);
contact_manager_->RemoveObserver(this);
account_manager_.RemoveObserver(this);
}

void NearbyShareCertificateManagerImpl::CertificateDownloadContext::
Expand Down Expand Up @@ -637,6 +639,15 @@ void NearbyShareCertificateManagerImpl::OnLocalDeviceDataChanged(
});
}

void NearbyShareCertificateManagerImpl::OnIconChanged() {
executor_->PostTask([this]() {
LOG(INFO) << __func__ << ": handle icon changed.";
// Recreate all private certificates to ensure up-to-date metadata.
certificate_storage_->ClearPrivateCertificates();
private_certificate_expiration_scheduler_->MakeImmediateRequest();
});
}

void NearbyShareCertificateManagerImpl::SetVendorId(int32_t vendor_id) {
LOG(INFO) << "Setting certificate vendor ID to " << vendor_id;
vendor_id_ = vendor_id;
Expand Down
7 changes: 7 additions & 0 deletions sharing/certificates/nearby_share_certificate_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class NearbyShareScheduler;
class NearbyShareCertificateManagerImpl
: public NearbyShareCertificateManager,
public NearbyShareContactManager::Observer,
public ::nearby::AccountManager::Observer,
public NearbyShareLocalDeviceDataManager::Observer {
public:
class Factory {
Expand Down Expand Up @@ -174,6 +175,12 @@ class NearbyShareCertificateManagerImpl
bool did_full_name_change,
bool did_icon_change) override;

// // AccountManager::Observer:
void OnLoginSucceeded(absl::string_view account_id) override {};
void OnLogoutSucceeded(absl::string_view account_id,
bool credential_error) override {};
void OnIconChanged() override;

// Dump certs information.
std::string Dump() const override;

Expand Down
10 changes: 10 additions & 0 deletions sharing/certificates/nearby_share_certificate_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,16 @@ TEST_F(NearbyShareCertificateManagerImplTest,
}
}

TEST_F(NearbyShareCertificateManagerImplTest,
RefreshPrivateCertificates_OnIconChanged) {
cert_manager_->Start();
fake_account_manager_.NotifyIconChanged();
Sync();
EXPECT_TRUE(cert_store_->GetPrivateCertificates()->empty());
EXPECT_EQ(1,
private_cert_exp_scheduler_->num_immediate_requests());
}

TEST_F(NearbyShareCertificateManagerImplTest,
RefreshPrivateCertificates_OnVendorIdChanged) {
cert_store_->ReplacePrivateCertificates({});
Expand Down

0 comments on commit e091ad6

Please sign in to comment.