Commit 519d03fe authored by Mehrdad Hessar's avatar Mehrdad Hessar Committed by Commit Bot

This CL adds a signal that shows the blocklist is loaded.

Bug: 1099030
Change-Id: Ibab49ba7816720c3abcba35dafd09be553788bf1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309140Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: Mehrdad Hessar <mehrdadh@google.com>
Cr-Commit-Position: refs/heads/master@{#790405}
parent 9ca53986
......@@ -168,6 +168,9 @@ void OptOutBlocklist::ClearBlockListSync(base::Time begin_time,
blocklist_data_->ClearData();
loaded_ = false;
// Notify |blocklist_delegate_| on blocklist load status
blocklist_delegate_->OnLoadingStateChanged(loaded_);
// Notify |blocklist_delegate_| that the blocklist is cleared.
blocklist_delegate_->OnBlocklistCleared(clock_->Now());
......@@ -216,6 +219,9 @@ void OptOutBlocklist::LoadBlockListDone(
std::move(pending_callbacks_.front()).Run();
pending_callbacks_.pop();
}
// Notify |blocklist_delegate_| on blocklist load status
blocklist_delegate_->OnLoadingStateChanged(loaded_);
}
} // namespace blocklist
......@@ -27,11 +27,11 @@ class OptOutBlocklistDelegate {
// Notifies |this| that the user blocklisted has changed, and it is
// guaranteed to be called when the user blocklisted status is changed.
//
// TODO(crbug/1099030): Update the comment and interface to support providing
// a signal that the blocklist is loaded and available.
virtual void OnUserBlocklistedStatusChange(bool blocklisted) {}
// Notifies |this| the blocklist loaded state changed to |is_loaded|.
virtual void OnLoadingStateChanged(bool is_load) {}
// Notifies |this| that the blocklist is cleared at |time|.
virtual void OnBlocklistCleared(base::Time time) {}
};
......
......@@ -49,6 +49,9 @@ class TestOptOutBlocklistDelegate : public OptOutBlocklistDelegate {
void OnUserBlocklistedStatusChange(bool blocklisted) override {
user_blocklisted_ = blocklisted;
}
void OnLoadingStateChanged(bool is_loaded) override {
blocklist_loaded_ = is_loaded;
}
void OnBlocklistCleared(base::Time time) override {
blocklist_cleared_ = true;
blocklist_cleared_time_ = time;
......@@ -62,6 +65,9 @@ class TestOptOutBlocklistDelegate : public OptOutBlocklistDelegate {
// Gets the state of user blocklisted status.
bool user_blocklisted() const { return user_blocklisted_; }
// Gets the load state of blocklist.
bool blocklist_loaded() const { return blocklist_loaded_; }
// Gets the state of blocklisted cleared status of |this| for testing.
bool blocklist_cleared() const { return blocklist_cleared_; }
......@@ -72,6 +78,9 @@ class TestOptOutBlocklistDelegate : public OptOutBlocklistDelegate {
// The user blocklisted status of |this| blocklist_delegate.
bool user_blocklisted_ = false;
// The blocklist load status of |this| blocklist_delegate.
bool blocklist_loaded_ = false;
// Check if the blocklist is notified as cleared on |this| blocklist_delegate.
bool blocklist_cleared_ = false;
......@@ -952,6 +961,7 @@ TEST_F(OptOutBlocklistTest, ObserverIsNotifiedWhenLoadBlocklistDone) {
opt_out_store->SetBlocklistData(std::move(data));
EXPECT_FALSE(blocklist_delegate_.user_blocklisted());
EXPECT_FALSE(blocklist_delegate_.blocklist_loaded());
allowed_types.clear();
allowed_types[1] = 0;
auto block_list = std::make_unique<TestOptOutBlocklist>(
......@@ -966,6 +976,7 @@ TEST_F(OptOutBlocklistTest, ObserverIsNotifiedWhenLoadBlocklistDone) {
block_list->Init();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(blocklist_delegate_.user_blocklisted());
EXPECT_TRUE(blocklist_delegate_.blocklist_loaded());
}
TEST_F(OptOutBlocklistTest, ObserverIsNotifiedOfHistoricalBlocklistedHosts) {
......
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