Skip to content

Commit

Permalink
[ads] [[nodiscard]] code health
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Feb 18, 2025
1 parent e858e32 commit 3162103
Show file tree
Hide file tree
Showing 145 changed files with 332 additions and 280 deletions.
2 changes: 1 addition & 1 deletion browser/ui/views/brave_ads/color_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace brave_ads {

// Converts a string of the form "RRGGBB" to a `SkColor`.
bool RgbStringToSkColor(std::string_view rgb, SkColor* color);
[[nodiscard]] bool RgbStringToSkColor(std::string_view rgb, SkColor* color);

} // namespace brave_ads

Expand Down
2 changes: 1 addition & 1 deletion components/brave_ads/browser/reminder/reminder_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace brave_ads {

base::Value::Dict BuildReminder(mojom::ReminderType mojom_reminder_type);

bool IsReminder(const std::string& placement_id);
[[nodiscard]] bool IsReminder(const std::string& placement_id);

GURL GetReminderTargetUrl();

Expand Down
2 changes: 1 addition & 1 deletion components/brave_ads/core/internal/account/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Account final : public AdsClientNotifierObserver,
void AddObserver(AccountObserver* observer);
void RemoveObserver(AccountObserver* observer);

bool IsUserRewardsSupported() const { return !!user_rewards_; }
[[nodiscard]] bool IsUserRewardsSupported() const { return !!user_rewards_; }

void SetWallet(const std::string& payment_id,
const std::string& recovery_seed_base64);
Expand Down
5 changes: 3 additions & 2 deletions components/brave_ads/core/internal/account/account_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

namespace brave_ads {

bool IsAllowedToDeposit(mojom::AdType mojom_ad_type,
mojom::ConfirmationType mojom_confirmation_type);
[[nodiscard]] bool IsAllowedToDeposit(
mojom::AdType mojom_ad_type,
mojom::ConfirmationType mojom_confirmation_type);

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class ConfirmationQueue final : public AdsClientNotifierObserver,
void AddCallback(const ConfirmationQueueItemInfo& confirmation_queue_item,
bool success);

bool ShouldProcessQueueItem(
[[nodiscard]] bool ShouldProcessQueueItem(
const ConfirmationQueueItemInfo& confirmation_queue_item);
bool ShouldProcessBeforeScheduledQueueItem(
[[nodiscard]] bool ShouldProcessBeforeScheduledQueueItem(
const ConfirmationQueueItemInfo& confirmation_queue_item);
void ProcessQueueItemAfterDelay(
const ConfirmationQueueItemInfo& confirmation_queue_item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ struct IssuersInfo;
void SetIssuers(const IssuersInfo& issuers);
std::optional<IssuersInfo> GetIssuers();

bool IsIssuersValid(const IssuersInfo& issuers);
[[nodiscard]] bool IsIssuersValid(const IssuersInfo& issuers);

bool HasIssuers();
bool HasIssuersChanged(const IssuersInfo& other);
[[nodiscard]] bool HasIssuers();
[[nodiscard]] bool HasIssuersChanged(const IssuersInfo& other);

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace brave_ads {

struct IssuersInfo;

bool IsConfirmationTokenIssuerValid(const IssuersInfo& issuers);
[[nodiscard]] bool IsConfirmationTokenIssuerValid(const IssuersInfo& issuers);

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace brave_ads {

struct IssuersInfo;

bool IsPaymentTokenIssuerValid(const IssuersInfo& issuers);
[[nodiscard]] bool IsPaymentTokenIssuerValid(const IssuersInfo& issuers);

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ namespace cbr {
class PublicKey;
} // namespace cbr

bool TokenIssuerExistsForType(TokenIssuerType token_issuer_type);
[[nodiscard]] bool TokenIssuerExistsForType(TokenIssuerType token_issuer_type);

std::optional<TokenIssuerInfo> GetTokenIssuerForType(
const IssuersInfo& issuers,
TokenIssuerType token_issuer_type);

bool TokenIssuerPublicKeyExistsForType(TokenIssuerType token_issuer_type,
const cbr::PublicKey& public_key);
[[nodiscard]] bool TokenIssuerPublicKeyExistsForType(
TokenIssuerType token_issuer_type,
const cbr::PublicKey& public_key);

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ class ConfirmationTokens final {
void Remove(const ConfirmationTokenList& confirmation_tokens);
void RemoveAll();

bool Exists(const ConfirmationTokenInfo& confirmation_token) const;
[[nodiscard]] bool Exists(
const ConfirmationTokenInfo& confirmation_token) const;

size_t Count() const;

bool IsEmpty() const;
[[nodiscard]] bool IsEmpty() const;

private:
ConfirmationTokenList confirmation_tokens_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ bool RemoveConfirmationToken(const ConfirmationTokenInfo& confirmation_token);
void RemoveConfirmationTokens(const ConfirmationTokenList& confirmation_tokens);
void RemoveAllConfirmationTokens();

bool ConfirmationTokenExists(const ConfirmationTokenInfo& confirmation_token);
[[nodiscard]] bool ConfirmationTokenExists(
const ConfirmationTokenInfo& confirmation_token);

bool ConfirmationTokensIsEmpty();
[[nodiscard]] bool ConfirmationTokensIsEmpty();

size_t ConfirmationTokenCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ bool RemovePaymentToken(const PaymentTokenInfo& payment_token);
void RemovePaymentTokens(const PaymentTokenList& payment_tokens);
void RemoveAllPaymentTokens();

bool PaymentTokenExists(const PaymentTokenInfo& payment_token);
[[nodiscard]] bool PaymentTokenExists(const PaymentTokenInfo& payment_token);

bool PaymentTokensIsEmpty();
[[nodiscard]] bool PaymentTokensIsEmpty();

size_t PaymentTokenCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class PaymentTokens final {
void RemoveTokens(const PaymentTokenList& payment_tokens);
void RemoveAllTokens();

bool TokenExists(const PaymentTokenInfo& payment_token);
[[nodiscard]] bool TokenExists(const PaymentTokenInfo& payment_token);

size_t Count() const;

bool IsEmpty() const;
[[nodiscard]] bool IsEmpty() const;

private:
PaymentTokenList payment_tokens_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ class Time;

namespace brave_ads {

bool DidReconcileTransaction(const TransactionInfo& transaction);
bool DidReconcileTransactionsPreviousMonth(const TransactionList& transactions);
bool DidReconcileTransactionsThisMonth(const TransactionList& transactions);
bool DidReconcileTransactionWithinDateRange(const TransactionInfo& transaction,
base::Time from_time,
base::Time to_time);
[[nodiscard]] bool DidReconcileTransaction(const TransactionInfo& transaction);
[[nodiscard]] bool DidReconcileTransactionsPreviousMonth(
const TransactionList& transactions);
[[nodiscard]] bool DidReconcileTransactionsThisMonth(
const TransactionList& transactions);
[[nodiscard]] bool DidReconcileTransactionWithinDateRange(
const TransactionInfo& transaction,
base::Time from_time,
base::Time to_time);

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RefillConfirmationTokens final {

void GenerateTokens();

bool ShouldRequestSignedTokens() const;
[[nodiscard]] bool ShouldRequestSignedTokens() const;
void RequestSignedTokens();
void RequestSignedTokensCallback(
const mojom::UrlResponseInfo& mojom_url_response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace brave_ads {

bool ShouldRefillConfirmationTokens();
[[nodiscard]] bool ShouldRefillConfirmationTokens();

size_t CalculateAmountOfConfirmationTokensToRefill();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace brave_ads {

namespace {

bool IsValid(const CreativeAdVariant& creative_ad_variant) {
[[nodiscard]] bool IsValid(const CreativeAdVariant& creative_ad_variant) {
return absl::visit(
base::Overloaded{
[](const mojom::CreativeSearchResultAdInfoPtr& mojom_creative_ad)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace brave_ads {

bool ShouldServe();
[[nodiscard]] bool ShouldServe();

bool CanServeIfUserIsActive();
[[nodiscard]] bool CanServeIfUserIsActive();

bool CanServeAtRegularIntervals();
bool ShouldServeAtRegularIntervals();
[[nodiscard]] bool CanServeAtRegularIntervals();
[[nodiscard]] bool ShouldServeAtRegularIntervals();

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ class AdsClientPrefProvider : public PrefProviderInterface {

std::optional<base::Value> GetProfilePref(
const std::string& pref_path) const override;
bool HasProfilePrefPath(const std::string& pref_path) const override;
[[nodiscard]] bool HasProfilePrefPath(
const std::string& pref_path) const override;

std::optional<base::Value> GetLocalStatePref(
const std::string& pref_path) const override;
bool HasLocalStatePrefPath(const std::string& pref_path) const override;
[[nodiscard]] bool HasLocalStatePrefPath(
const std::string& pref_path) const override;

std::optional<base::Value> GetVirtualPref(
const std::string& pref_path) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ class BrowserManager final : public AdsClientNotifierObserver {
void AddObserver(BrowserManagerObserver* observer);
void RemoveObserver(BrowserManagerObserver* observer);

bool IsActive() const { return is_active_.value_or(false); }
[[nodiscard]] bool IsActive() const { return is_active_.value_or(false); }

bool IsInForeground() const { return is_in_foreground_.value_or(false); }
[[nodiscard]] bool IsInForeground() const {
return is_in_foreground_.value_or(false);
}

private:
void NotifyBrowserDidBecomeActive() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ScopedBrowserVersionNumberForTesting final {
~ScopedBrowserVersionNumberForTesting();
};

bool WasBrowserUpgraded();
[[nodiscard]] bool WasBrowserUpgraded();

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct CatalogCreativeSetInfo final {
bool operator==(const CatalogCreativeSetInfo&) const;
bool operator!=(const CatalogCreativeSetInfo&) const;

bool DoesSupportOS() const;
[[nodiscard]] bool DoesSupportOS() const;

std::string id;
int per_day = 0;
Expand Down
4 changes: 2 additions & 2 deletions components/brave_ads/core/internal/catalog/catalog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace brave_ads {

namespace {

bool DoesRequireResourceForNewTabPageAds() {
[[nodiscard]] bool DoesRequireResourceForNewTabPageAds() {
// Require resource only if:
// - The user has opted into new tab page ads and either joined Brave Rewards
// or new tab page ad events should always be triggered.
Expand All @@ -32,7 +32,7 @@ bool DoesRequireResourceForNewTabPageAds() {
ShouldAlwaysTriggerNewTabPageAdEvents());
}

bool DoesRequireResource() {
[[nodiscard]] bool DoesRequireResource() {
// Require resource only if:
// - The user has opted into Brave News ads.
// - The user has opted into new tab page ads and has either joined Brave
Expand Down
6 changes: 3 additions & 3 deletions components/brave_ads/core/internal/catalog/catalog_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void SetCatalogPing(base::TimeDelta ping);
base::Time GetCatalogLastUpdated();
void SetCatalogLastUpdated(base::Time last_updated_at);

bool DoesCatalogExist();
bool HasCatalogChanged(const std::string& catalog_id);
bool HasCatalogExpired();
[[nodiscard]] bool DoesCatalogExist();
[[nodiscard]] bool HasCatalogChanged(const std::string& catalog_id);
[[nodiscard]] bool HasCatalogExpired();

} // namespace brave_ads

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BatchDLEQProof {
bool operator==(const BatchDLEQProof&) const;
bool operator!=(const BatchDLEQProof&) const;

bool has_value() const {
[[nodiscard]] bool has_value() const {
return batch_dleq_proof_ && batch_dleq_proof_.has_value();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BlindedToken {
bool operator==(const BlindedToken&) const;
bool operator!=(const BlindedToken&) const;

bool has_value() const {
[[nodiscard]] bool has_value() const {
return blinded_token_ && blinded_token_.has_value();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PublicKey {
bool operator==(const PublicKey&) const;
bool operator!=(const PublicKey&) const;

bool has_value() const { return public_key_.has_value(); }
[[nodiscard]] bool has_value() const { return public_key_.has_value(); }

challenge_bypass_ristretto::PublicKey& get() {
CHECK(public_key_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SignedToken {
bool operator==(const SignedToken&) const;
bool operator!=(const SignedToken&) const;

bool has_value() const { return signed_token_.has_value(); }
[[nodiscard]] bool has_value() const { return signed_token_.has_value(); }

challenge_bypass_ristretto::SignedToken& get() {
CHECK(signed_token_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SigningKey {
bool operator==(const SigningKey&) const;
bool operator!=(const SigningKey&) const;

bool has_value() const { return signing_key_.has_value(); }
[[nodiscard]] bool has_value() const { return signing_key_.has_value(); }

challenge_bypass_ristretto::SigningKey& get() {
CHECK(signing_key_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Token {
bool operator==(const Token&) const;
bool operator!=(const Token&) const;

bool has_value() const { return token_.has_value(); }
[[nodiscard]] bool has_value() const { return token_.has_value(); }

challenge_bypass_ristretto::Token& get() {
CHECK(token_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TokenPreimage {
bool operator==(const TokenPreimage&) const;
bool operator!=(const TokenPreimage&) const;

bool has_value() const {
[[nodiscard]] bool has_value() const {
return token_preimage_ && token_preimage_.has_value();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class UnblindedToken {
bool operator==(const UnblindedToken&) const;
bool operator!=(const UnblindedToken&) const;

bool has_value() const {
[[nodiscard]] bool has_value() const {
return unblinded_token_ && unblinded_token_.has_value();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class VerificationSignature {
bool operator==(const VerificationSignature&) const;
bool operator!=(const VerificationSignature&) const;

bool has_value() const {
[[nodiscard]] bool has_value() const {
return verification_signature_ && verification_signature_.has_value();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace brave_ads {

namespace {

bool DoesSupportCountryCode() {
[[nodiscard]] bool DoesSupportCountryCode() {
return UserHasJoinedBraveRewards();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace brave_ads::database {

// Returns true if the transaction result is a success.
bool IsTransactionSuccessful(
[[nodiscard]] bool IsTransactionSuccessful(
const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result);

// Run a database transaction. The callback takes one argument -
Expand Down
Loading

0 comments on commit 3162103

Please sign in to comment.