Skip to content

Commit

Permalink
[Browsing Data Model] Adds Attribution Reporting interface
Browse files Browse the repository at this point in the history
Exposes Get and Remove methods in a new public interface for Attribution Reporting. Next step is implementing the interface. See crrev.com/c/4026870 for reference.

Bug: 1407369
Change-Id: Id5505f54014a4a698a5ca6989ed0564f6227b0ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4166234
Reviewed-by: Nan Lin <linnan@chromium.org>
Reviewed-by: Andrew Paseltiner <apaseltiner@chromium.org>
Commit-Queue: Mariam Ali <alimariam@google.com>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1096090}
  • Loading branch information
ThomasQuesadilla authored and Chromium LUCI CQ committed Jan 24, 2023
1 parent 1540cdc commit 93a252e
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 2 deletions.
5 changes: 3 additions & 2 deletions content/browser/attribution_reporting/attribution_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "components/attribution_reporting/os_support.mojom-forward.h"
#include "components/attribution_reporting/source_registration_error.mojom-forward.h"
#include "content/browser/attribution_reporting/attribution_report.h"
#include "content/public/browser/attribution_data_model.h"
#include "content/public/browser/storage_partition.h"

namespace attribution_reporting {
Expand All @@ -34,13 +35,13 @@ class WebContents;

// Interface that mediates data flow between the network, storage layer, and
// blink.
class AttributionManager {
class AttributionManager : public AttributionDataModel {
public:
static AttributionManager* FromWebContents(WebContents* web_contents);

static attribution_reporting::mojom::OsSupport GetOsSupport();

virtual ~AttributionManager() = default;
~AttributionManager() override = default;

virtual void AddObserver(AttributionObserver* observer) = 0;

Expand Down
16 changes: 16 additions & 0 deletions content/browser/attribution_reporting/attribution_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <cmath>
#include <utility>
#include <vector>

#include "base/barrier_closure.h"
#include "base/check.h"
Expand Down Expand Up @@ -56,6 +57,7 @@
#include "content/browser/attribution_reporting/storable_source.h"
#include "content/browser/attribution_reporting/stored_source.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/attribution_data_model.h"
#include "content/public/browser/attribution_reporting.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browsing_data_filter_builder.h"
Expand Down Expand Up @@ -800,6 +802,20 @@ void AttributionManagerImpl::OnClearDataComplete() {
NotifyReportsChanged(AttributionReport::Type::kAggregatableAttribution);
}

// TODO(crbug.com/1407369): Propagate calls to storage
void AttributionManagerImpl::GetAllDataKeys(
base::OnceCallback<void(std::vector<AttributionManager::DataKey>)>
callback) {
std::move(callback).Run({});
}

// TODO(crbug.com/1407369): Propagate calls to storage
void AttributionManagerImpl::RemoveAttributionDataByDataKey(
const AttributionManager::DataKey& data_key,
base::OnceClosure callback) {
std::move(callback).Run();
}

void AttributionManagerImpl::GetReportsToSend() {
// We only get the next report time strictly after now, because if we are
// sending a report now but haven't finished doing so and it is still present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ class CONTENT_EXPORT AttributionManagerImpl : public AttributionManager {
const attribution_reporting::SuitableOrigin& reporting_origin,
attribution_reporting::mojom::SourceRegistrationError) override;

void GetAllDataKeys(
base::OnceCallback<void(std::vector<DataKey>)> callback) override;

void RemoveAttributionDataByDataKey(const DataKey& data_key,
base::OnceClosure callback) override;

private:
friend class AttributionManagerImplTest;

Expand Down
12 changes: 12 additions & 0 deletions content/browser/attribution_reporting/attribution_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ class MockAttributionManager : public AttributionManager {
attribution_reporting::mojom::SourceRegistrationError),
(override));

MOCK_METHOD(void,
GetAllDataKeys,
(base::OnceCallback<
void(std::vector<AttributionManager::DataKey>)> callback),
(override));

MOCK_METHOD(void,
RemoveAttributionDataByDataKey,
(const AttributionManager::DataKey& data_key,
base::OnceClosure callback),
(override));

void AddObserver(AttributionObserver* observer) override;
void RemoveObserver(AttributionObserver* observer) override;
AttributionDataHostManager* GetDataHostManager() override;
Expand Down
5 changes: 5 additions & 0 deletions content/browser/storage_partition_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,11 @@ AttributionManager* StoragePartitionImpl::GetAttributionManager() {
return attribution_manager_.get();
}

AttributionDataModel* StoragePartitionImpl::GetAttributionDataModel() {
DCHECK(initialized_);
return attribution_manager_.get();
}

FontAccessManager* StoragePartitionImpl::GetFontAccessManager() {
DCHECK(initialized_);
return font_access_manager_.get();
Expand Down
4 changes: 4 additions & 0 deletions content/browser/storage_partition_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ class CONTENT_EXPORT StoragePartitionImpl
InterestGroupManager* GetInterestGroupManager() override;
BrowsingTopicsSiteDataManager* GetBrowsingTopicsSiteDataManager() override;
leveldb_proto::ProtoDatabaseProvider* GetProtoDatabaseProvider() override;
// Use outside content.
AttributionDataModel* GetAttributionDataModel() override;

void SetProtoDatabaseProvider(
std::unique_ptr<leveldb_proto::ProtoDatabaseProvider> proto_db_provider)
override;
Expand Down Expand Up @@ -256,6 +259,7 @@ class CONTENT_EXPORT StoragePartitionImpl
FileSystemAccessManagerImpl* GetFileSystemAccessManager();
BucketManager* GetBucketManager();
QuotaContext* GetQuotaContext();
// Use inside content.
AttributionManager* GetAttributionManager();
void SetFontAccessManagerForTesting(
std::unique_ptr<FontAccessManager> font_access_manager);
Expand Down
2 changes: 2 additions & 0 deletions content/public/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ source_set("browser_sources") {
"allow_service_worker_result.h",
"anchor_element_preconnect_delegate.h",
"attribution_config.h",
"attribution_data_model.cc",
"attribution_data_model.h",
"attribution_reporting.h",
"audio_service.h",
"audio_service_info.cc",
Expand Down
49 changes: 49 additions & 0 deletions content/public/browser/attribution_data_model.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/public/browser/attribution_data_model.h"

#include <tuple>
#include <utility>

#include "base/check.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/origin.h"

namespace content {

AttributionDataModel::DataKey::DataKey(
url::Origin reporting_origin,
absl::optional<url::Origin> source_origin,
absl::optional<url::Origin> destination_origin)
: reporting_origin_(std::move(reporting_origin)),
source_origin_(std::move(source_origin)),
destination_origin_(std::move(destination_origin)) {
DCHECK(!reporting_origin_.opaque());

DCHECK(!source_origin_.has_value() || !source_origin_->opaque());

DCHECK(!destination_origin_.has_value() || !destination_origin_->opaque());
}

AttributionDataModel::DataKey::DataKey(const DataKey&) = default;

AttributionDataModel::DataKey::DataKey(DataKey&&) = default;

AttributionDataModel::DataKey& AttributionDataModel::DataKey::operator=(
const DataKey&) = default;

AttributionDataModel::DataKey& AttributionDataModel::DataKey::operator=(
DataKey&&) = default;

AttributionDataModel::DataKey::~DataKey() = default;

bool AttributionDataModel::DataKey::operator<(
const AttributionDataModel::DataKey& other) const {
return std::tie(reporting_origin_, source_origin_, destination_origin_) <
std::tie(other.reporting_origin_, other.source_origin_,
other.destination_origin_);
}

} // namespace content
64 changes: 64 additions & 0 deletions content/public/browser/attribution_data_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_PUBLIC_BROWSER_ATTRIBUTION_DATA_MODEL_H_
#define CONTENT_PUBLIC_BROWSER_ATTRIBUTION_DATA_MODEL_H_

#include <vector>

#include "base/functional/callback_forward.h"
#include "content/common/content_export.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/origin.h"

namespace content {

class CONTENT_EXPORT AttributionDataModel {
public:
class DataKey {
public:
DataKey(url::Origin reporting_origin,
absl::optional<url::Origin> source_origin,
absl::optional<url::Origin> destination_origin);

DataKey(const DataKey&);
DataKey(DataKey&&);

DataKey& operator=(const DataKey&);
DataKey& operator=(DataKey&&);

~DataKey();

const url::Origin& reporting_origin() const { return reporting_origin_; }

const absl::optional<url::Origin>& source_origin() const {
return source_origin_;
}

const absl::optional<url::Origin>& destination_origin() const {
return destination_origin_;
}

bool operator<(const DataKey&) const;

private:
url::Origin reporting_origin_;

absl::optional<url::Origin> source_origin_;

absl::optional<url::Origin> destination_origin_;
};

virtual ~AttributionDataModel() = default;

virtual void GetAllDataKeys(
base::OnceCallback<void(std::vector<DataKey>)> callback) = 0;

virtual void RemoveAttributionDataByDataKey(const DataKey& data_key,
base::OnceClosure callback) = 0;
};

} // namespace content

#endif // CONTENT_PUBLIC_BROWSER_ATTRIBUTION_DATA_MODEL_H_
2 changes: 2 additions & 0 deletions content/public/browser/storage_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Origin;

namespace content {

class AttributionDataModel;
class BackgroundSyncContext;
class BrowserContext;
class BrowsingDataFilterBuilder;
Expand Down Expand Up @@ -157,6 +158,7 @@ class CONTENT_EXPORT StoragePartition {
virtual PlatformNotificationContext* GetPlatformNotificationContext() = 0;
virtual InterestGroupManager* GetInterestGroupManager() = 0;
virtual BrowsingTopicsSiteDataManager* GetBrowsingTopicsSiteDataManager() = 0;
virtual AttributionDataModel* GetAttributionDataModel() = 0;

virtual leveldb_proto::ProtoDatabaseProvider* GetProtoDatabaseProvider() = 0;
// Must be set before the first call to GetProtoDatabaseProvider(), or a new
Expand Down
4 changes: 4 additions & 0 deletions content/public/test/test_storage_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ InterestGroupManager* TestStoragePartition::GetInterestGroupManager() {
return nullptr;
}

AttributionDataModel* TestStoragePartition::GetAttributionDataModel() {
return nullptr;
}

BrowsingTopicsSiteDataManager*
TestStoragePartition::GetBrowsingTopicsSiteDataManager() {
return browsing_topics_site_data_manager_;
Expand Down
2 changes: 2 additions & 0 deletions content/public/test/test_storage_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class TestStoragePartition : public StoragePartition {

InterestGroupManager* GetInterestGroupManager() override;

AttributionDataModel* GetAttributionDataModel() override;

void set_browsing_topics_site_data_manager(
BrowsingTopicsSiteDataManager* manager) {
browsing_topics_site_data_manager_ = manager;
Expand Down

0 comments on commit 93a252e

Please sign in to comment.