Skip to content

Commit

Permalink
Merge pull request #20395 from brave/issues/31564
Browse files Browse the repository at this point in the history
Add additional Brave Ads Griffin support
  • Loading branch information
tmancey authored Oct 5, 2023
2 parents a6a16e4 + 31f42a7 commit 0ff6e24
Show file tree
Hide file tree
Showing 73 changed files with 1,169 additions and 212 deletions.
2 changes: 1 addition & 1 deletion browser/ntp_background/ntp_p3a_helper_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void NTPP3AHelperImpl::OnLandingStartCheck(
return;
}
landing_check_timer_.Start(
FROM_HERE, brave_ads::kTransferredAfter.Get(),
FROM_HERE, brave_ads::kTransferAfter.Get(),
base::BindOnce(&NTPP3AHelperImpl::OnLandingEndCheck,
base::Unretained(this), creative_instance_id,
*last_tab_hostname_));
Expand Down
2 changes: 1 addition & 1 deletion components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ void AdsServiceImpl::CheckIdleStateAfterDelay() {
}

void AdsServiceImpl::CheckIdleState() {
const int64_t idle_threshold = kIdleThreshold.Get().InSeconds();
const int64_t idle_threshold = kUserIdleDetectionThreshold.Get().InSeconds();
ProcessIdleState(ui::CalculateIdleState(static_cast<int>(idle_threshold)),
last_idle_time_);
last_idle_time_ = base::Seconds(ui::CalculateIdleTime());
Expand Down
12 changes: 10 additions & 2 deletions components/brave_ads/core/internal/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ static_library("internal") {
"account/confirmations/confirmations.cc",
"account/confirmations/confirmations.h",
"account/confirmations/confirmations_delegate.h",
"account/confirmations/confirmations_feature.cc",
"account/confirmations/confirmations_feature.h",
"account/confirmations/confirmations_util.cc",
"account/confirmations/confirmations_util.h",
"account/confirmations/non_reward/non_reward_confirmation_util.cc",
Expand Down Expand Up @@ -73,6 +75,8 @@ static_library("internal") {
"account/issuers/issuer_info.h",
"account/issuers/issuer_types.h",
"account/issuers/issuers_constants.h",
"account/issuers/issuers_feature.cc",
"account/issuers/issuers_feature.h",
"account/issuers/issuers_info.cc",
"account/issuers/issuers_info.h",
"account/issuers/issuers_url_request.cc",
Expand Down Expand Up @@ -200,6 +204,8 @@ static_library("internal") {
"account/utility/redeem_payment_tokens/redeem_payment_tokens.cc",
"account/utility/redeem_payment_tokens/redeem_payment_tokens.h",
"account/utility/redeem_payment_tokens/redeem_payment_tokens_delegate.h",
"account/utility/redeem_payment_tokens/redeem_payment_tokens_feature.cc",
"account/utility/redeem_payment_tokens/redeem_payment_tokens_feature.h",
"account/utility/redeem_payment_tokens/redeem_payment_tokens_util.cc",
"account/utility/redeem_payment_tokens/redeem_payment_tokens_util.h",
"account/utility/redeem_payment_tokens/url_request_builders/redeem_payment_tokens_url_request_builder.cc",
Expand Down Expand Up @@ -289,6 +295,8 @@ static_library("internal") {
"catalog/catalog.cc",
"catalog/catalog.h",
"catalog/catalog_constants.h",
"catalog/catalog_feature.cc",
"catalog/catalog_feature.h",
"catalog/catalog_info.cc",
"catalog/catalog_info.h",
"catalog/catalog_observer.h",
Expand Down Expand Up @@ -707,7 +715,8 @@ static_library("internal") {
"history/filters/history_filter_factory.cc",
"history/filters/history_filter_factory.h",
"history/filters/history_filter_interface.h",
"history/history_constants.h",
"history/history_feature.cc",
"history/history_feature.h",
"history/history_item_info.cc",
"history/history_item_util.cc",
"history/history_item_util.h",
Expand Down Expand Up @@ -1164,7 +1173,6 @@ static_library("internal") {
"units/search_result_ad/search_result_ad_handler.h",
"user/user_attention/user_activity/page_transition_util.cc",
"user/user_attention/user_activity/page_transition_util.h",
"user/user_attention/user_activity/user_activity_constants.h",
"user/user_attention/user_activity/user_activity_event_info.cc",
"user/user_attention/user_activity/user_activity_event_info.h",
"user/user_attention/user_activity/user_activity_event_types.h",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_ads/core/internal/account/confirmations/confirmations_feature.h" // IWYU pragma: keep

namespace brave_ads {

BASE_FEATURE(kConfirmationsFeature,
"Confirmations",
base::FEATURE_ENABLED_BY_DEFAULT);

} // namespace brave_ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_CONFIRMATIONS_CONFIRMATIONS_FEATURE_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_CONFIRMATIONS_CONFIRMATIONS_FEATURE_H_

#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"

namespace base {
class TimeDelta;
} // namespace base

namespace brave_ads {

BASE_DECLARE_FEATURE(kConfirmationsFeature);

constexpr base::FeatureParam<base::TimeDelta> kProcessConfirmationAfter{
&kConfirmationsFeature, "process_after", base::Seconds(15)};

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_CONFIRMATIONS_CONFIRMATIONS_FEATURE_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_ads/core/internal/account/confirmations/confirmations_feature.h"

#include "base/test/scoped_feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"

// npm run test -- brave_unit_tests --filter=BraveAds*

namespace brave_ads {

TEST(BraveAdsConfirmationsFeatureTest, IsEnabled) {
// Arrange

// Act

// Assert
EXPECT_TRUE(base::FeatureList::IsEnabled(kConfirmationsFeature));
}

TEST(BraveAdsConfirmationsFeatureTest, IsDisabled) {
// Arrange
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndDisableFeature(kConfirmationsFeature);

// Act

// Assert
EXPECT_FALSE(base::FeatureList::IsEnabled(kConfirmationsFeature));
}

TEST(BraveAdsConfirmationsFeatureTest, ProcessConfirmationAfter) {
// Arrange
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeatureWithParameters(
kConfirmationsFeature, {{"process_after", "3h"}});
// Act

// Assert
EXPECT_EQ(base::Hours(3), kProcessConfirmationAfter.Get());
}

TEST(BraveAdsConfirmationsFeatureTest, DefaultProcessConfirmationAfter) {
// Arrange

// Act

// Assert
EXPECT_EQ(base::Seconds(15), kProcessConfirmationAfter.Get());
}

TEST(BraveAdsConfirmationsFeatureTest,
DefaultProcessConfirmationAfterWhenDisabled) {
// Arrange
base::test::ScopedFeatureList scoped_feature_list;

// Act

// Assert
EXPECT_EQ(base::Seconds(15), kProcessConfirmationAfter.Get());
}

} // namespace brave_ads
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "brave/components/brave_ads/core/internal/account/confirmations/confirmation_info.h"
#include "brave/components/brave_ads/core/internal/account/confirmations/confirmations_feature.h"
#include "brave/components/brave_ads/core/internal/account/confirmations/confirmations_util.h"
#include "brave/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_delegate.h"
#include "brave/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_util.h"
Expand All @@ -18,10 +19,6 @@

namespace brave_ads {

namespace {
constexpr base::TimeDelta kProcessQueueItemAfter = base::Seconds(15);
} // namespace

ConfirmationQueue::ConfirmationQueue() {
AdsClientHelper::AddObserver(this);
}
Expand Down Expand Up @@ -52,7 +49,7 @@ bool ConfirmationQueue::ShouldProcessQueueItem() {
void ConfirmationQueue::ProcessQueueItemAfterDelay(
const ConfirmationInfo& confirmation) {
const base::Time process_at = timer_.StartWithPrivacy(
FROM_HERE, kProcessQueueItemAfter,
FROM_HERE, kProcessConfirmationAfter.Get(),
base::BindOnce(&ConfirmationQueue::ProcessQueueItem,
base::Unretained(this), confirmation));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "brave/components/brave_ads/core/internal/account/issuers/issuer_info.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuer_types.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_constants.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_feature.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_info.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_util.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
Expand All @@ -21,7 +21,8 @@ bool IsConfirmationsIssuerValid(const IssuersInfo& issuers) {
return false;
}

return confirmations_issuer->public_keys.size() <= kMaximumIssuerPublicKeys;
return confirmations_issuer->public_keys.size() <=
static_cast<size_t>(kMaximumIssuerPublicKeys.Get());
}

} // namespace brave_ads
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "base/uuid.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuer_info.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_constants.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_feature.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_info.h"
#include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h"

Expand All @@ -22,7 +22,7 @@ TEST_F(BraveAdsConfirmationsIssuerUtilTest, IsValid) {
IssuerInfo issuer;
issuer.type = IssuerType::kConfirmations;

for (int i = 0; i < kMaximumIssuerPublicKeys; i++) {
for (int i = 0; i < kMaximumIssuerPublicKeys.Get(); i++) {
issuer.public_keys.insert(
{/*public_key*/ base::Uuid::GenerateRandomV4().AsLowercaseString(),
/*associated_value*/ 0.1});
Expand All @@ -42,7 +42,7 @@ TEST_F(BraveAdsConfirmationsIssuerUtilTest, IsInvalid) {
IssuerInfo issuer;
issuer.type = IssuerType::kConfirmations;

for (int i = 0; i < kMaximumIssuerPublicKeys + 1; i++) {
for (int i = 0; i < kMaximumIssuerPublicKeys.Get() + 1; i++) {
issuer.public_keys.insert(
{/*public_key*/ base::Uuid::GenerateRandomV4().AsLowercaseString(),
/*associated_value*/ 0.1});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace brave_ads {

constexpr int kIssuersServerVersion = 3;

constexpr int kMaximumIssuerPublicKeys = 6;

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_ISSUERS_ISSUERS_CONSTANTS_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_ads/core/internal/account/issuers/issuers_feature.h" // IWYU pragma: keep

namespace brave_ads {

BASE_FEATURE(kIssuersFeature, "Issuers", base::FEATURE_ENABLED_BY_DEFAULT);

} // namespace brave_ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_ISSUERS_ISSUERS_FEATURE_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_ISSUERS_ISSUERS_FEATURE_H_

#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"

namespace brave_ads {

BASE_DECLARE_FEATURE(kIssuersFeature);

constexpr base::FeatureParam<int> kMaximumIssuerPublicKeys{
&kIssuersFeature, "maximum_public_keys", 6};

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_ISSUERS_ISSUERS_FEATURE_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_ads/core/internal/account/issuers/issuers_feature.h"

#include "base/test/scoped_feature_list.h"
#include "testing/gtest/include/gtest/gtest.h"

// npm run test -- brave_unit_tests --filter=BraveAds*

namespace brave_ads {

TEST(BraveAdsIssuersFeatureTest, IsEnabled) {
// Arrange

// Act

// Assert
EXPECT_TRUE(base::FeatureList::IsEnabled(kIssuersFeature));
}

TEST(BraveAdsIssuersFeatureTest, IsDisabled) {
// Arrange
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndDisableFeature(kIssuersFeature);

// Act

// Assert
EXPECT_FALSE(base::FeatureList::IsEnabled(kIssuersFeature));
}

TEST(BraveAdsIssuersFeatureTest, MaximumIssuerPublicKeys) {
// Arrange
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeatureWithParameters(
kIssuersFeature, {{"maximum_public_keys", "1"}});

// Act

// Assert
EXPECT_EQ(1, kMaximumIssuerPublicKeys.Get());
}

TEST(BraveAdsIssuersFeatureTest, DefaultMaximumIssuerPublicKeys) {
// Arrange

// Act

// Assert
EXPECT_EQ(6, kMaximumIssuerPublicKeys.Get());
}

TEST(BraveAdsIssuersFeatureTest, DefaultMaximumIssuerPublicKeysWhenDisabled) {
// Arrange
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndDisableFeature(kIssuersFeature);

// Act

// Assert
EXPECT_EQ(6, kMaximumIssuerPublicKeys.Get());
}

} // namespace brave_ads
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "base/containers/flat_map.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuer_info.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuer_types.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_constants.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_feature.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_info.h"
#include "brave/components/brave_ads/core/internal/account/issuers/issuers_util.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
Expand All @@ -28,7 +28,7 @@ bool IsPaymentsIssuerValid(const IssuersInfo& issuers) {
buckets[associated_value]++;

const int count = buckets[associated_value];
if (count > kMaximumIssuerPublicKeys) {
if (count > kMaximumIssuerPublicKeys.Get()) {
return false;
}
}
Expand Down
Loading

0 comments on commit 0ff6e24

Please sign in to comment.