Skip to content

Commit

Permalink
Notify observers when Attribution Reporting data is deleted by key
Browse files Browse the repository at this point in the history
Otherwise, the Attribution Internals UI will not be updated promptly,
causing misleading data to be shown indefinitely.

Bug: 1449219
Change-Id: I61159ba12d8f6f4bec7b88e1de90452bda2420dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4568989
Commit-Queue: Andrew Paseltiner <apaseltiner@chromium.org>
Reviewed-by: Nan Lin <linnan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1149708}
  • Loading branch information
Andrew Paseltiner authored and Chromium LUCI CQ committed May 26, 2023
1 parent af7bcc1 commit b9556b0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,18 @@ void AttributionManagerImpl::RemoveAttributionDataByDataKey(
base::OnceClosure callback) {
attribution_storage_.AsyncCall(&AttributionStorage::DeleteByDataKey)
.WithArgs(data_key)
.Then(std::move(callback));
.Then(std::move(callback).Then(
// TODO(crbug.com/1446693): Replace this lambda with
// `OnClearDataComplete()` so that observers are notified and the
// task-runner priority is restored.
base::BindOnce(
[](base::WeakPtr<AttributionManagerImpl> manager) {
if (manager) {
manager->NotifySourcesChanged();
manager->NotifyReportsChanged();
}
},
weak_factory_.GetWeakPtr())));
}

void AttributionManagerImpl::GetReportsToSend() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "content/browser/attribution_reporting/test/mock_content_browser_client.h"
#include "content/browser/browsing_data/browsing_data_filter_builder_impl.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/attribution_data_model.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browsing_data_filter_builder.h"
#include "content/public/browser/global_routing_id.h"
Expand Down Expand Up @@ -2839,6 +2840,24 @@ TEST_F(AttributionManagerImplTest, PendingReportsMetrics_OverLimits) {
(base::Seconds(10) * kMaxPendingReportsTimings).InMilliseconds());
}

TEST_F(AttributionManagerImplTest,
RemoveAttributionDataByDataKey_NotifiesObservers) {
MockAttributionObserver observer;
base::ScopedObservation<AttributionManager, AttributionObserver> observation(
&observer);
observation.Observe(attribution_manager_.get());

EXPECT_CALL(observer, OnSourcesChanged);
EXPECT_CALL(observer, OnReportsChanged);

base::RunLoop run_loop;
attribution_manager_->RemoveAttributionDataByDataKey(
AttributionDataModel::DataKey(
url::Origin::Create(GURL("https://x.test"))),
run_loop.QuitClosure());
run_loop.Run();
}

class AttributionManagerImplDebugReportTest
: public AttributionManagerImplTest {
protected:
Expand Down

0 comments on commit b9556b0

Please sign in to comment.