From 316210385e388ebeaf8ad34a499ae36621f9924a Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Tue, 18 Feb 2025 10:30:42 -0500 Subject: [PATCH] [ads] [[nodiscard]] code health --- browser/ui/views/brave_ads/color_util.h | 2 +- .../browser/reminder/reminder_util.h | 2 +- .../brave_ads/core/internal/account/account.h | 2 +- .../core/internal/account/account_util.h | 5 +- .../confirmations/queue/confirmation_queue.h | 4 +- .../internal/account/issuers/issuers_util.h | 6 +- .../confirmation_token_issuer_util.h | 2 +- .../token_issuers/payment_token_issuer_util.h | 2 +- .../issuers/token_issuers/token_issuer_util.h | 7 +- .../confirmation_tokens/confirmation_tokens.h | 5 +- .../confirmation_tokens_util.h | 5 +- .../payment_tokens/payment_token_util.h | 4 +- .../tokens/payment_tokens/payment_tokens.h | 4 +- .../reconciled_transactions_util.h | 15 +++-- .../refill_confirmation_tokens.h | 2 +- .../refill_confirmation_tokens_util.h | 2 +- .../internal/ad_units/creative_ad_cache.cc | 2 +- .../notification_ad_handler_util.h | 8 +-- .../ads_client/ads_client_pref_provider.h | 6 +- .../application_state/browser_manager.h | 6 +- .../internal/application_state/browser_util.h | 2 +- .../creative_set/catalog_creative_set_info.h | 2 +- .../core/internal/catalog/catalog.cc | 4 +- .../core/internal/catalog/catalog_util.h | 6 +- .../batch_dleq_proof.h | 2 +- .../blinded_token.h | 2 +- .../challenge_bypass_ristretto/public_key.h | 2 +- .../challenge_bypass_ristretto/signed_token.h | 2 +- .../challenge_bypass_ristretto/signing_key.h | 2 +- .../common/challenge_bypass_ristretto/token.h | 2 +- .../token_preimage.h | 2 +- .../unblinded_token.h | 2 +- .../verification_signature.h | 2 +- .../common/country_code/country_code.cc | 2 +- .../database/database_transaction_util.h | 2 +- .../functional/once_closure_task_queue.h | 4 +- .../common/net/http/http_status_code_util.h | 2 +- .../common/platform/platform_helper_android.h | 2 +- .../common/platform/platform_helper_ios.h | 2 +- .../common/platform/platform_helper_linux.h | 2 +- .../common/platform/platform_helper_mac.h | 2 +- .../common/platform/platform_helper_win.h | 2 +- .../search_engine_results_page_util.h | 2 +- .../common/search_engine/search_engine_util.h | 2 +- .../common/subdivision/subdivision.cc | 4 +- ...al_state_pref_storage_test_util_internal.h | 4 +- ...ocal_state_pref_value_test_util_internal.h | 2 +- .../profile_pref_storage_test_util_internal.h | 4 +- .../profile_pref_value_test_util_internal.h | 2 +- .../url_response_test_util_internal.cc | 3 +- .../core/internal/common/test/test_base.h | 2 +- .../common/time/time_constraint_util.h | 2 +- .../internal/common/timer/backoff_timer.h | 2 +- .../core/internal/common/timer/timer.h | 2 +- .../core/internal/common/url/url_util.h | 14 ++-- .../internal/common/url/url_util_internal.h | 8 +-- .../notification_ad_manager.h | 2 +- .../core/internal/database/database.h | 4 +- .../deprecated/client/client_state_manager.cc | 1 - .../confirmation_state_manager.h | 2 +- .../debug_command_line_switch_parser_util.h | 2 +- .../internal/flags/debug/debug_flag_util.h | 2 +- .../did_override_command_line_flag_util.h | 2 +- ...override_command_line_switch_values_util.h | 2 +- .../did_override_command_line_switches_util.h | 2 +- ...override_features_from_command_line_util.h | 2 +- .../flags/environment/environment_flag_util.h | 2 +- .../client/legacy_client_migration_util.h | 2 +- .../legacy_confirmation_migration_util.h | 2 +- .../core/internal/ml/data/vector_data.h | 2 +- .../text_processing/text_processing.h | 6 +- .../core/internal/prefs/pref_path_util.h | 15 +++-- .../brave_ads/core/internal/prefs/pref_util.h | 8 +-- ...ked_same_ad_multiple_times_reminder_util.h | 7 +- .../core/internal/reminders/reminders.h | 2 +- .../core/internal/segments/segment_util.h | 4 +- .../anti_targeting_exclusion_rule.h | 2 +- .../anti_targeting_exclusion_rule_util.h | 5 +- .../exclusion_rules/daypart_exclusion_rule.cc | 2 +- .../daypart_exclusion_rule_util.h | 6 +- .../exclusion_rules/dislike_exclusion_rule.cc | 2 +- .../dislike_segment_exclusion_rule.cc | 2 +- .../exclusion_rules/exclusion_rule_util.h | 65 ++++++++++--------- .../exclusion_rules/exclusion_rules_base.cc | 4 +- .../exclusion_rules/exclusion_rules_base.h | 4 +- .../exclusion_rules/exclusion_rules_util.h | 2 +- .../marked_as_inappropriate_exclusion_rule.cc | 2 +- ...otification_ad_dismissed_exclusion_rule.cc | 2 +- .../subdivision_targeting_exclusion_rule.cc | 8 ++- .../subdivision_targeting_exclusion_rule.h | 2 +- .../total_max_exclusion_rule.cc | 4 +- .../serving/eligible_ads/pacing/pacing_util.h | 2 +- .../serving/inline_content_ad_serving.h | 4 +- .../serving/new_tab_page_ad_serving.h | 4 +- .../serving/notification_ad_serving.h | 4 +- .../serving/notification_ad_serving_util.h | 2 +- .../ads_per_day_permission_rule.h | 4 +- .../ads_per_hour_permission_rule.h | 5 +- .../browser_is_active_permission_rule.h | 2 +- .../catalog_permission_rule.h | 2 +- .../command_line_permission_rule.h | 2 +- .../confirmation_tokens_permission_rule.h | 2 +- .../do_not_disturb_permission_rule.h | 2 +- .../full_screen_mode_permission_rule.h | 2 +- .../issuers_permission_rule.h | 2 +- .../permission_rules/media_permission_rule.h | 2 +- .../minimum_wait_time_permission_rule.h | 5 +- .../network_connection_permission_rule.h | 2 +- .../can_show_notifications_permission_rule.h | 2 +- .../user_activity_permission_rule.h | 2 +- .../epoch_operator_condition_matcher_util.h | 5 +- ...perator_condition_matcher_util_internal.cc | 2 +- ...operator_condition_matcher_util_internal.h | 2 +- ...umerical_operator_condition_matcher_util.h | 5 +- .../matchers/pattern_condition_matcher_util.h | 3 +- .../matchers/regex_condition_matcher_util.h | 3 +- .../core/internal/settings/settings.h | 10 +-- .../core/internal/tabs/tab_manager.h | 8 ++- .../resource/anti_targeting_resource.cc | 4 +- .../resource/anti_targeting_resource.h | 2 +- .../purchase_intent_processor.h | 2 +- .../resource/purchase_intent_resource.cc | 2 +- .../resource/purchase_intent_resource.h | 2 +- .../resource/text_classification_resource.cc | 2 +- .../resource/text_classification_resource.h | 2 +- .../subdivision/subdivision_targeting.cc | 4 +- .../subdivision/subdivision_targeting.h | 6 +- .../subdivision/subdivision_targeting_util.h | 7 +- .../user_activity/page_transition_util.h | 12 ++-- .../user_activity_scoring_util.h | 2 +- .../user_idle_detection_util.h | 4 +- .../ad_events/ad_event_handler_util.h | 34 +++++----- .../search_result_ad_event_handler_util.h | 9 +-- .../conversions/conversions_util.h | 7 +- .../conversions/conversions_util_internal.h | 2 +- .../resource/conversion_resource.cc | 2 +- .../resource/conversion_resource.h | 2 +- ...creative_set_conversion_url_pattern_util.h | 2 +- .../user_engagement/reactions/reactions.h | 5 +- .../user_engagement/site_visit/site_visit.h | 2 +- .../site_visit/site_visit_util.h | 6 +- .../brave_ads/core/public/ads_feature.h | 8 +-- components/brave_ads/core/public/ads_util.h | 2 +- .../core/public/prefs/pref_provider.h | 6 +- .../condition_matcher_util.h | 5 +- 145 files changed, 332 insertions(+), 280 deletions(-) diff --git a/browser/ui/views/brave_ads/color_util.h b/browser/ui/views/brave_ads/color_util.h index 4f92427c0212..eab079953077 100644 --- a/browser/ui/views/brave_ads/color_util.h +++ b/browser/ui/views/brave_ads/color_util.h @@ -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 diff --git a/components/brave_ads/browser/reminder/reminder_util.h b/components/brave_ads/browser/reminder/reminder_util.h index cceceefbef2a..54bb70d03af0 100644 --- a/components/brave_ads/browser/reminder/reminder_util.h +++ b/components/brave_ads/browser/reminder/reminder_util.h @@ -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(); diff --git a/components/brave_ads/core/internal/account/account.h b/components/brave_ads/core/internal/account/account.h index 801e3d257b0e..55a3209ca97e 100644 --- a/components/brave_ads/core/internal/account/account.h +++ b/components/brave_ads/core/internal/account/account.h @@ -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); diff --git a/components/brave_ads/core/internal/account/account_util.h b/components/brave_ads/core/internal/account/account_util.h index a3ebaf0c72b6..cb6a59c575e2 100644 --- a/components/brave_ads/core/internal/account/account_util.h +++ b/components/brave_ads/core/internal/account/account_util.h @@ -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 diff --git a/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue.h b/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue.h index 98b5a972b307..02874117b91f 100644 --- a/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue.h +++ b/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue.h @@ -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); diff --git a/components/brave_ads/core/internal/account/issuers/issuers_util.h b/components/brave_ads/core/internal/account/issuers/issuers_util.h index 078da6ef3160..b38977e7f3ff 100644 --- a/components/brave_ads/core/internal/account/issuers/issuers_util.h +++ b/components/brave_ads/core/internal/account/issuers/issuers_util.h @@ -15,10 +15,10 @@ struct IssuersInfo; void SetIssuers(const IssuersInfo& issuers); std::optional 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 diff --git a/components/brave_ads/core/internal/account/issuers/token_issuers/confirmation_token_issuer_util.h b/components/brave_ads/core/internal/account/issuers/token_issuers/confirmation_token_issuer_util.h index de86e6723f0f..417707cf2510 100644 --- a/components/brave_ads/core/internal/account/issuers/token_issuers/confirmation_token_issuer_util.h +++ b/components/brave_ads/core/internal/account/issuers/token_issuers/confirmation_token_issuer_util.h @@ -10,7 +10,7 @@ namespace brave_ads { struct IssuersInfo; -bool IsConfirmationTokenIssuerValid(const IssuersInfo& issuers); +[[nodiscard]] bool IsConfirmationTokenIssuerValid(const IssuersInfo& issuers); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/issuers/token_issuers/payment_token_issuer_util.h b/components/brave_ads/core/internal/account/issuers/token_issuers/payment_token_issuer_util.h index d78b461ee80d..2f66c0a7c64e 100644 --- a/components/brave_ads/core/internal/account/issuers/token_issuers/payment_token_issuer_util.h +++ b/components/brave_ads/core/internal/account/issuers/token_issuers/payment_token_issuer_util.h @@ -10,7 +10,7 @@ namespace brave_ads { struct IssuersInfo; -bool IsPaymentTokenIssuerValid(const IssuersInfo& issuers); +[[nodiscard]] bool IsPaymentTokenIssuerValid(const IssuersInfo& issuers); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/issuers/token_issuers/token_issuer_util.h b/components/brave_ads/core/internal/account/issuers/token_issuers/token_issuer_util.h index 3f6631862f59..a2986cf2f6d5 100644 --- a/components/brave_ads/core/internal/account/issuers/token_issuers/token_issuer_util.h +++ b/components/brave_ads/core/internal/account/issuers/token_issuers/token_issuer_util.h @@ -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 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 diff --git a/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens.h b/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens.h index bc71dd2c422a..10f9aa081d21 100644 --- a/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens.h +++ b/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens.h @@ -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_; diff --git a/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens_util.h b/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens_util.h index c3cdeb863986..d6d9d5071a83 100644 --- a/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens_util.h +++ b/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens_util.h @@ -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(); diff --git a/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_util.h b/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_util.h index 85518f90e24c..dc3d1682a23e 100644 --- a/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_util.h +++ b/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_util.h @@ -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(); diff --git a/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens.h b/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens.h index 7bfa4df09ce2..07ab16b28e1c 100644 --- a/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens.h +++ b/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens.h @@ -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_; diff --git a/components/brave_ads/core/internal/account/transactions/reconciled_transactions_util.h b/components/brave_ads/core/internal/account/transactions/reconciled_transactions_util.h index abcd4094006b..4aa48d4117fc 100644 --- a/components/brave_ads/core/internal/account/transactions/reconciled_transactions_util.h +++ b/components/brave_ads/core/internal/account/transactions/reconciled_transactions_util.h @@ -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 diff --git a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.h b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.h index 2f74e341a657..8347f677809a 100644 --- a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.h +++ b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.h @@ -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); diff --git a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens_util.h b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens_util.h index af6f723b7d71..66368c921a3c 100644 --- a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens_util.h +++ b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens_util.h @@ -10,7 +10,7 @@ namespace brave_ads { -bool ShouldRefillConfirmationTokens(); +[[nodiscard]] bool ShouldRefillConfirmationTokens(); size_t CalculateAmountOfConfirmationTokensToRefill(); diff --git a/components/brave_ads/core/internal/ad_units/creative_ad_cache.cc b/components/brave_ads/core/internal/ad_units/creative_ad_cache.cc index 139e559e909e..a2202e56944b 100644 --- a/components/brave_ads/core/internal/ad_units/creative_ad_cache.cc +++ b/components/brave_ads/core/internal/ad_units/creative_ad_cache.cc @@ -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) diff --git a/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_handler_util.h b/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_handler_util.h index 2ef34baabd4b..47102a7c1705 100644 --- a/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_handler_util.h +++ b/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_handler_util.h @@ -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 diff --git a/components/brave_ads/core/internal/ads_client/ads_client_pref_provider.h b/components/brave_ads/core/internal/ads_client/ads_client_pref_provider.h index b3ddff2327ce..d3c63c3cb88a 100644 --- a/components/brave_ads/core/internal/ads_client/ads_client_pref_provider.h +++ b/components/brave_ads/core/internal/ads_client/ads_client_pref_provider.h @@ -29,11 +29,13 @@ class AdsClientPrefProvider : public PrefProviderInterface { std::optional 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 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 GetVirtualPref( const std::string& pref_path) const override; diff --git a/components/brave_ads/core/internal/application_state/browser_manager.h b/components/brave_ads/core/internal/application_state/browser_manager.h index 7f0c96e31bab..8a7323725757 100644 --- a/components/brave_ads/core/internal/application_state/browser_manager.h +++ b/components/brave_ads/core/internal/application_state/browser_manager.h @@ -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; diff --git a/components/brave_ads/core/internal/application_state/browser_util.h b/components/brave_ads/core/internal/application_state/browser_util.h index e4801a982d1c..c1c88e606926 100644 --- a/components/brave_ads/core/internal/application_state/browser_util.h +++ b/components/brave_ads/core/internal/application_state/browser_util.h @@ -19,7 +19,7 @@ class ScopedBrowserVersionNumberForTesting final { ~ScopedBrowserVersionNumberForTesting(); }; -bool WasBrowserUpgraded(); +[[nodiscard]] bool WasBrowserUpgraded(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/catalog/campaign/creative_set/catalog_creative_set_info.h b/components/brave_ads/core/internal/catalog/campaign/creative_set/catalog_creative_set_info.h index 426a91840cca..3ab74fc3e215 100644 --- a/components/brave_ads/core/internal/catalog/campaign/creative_set/catalog_creative_set_info.h +++ b/components/brave_ads/core/internal/catalog/campaign/creative_set/catalog_creative_set_info.h @@ -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; diff --git a/components/brave_ads/core/internal/catalog/catalog.cc b/components/brave_ads/core/internal/catalog/catalog.cc index 7c88b5984029..d36b9e10e6d3 100644 --- a/components/brave_ads/core/internal/catalog/catalog.cc +++ b/components/brave_ads/core/internal/catalog/catalog.cc @@ -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. @@ -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 diff --git a/components/brave_ads/core/internal/catalog/catalog_util.h b/components/brave_ads/core/internal/catalog/catalog_util.h index ea255abeffbd..68905aadc58a 100644 --- a/components/brave_ads/core/internal/catalog/catalog_util.h +++ b/components/brave_ads/core/internal/catalog/catalog_util.h @@ -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 diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/batch_dleq_proof.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/batch_dleq_proof.h index 065c9d69d646..b37a0301b183 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/batch_dleq_proof.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/batch_dleq_proof.h @@ -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(); } diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token.h index 8c4abacc1436..7b9c50b17f5e 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token.h @@ -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(); } diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/public_key.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/public_key.h index 544c214f33b7..f6c77ca5a3fd 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/public_key.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/public_key.h @@ -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_); diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token.h index 43071c4202ad..d15b3caa4f4a 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token.h @@ -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_); diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signing_key.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signing_key.h index 1f3f1ef4d2ff..11cdc5cfe2a2 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signing_key.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signing_key.h @@ -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_); diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h index 5e53434f322d..dc3e4a420fe0 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h @@ -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_); diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token_preimage.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token_preimage.h index 6e8bcbc49646..83484b080488 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token_preimage.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token_preimage.h @@ -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(); } diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h index cb967b81eee0..404ad10aee4a 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h @@ -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(); } diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/verification_signature.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/verification_signature.h index 64ec8e73e482..06757a3243f8 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/verification_signature.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/verification_signature.h @@ -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(); } diff --git a/components/brave_ads/core/internal/common/country_code/country_code.cc b/components/brave_ads/core/internal/common/country_code/country_code.cc index f8c352e705bf..c3f5cd32d0ad 100644 --- a/components/brave_ads/core/internal/common/country_code/country_code.cc +++ b/components/brave_ads/core/internal/common/country_code/country_code.cc @@ -20,7 +20,7 @@ namespace brave_ads { namespace { -bool DoesSupportCountryCode() { +[[nodiscard]] bool DoesSupportCountryCode() { return UserHasJoinedBraveRewards(); } diff --git a/components/brave_ads/core/internal/common/database/database_transaction_util.h b/components/brave_ads/core/internal/common/database/database_transaction_util.h index 55dc590652d2..e8d3b161a038 100644 --- a/components/brave_ads/core/internal/common/database/database_transaction_util.h +++ b/components/brave_ads/core/internal/common/database/database_transaction_util.h @@ -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 - diff --git a/components/brave_ads/core/internal/common/functional/once_closure_task_queue.h b/components/brave_ads/core/internal/common/functional/once_closure_task_queue.h index 8a36c402ef54..bd6ec2999306 100644 --- a/components/brave_ads/core/internal/common/functional/once_closure_task_queue.h +++ b/components/brave_ads/core/internal/common/functional/once_closure_task_queue.h @@ -23,9 +23,9 @@ class OnceClosureTaskQueue final { void Add(base::OnceClosure closure); void FlushAndStopQueueing(); - bool should_queue() const { return should_queue_; } + [[nodiscard]] bool should_queue() const { return should_queue_; } - bool empty() const { return queue_.empty(); } + [[nodiscard]] bool empty() const { return queue_.empty(); } private: bool should_queue_ = true; diff --git a/components/brave_ads/core/internal/common/net/http/http_status_code_util.h b/components/brave_ads/core/internal/common/net/http/http_status_code_util.h index 1ba7be036788..0d5cbc217b80 100644 --- a/components/brave_ads/core/internal/common/net/http/http_status_code_util.h +++ b/components/brave_ads/core/internal/common/net/http/http_status_code_util.h @@ -11,7 +11,7 @@ namespace brave_ads { -bool IsSuccessfulHttpStatusCode(int http_status_code); +[[nodiscard]] bool IsSuccessfulHttpStatusCode(int http_status_code); std::optional HttpStatusCodeToString(int http_status_code); diff --git a/components/brave_ads/core/internal/common/platform/platform_helper_android.h b/components/brave_ads/core/internal/common/platform/platform_helper_android.h index 955a81992c3d..56dd29e7774a 100644 --- a/components/brave_ads/core/internal/common/platform/platform_helper_android.h +++ b/components/brave_ads/core/internal/common/platform/platform_helper_android.h @@ -22,7 +22,7 @@ class PlatformHelperAndroid final : public PlatformHelper { private: // PlatformHelper: - bool IsMobile() const override; + [[nodiscard]] bool IsMobile() const override; std::string GetName() const override; PlatformType GetType() const override; }; diff --git a/components/brave_ads/core/internal/common/platform/platform_helper_ios.h b/components/brave_ads/core/internal/common/platform/platform_helper_ios.h index 7dd317321457..18c7750489f9 100644 --- a/components/brave_ads/core/internal/common/platform/platform_helper_ios.h +++ b/components/brave_ads/core/internal/common/platform/platform_helper_ios.h @@ -22,7 +22,7 @@ class PlatformHelperIos final : public PlatformHelper { private: // PlatformHelper: - bool IsMobile() const override; + [[nodiscard]] bool IsMobile() const override; std::string GetName() const override; PlatformType GetType() const override; }; diff --git a/components/brave_ads/core/internal/common/platform/platform_helper_linux.h b/components/brave_ads/core/internal/common/platform/platform_helper_linux.h index 5c3c3ee678b7..26e7cca9b016 100644 --- a/components/brave_ads/core/internal/common/platform/platform_helper_linux.h +++ b/components/brave_ads/core/internal/common/platform/platform_helper_linux.h @@ -22,7 +22,7 @@ class PlatformHelperLinux final : public PlatformHelper { private: // PlatformHelper: - bool IsMobile() const override; + [[nodiscard]] bool IsMobile() const override; std::string GetName() const override; PlatformType GetType() const override; }; diff --git a/components/brave_ads/core/internal/common/platform/platform_helper_mac.h b/components/brave_ads/core/internal/common/platform/platform_helper_mac.h index 59dfe658a9c5..62574a111725 100644 --- a/components/brave_ads/core/internal/common/platform/platform_helper_mac.h +++ b/components/brave_ads/core/internal/common/platform/platform_helper_mac.h @@ -26,7 +26,7 @@ class PlatformHelperMac final : public PlatformHelper { private: // PlatformHelper: - bool IsMobile() const override; + [[nodiscard]] bool IsMobile() const override; std::string GetName() const override; PlatformType GetType() const override; }; diff --git a/components/brave_ads/core/internal/common/platform/platform_helper_win.h b/components/brave_ads/core/internal/common/platform/platform_helper_win.h index 4e83fe937552..5618918d28be 100644 --- a/components/brave_ads/core/internal/common/platform/platform_helper_win.h +++ b/components/brave_ads/core/internal/common/platform/platform_helper_win.h @@ -22,7 +22,7 @@ class PlatformHelperWin final : public PlatformHelper { private: // PlatformHelper: - bool IsMobile() const override; + [[nodiscard]] bool IsMobile() const override; std::string GetName() const override; PlatformType GetType() const override; }; diff --git a/components/brave_ads/core/internal/common/search_engine/search_engine_results_page_util.h b/components/brave_ads/core/internal/common/search_engine/search_engine_results_page_util.h index f6390e9b5cf5..c0534236c28e 100644 --- a/components/brave_ads/core/internal/common/search_engine/search_engine_results_page_util.h +++ b/components/brave_ads/core/internal/common/search_engine/search_engine_results_page_util.h @@ -14,7 +14,7 @@ class GURL; namespace brave_ads { -bool IsSearchEngineResultsPage(const GURL& url); +[[nodiscard]] bool IsSearchEngineResultsPage(const GURL& url); std::optional ExtractSearchTermQueryValue(const GURL& url); diff --git a/components/brave_ads/core/internal/common/search_engine/search_engine_util.h b/components/brave_ads/core/internal/common/search_engine/search_engine_util.h index 7b1458de7e3c..43b2274a2add 100644 --- a/components/brave_ads/core/internal/common/search_engine/search_engine_util.h +++ b/components/brave_ads/core/internal/common/search_engine/search_engine_util.h @@ -10,7 +10,7 @@ class GURL; namespace brave_ads { -bool IsSearchEngine(const GURL& url); +[[nodiscard]] bool IsSearchEngine(const GURL& url); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/common/subdivision/subdivision.cc b/components/brave_ads/core/internal/common/subdivision/subdivision.cc index 7e380a2a4506..be737ba6292a 100644 --- a/components/brave_ads/core/internal/common/subdivision/subdivision.cc +++ b/components/brave_ads/core/internal/common/subdivision/subdivision.cc @@ -20,7 +20,7 @@ namespace brave_ads { namespace { -bool DoesRequireResourceForNewTabPageAds() { +[[nodiscard]] bool DoesRequireResourceForNewTabPageAds() { // Require resource only if: // - The user has opted into new tab page ads and has either joined Brave // Rewards or new tab page ad events should always be triggered. @@ -29,7 +29,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 diff --git a/components/brave_ads/core/internal/common/test/internal/local_state_pref_storage_test_util_internal.h b/components/brave_ads/core/internal/common/test/internal/local_state_pref_storage_test_util_internal.h index 88fe1eb978ad..be438712aebf 100644 --- a/components/brave_ads/core/internal/common/test/internal/local_state_pref_storage_test_util_internal.h +++ b/components/brave_ads/core/internal/common/test/internal/local_state_pref_storage_test_util_internal.h @@ -12,11 +12,11 @@ namespace brave_ads::test { struct PrefValueInfo; -bool FindLocalStatePref(const std::string& path); +[[nodiscard]] bool FindLocalStatePref(const std::string& path); PrefValueInfo& LocalStatePref(const std::string& path); -bool HasLocalStatePref(const std::string& path); +[[nodiscard]] bool HasLocalStatePref(const std::string& path); } // namespace brave_ads::test diff --git a/components/brave_ads/core/internal/common/test/internal/local_state_pref_value_test_util_internal.h b/components/brave_ads/core/internal/common/test/internal/local_state_pref_value_test_util_internal.h index 8104507f38fc..9de1d53a9550 100644 --- a/components/brave_ads/core/internal/common/test/internal/local_state_pref_value_test_util_internal.h +++ b/components/brave_ads/core/internal/common/test/internal/local_state_pref_value_test_util_internal.h @@ -18,7 +18,7 @@ base::Value GetDefaultLocalStatePrefValue(const std::string& path); void ClearLocalStatePrefValue(const std::string& path); -bool HasLocalStatePrefPathValue(const std::string& path); +[[nodiscard]] bool HasLocalStatePrefPathValue(const std::string& path); } // namespace brave_ads::test diff --git a/components/brave_ads/core/internal/common/test/internal/profile_pref_storage_test_util_internal.h b/components/brave_ads/core/internal/common/test/internal/profile_pref_storage_test_util_internal.h index 3f0256e13f16..b7c5245f429c 100644 --- a/components/brave_ads/core/internal/common/test/internal/profile_pref_storage_test_util_internal.h +++ b/components/brave_ads/core/internal/common/test/internal/profile_pref_storage_test_util_internal.h @@ -12,11 +12,11 @@ namespace brave_ads::test { struct PrefValueInfo; -bool FindProfilePref(const std::string& path); +[[nodiscard]] bool FindProfilePref(const std::string& path); PrefValueInfo& ProfilePref(const std::string& path); -bool HasProfilePref(const std::string& path); +[[nodiscard]] bool HasProfilePref(const std::string& path); } // namespace brave_ads::test diff --git a/components/brave_ads/core/internal/common/test/internal/profile_pref_value_test_util_internal.h b/components/brave_ads/core/internal/common/test/internal/profile_pref_value_test_util_internal.h index 60f1499f144f..a40cd4421074 100644 --- a/components/brave_ads/core/internal/common/test/internal/profile_pref_value_test_util_internal.h +++ b/components/brave_ads/core/internal/common/test/internal/profile_pref_value_test_util_internal.h @@ -18,7 +18,7 @@ base::Value GetDefaultProfilePrefValue(const std::string& path); void ClearProfilePrefValue(const std::string& path); -bool HasProfilePrefPathValue(const std::string& path); +[[nodiscard]] bool HasProfilePrefPathValue(const std::string& path); } // namespace brave_ads::test diff --git a/components/brave_ads/core/internal/common/test/internal/url_response_test_util_internal.cc b/components/brave_ads/core/internal/common/test/internal/url_response_test_util_internal.cc index 98acea606450..425a3ebd6675 100644 --- a/components/brave_ads/core/internal/common/test/internal/url_response_test_util_internal.cc +++ b/components/brave_ads/core/internal/common/test/internal/url_response_test_util_internal.cc @@ -79,7 +79,8 @@ std::optional GetNextUrlResponseForUrl( return url_responses_for_request_path.at(index); } -bool ShouldReadResponseBodyFromFile(const std::string& response_body) { +[[nodiscard]] bool ShouldReadResponseBodyFromFile( + const std::string& response_body) { return response_body.starts_with("/"); } diff --git a/components/brave_ads/core/internal/common/test/test_base.h b/components/brave_ads/core/internal/common/test/test_base.h index b91efb151a9d..bc0812289395 100644 --- a/components/brave_ads/core/internal/common/test/test_base.h +++ b/components/brave_ads/core/internal/common/test/test_base.h @@ -118,7 +118,7 @@ class TestBase : public AdsClientNotifierForTesting, public ::testing::Test { // Returns `true` if there are pending tasks on the main thread's TaskRunner. // When debugging, use `task_environment_.DescribeCurrentTasks` to see what // those are. See `TaskEnvironment` for more detail. - bool HasPendingTasks() const; + [[nodiscard]] bool HasPendingTasks() const; // Unlike `FastForwardClockToNextPendingTask`, `FastForwardClockTo`, // `FastForwardClockBy` and `SuspendedFastForwardClockBy`, `AdvanceClock*` diff --git a/components/brave_ads/core/internal/common/time/time_constraint_util.h b/components/brave_ads/core/internal/common/time/time_constraint_util.h index 73978394973b..4ddb2f79bbb9 100644 --- a/components/brave_ads/core/internal/common/time/time_constraint_util.h +++ b/components/brave_ads/core/internal/common/time/time_constraint_util.h @@ -19,7 +19,7 @@ namespace brave_ads { // Check if the `history` of time points respects a certain `time_constraint` // and a `cap` on the number of elements. Assumes that `history` is in // chronological order. -bool DoesHistoryRespectRollingTimeConstraint( +[[nodiscard]] bool DoesHistoryRespectRollingTimeConstraint( const std::vector& history, base::TimeDelta time_constraint, size_t cap); diff --git a/components/brave_ads/core/internal/common/timer/backoff_timer.h b/components/brave_ads/core/internal/common/timer/backoff_timer.h index 9b76148202aa..dba0f81719de 100644 --- a/components/brave_ads/core/internal/common/timer/backoff_timer.h +++ b/components/brave_ads/core/internal/common/timer/backoff_timer.h @@ -34,7 +34,7 @@ class BackoffTimer final { base::OnceClosure user_task); // Returns `true` if the timer is running (i.e., not stopped). - bool IsRunning() const; + [[nodiscard]] bool IsRunning() const; // Call this method to stop the timer if running and to reset the exponential // backoff delay. Returns `true` if the timer was stopped, otherwise returns diff --git a/components/brave_ads/core/internal/common/timer/timer.h b/components/brave_ads/core/internal/common/timer/timer.h index d40353a53663..09a056bd4ac3 100644 --- a/components/brave_ads/core/internal/common/timer/timer.h +++ b/components/brave_ads/core/internal/common/timer/timer.h @@ -43,7 +43,7 @@ class Timer final { base::OnceClosure user_task); // Returns `true` if the timer is running (i.e., not stopped). - bool IsRunning() const; + [[nodiscard]] bool IsRunning() const; // Call this method to stop the timer. It is a no-op if the timer is not // running. Returns `true` if the timer was stopped, otherwise returns diff --git a/components/brave_ads/core/internal/common/url/url_util.h b/components/brave_ads/core/internal/common/url/url_util.h index 62da115342fb..f2e024f4d517 100644 --- a/components/brave_ads/core/internal/common/url/url_util.h +++ b/components/brave_ads/core/internal/common/url/url_util.h @@ -19,18 +19,18 @@ GURL GetUrlExcludingQuery(const GURL& url); // password, is not an IP address, the eTLD+1 does not contain an asterisk // wildcard, and the host is either on the public suffix list or is a supported // internal URL. -bool ShouldSupportUrl(const GURL& url); +[[nodiscard]] bool ShouldSupportUrl(const GURL& url); // Returns `true` if the `url` matches the `pattern`. The pattern string can // contain asterix wildcards. The backslash character (\) is an escape character // for *. * matches 0 or more characters. -bool MatchUrlPattern(const GURL& url, const std::string& pattern); -bool MatchUrlPattern(const std::vector& redirect_chain, - const std::string& pattern); +[[nodiscard]] bool MatchUrlPattern(const GURL& url, const std::string& pattern); +[[nodiscard]] bool MatchUrlPattern(const std::vector& redirect_chain, + const std::string& pattern); -bool SameDomainOrHost(const GURL&, const GURL&); -bool DomainOrHostExists(const std::vector& redirect_chain, - const GURL& url); +[[nodiscard]] bool SameDomainOrHost(const GURL&, const GURL&); +[[nodiscard]] bool DomainOrHostExists(const std::vector& redirect_chain, + const GURL& url); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/common/url/url_util_internal.h b/components/brave_ads/core/internal/common/url/url_util_internal.h index 246d0ba130b0..e805761cf042 100644 --- a/components/brave_ads/core/internal/common/url/url_util_internal.h +++ b/components/brave_ads/core/internal/common/url/url_util_internal.h @@ -12,12 +12,12 @@ class GURL; namespace brave_ads { -bool HasSearchQuery(const GURL& url); -bool ShouldSupportInternalUrl(const GURL& url); +[[nodiscard]] bool HasSearchQuery(const GURL& url); +[[nodiscard]] bool ShouldSupportInternalUrl(const GURL& url); -bool HostHasRegistryControlledDomain(std::string_view host); +[[nodiscard]] bool HostHasRegistryControlledDomain(std::string_view host); -bool DoesETLDPlusOneContainWildcards(const GURL& url); +[[nodiscard]] bool DoesETLDPlusOneContainWildcards(const GURL& url); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.h b/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.h index 06868646ff30..29fc54433a0b 100644 --- a/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.h +++ b/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.h @@ -34,7 +34,7 @@ class NotificationAdManager final { void Remove(const std::string& placement_id, bool should_close); void RemoveAll(bool should_close); - bool Exists(const std::string& placement_id) const; + [[nodiscard]] bool Exists(const std::string& placement_id) const; private: void Initialize(); diff --git a/components/brave_ads/core/internal/database/database.h b/components/brave_ads/core/internal/database/database.h index 7ec323eafeee..f522d1e4d14d 100644 --- a/components/brave_ads/core/internal/database/database.h +++ b/components/brave_ads/core/internal/database/database.h @@ -42,9 +42,9 @@ class Database final { const mojom::DBTransactionInfoPtr& mojom_db_transaction, uint64_t trace_id); - bool InitializeMetaTable(); + [[nodiscard]] bool InitializeMetaTable(); - bool ShouldCreateTables(); + [[nodiscard]] bool ShouldCreateTables(); mojom::DBTransactionResultInfo::StatusCode Initialize( const mojom::DBTransactionResultInfoPtr& mojom_db_transaction_result); diff --git a/components/brave_ads/core/internal/deprecated/client/client_state_manager.cc b/components/brave_ads/core/internal/deprecated/client/client_state_manager.cc index f50acca62b64..5f0ee87482e6 100644 --- a/components/brave_ads/core/internal/deprecated/client/client_state_manager.cc +++ b/components/brave_ads/core/internal/deprecated/client/client_state_manager.cc @@ -5,7 +5,6 @@ #include "brave/components/brave_ads/core/internal/deprecated/client/client_state_manager.h" -#include #include #include diff --git a/components/brave_ads/core/internal/deprecated/confirmations/confirmation_state_manager.h b/components/brave_ads/core/internal/deprecated/confirmations/confirmation_state_manager.h index 412563ffeac6..b1d52037f84e 100644 --- a/components/brave_ads/core/internal/deprecated/confirmations/confirmation_state_manager.h +++ b/components/brave_ads/core/internal/deprecated/confirmations/confirmation_state_manager.h @@ -31,7 +31,7 @@ class ConfirmationStateManager final { void LoadState(std::optional wallet, InitializeCallback callback); - bool IsInitialized() const { return is_initialized_; } + [[nodiscard]] bool IsInitialized() const { return is_initialized_; } void SaveState(); diff --git a/components/brave_ads/core/internal/flags/debug/debug_command_line_switch_parser_util.h b/components/brave_ads/core/internal/flags/debug/debug_command_line_switch_parser_util.h index fae21d8fc36d..bad78387226f 100644 --- a/components/brave_ads/core/internal/flags/debug/debug_command_line_switch_parser_util.h +++ b/components/brave_ads/core/internal/flags/debug/debug_command_line_switch_parser_util.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool ParseDebugCommandLineSwitch(); +[[nodiscard]] bool ParseDebugCommandLineSwitch(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/flags/debug/debug_flag_util.h b/components/brave_ads/core/internal/flags/debug/debug_flag_util.h index 2f9f02a3c94d..19a243972fe8 100644 --- a/components/brave_ads/core/internal/flags/debug/debug_flag_util.h +++ b/components/brave_ads/core/internal/flags/debug/debug_flag_util.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool ShouldDebug(); +[[nodiscard]] bool ShouldDebug(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/flags/did_override/did_override_command_line_flag_util.h b/components/brave_ads/core/internal/flags/did_override/did_override_command_line_flag_util.h index d823de1a1703..a8df2b560ed1 100644 --- a/components/brave_ads/core/internal/flags/did_override/did_override_command_line_flag_util.h +++ b/components/brave_ads/core/internal/flags/did_override/did_override_command_line_flag_util.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool DidOverrideCommandLine(); +[[nodiscard]] bool DidOverrideCommandLine(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/flags/did_override/did_override_command_line_switch_values_util.h b/components/brave_ads/core/internal/flags/did_override/did_override_command_line_switch_values_util.h index 48e8f3beb04f..b4c3a57439e1 100644 --- a/components/brave_ads/core/internal/flags/did_override/did_override_command_line_switch_values_util.h +++ b/components/brave_ads/core/internal/flags/did_override/did_override_command_line_switch_values_util.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool DidOverrideCommandLineSwitchValues(); +[[nodiscard]] bool DidOverrideCommandLineSwitchValues(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/flags/did_override/did_override_command_line_switches_util.h b/components/brave_ads/core/internal/flags/did_override/did_override_command_line_switches_util.h index f28aa5c3a4ad..4b9ccb9b930c 100644 --- a/components/brave_ads/core/internal/flags/did_override/did_override_command_line_switches_util.h +++ b/components/brave_ads/core/internal/flags/did_override/did_override_command_line_switches_util.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool DidOverrideCommandLineSwitches(); +[[nodiscard]] bool DidOverrideCommandLineSwitches(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/flags/did_override/did_override_features_from_command_line_util.h b/components/brave_ads/core/internal/flags/did_override/did_override_features_from_command_line_util.h index 9f55f675af71..490205f767e8 100644 --- a/components/brave_ads/core/internal/flags/did_override/did_override_features_from_command_line_util.h +++ b/components/brave_ads/core/internal/flags/did_override/did_override_features_from_command_line_util.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool DidOverrideFeaturesFromCommandLine(); +[[nodiscard]] bool DidOverrideFeaturesFromCommandLine(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/flags/environment/environment_flag_util.h b/components/brave_ads/core/internal/flags/environment/environment_flag_util.h index 856364477b42..aa0ff57cbf68 100644 --- a/components/brave_ads/core/internal/flags/environment/environment_flag_util.h +++ b/components/brave_ads/core/internal/flags/environment/environment_flag_util.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool IsProductionEnvironment(); +[[nodiscard]] bool IsProductionEnvironment(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/legacy_migration/client/legacy_client_migration_util.h b/components/brave_ads/core/internal/legacy_migration/client/legacy_client_migration_util.h index d2e701ba40e0..29ea5755489e 100644 --- a/components/brave_ads/core/internal/legacy_migration/client/legacy_client_migration_util.h +++ b/components/brave_ads/core/internal/legacy_migration/client/legacy_client_migration_util.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasMigratedClientState(); +[[nodiscard]] bool HasMigratedClientState(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/legacy_migration/confirmations/legacy_confirmation_migration_util.h b/components/brave_ads/core/internal/legacy_migration/confirmations/legacy_confirmation_migration_util.h index d22c640a2e4f..5eee807c9232 100644 --- a/components/brave_ads/core/internal/legacy_migration/confirmations/legacy_confirmation_migration_util.h +++ b/components/brave_ads/core/internal/legacy_migration/confirmations/legacy_confirmation_migration_util.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasMigratedConfirmation(); +[[nodiscard]] bool HasMigratedConfirmation(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/ml/data/vector_data.h b/components/brave_ads/core/internal/ml/data/vector_data.h index 0e13cd693b92..0e09b8afee90 100644 --- a/components/brave_ads/core/internal/ml/data/vector_data.h +++ b/components/brave_ads/core/internal/ml/data/vector_data.h @@ -51,7 +51,7 @@ class VectorData final : public Data { void Normalize(); void Tanh(); - bool IsEmpty() const; + [[nodiscard]] bool IsEmpty() const; size_t GetDimensionCount() const; size_t GetNonZeroElementCount() const; float GetSum() const; diff --git a/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing.h b/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing.h index 9e7071210617..ef3b29404622 100644 --- a/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing.h +++ b/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing.h @@ -39,8 +39,10 @@ class TextProcessing final { ~TextProcessing(); - bool IsInitialized() const { return is_initialized_; } - bool IsNeuralPipline() const { return neural_model_.has_value(); } + [[nodiscard]] bool IsInitialized() const { return is_initialized_; } + [[nodiscard]] bool IsNeuralPipline() const { + return neural_model_.has_value(); + } base::expected LoadPipeline(base::File file); void SetPipeline(PipelineInfo pipeline); diff --git a/components/brave_ads/core/internal/prefs/pref_path_util.h b/components/brave_ads/core/internal/prefs/pref_path_util.h index ff9ece17da49..ae11bb58c10e 100644 --- a/components/brave_ads/core/internal/prefs/pref_path_util.h +++ b/components/brave_ads/core/internal/prefs/pref_path_util.h @@ -10,15 +10,20 @@ namespace brave_ads { -bool DoesMatchUserHasJoinedBraveRewardsPrefPath(const std::string& path); +[[nodiscard]] bool DoesMatchUserHasJoinedBraveRewardsPrefPath( + const std::string& path); -bool DoesMatchUserHasOptedInToBraveNewsAdsPrefPath(const std::string& path); +[[nodiscard]] bool DoesMatchUserHasOptedInToBraveNewsAdsPrefPath( + const std::string& path); -bool DoesMatchUserHasOptedInToNewTabPageAdsPrefPath(const std::string& path); +[[nodiscard]] bool DoesMatchUserHasOptedInToNewTabPageAdsPrefPath( + const std::string& path); -bool DoesMatchUserHasOptedInToNotificationAdsPrefPath(const std::string& path); +[[nodiscard]] bool DoesMatchUserHasOptedInToNotificationAdsPrefPath( + const std::string& path); -bool DoesMatchUserHasOptedInToSearchResultAdsPrefPath(const std::string& path); +[[nodiscard]] bool DoesMatchUserHasOptedInToSearchResultAdsPrefPath( + const std::string& path); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/prefs/pref_util.h b/components/brave_ads/core/internal/prefs/pref_util.h index c314ef7a61e5..c9daa4df63ff 100644 --- a/components/brave_ads/core/internal/prefs/pref_util.h +++ b/components/brave_ads/core/internal/prefs/pref_util.h @@ -39,8 +39,8 @@ void SetProfileTimePref(const std::string& path, base::Time value); void SetProfileTimeDeltaPref(const std::string& path, base::TimeDelta value); void ClearProfilePref(const std::string& path); -bool FindProfilePref(const std::string& path); -bool HasProfilePrefPath(const std::string& path); +[[nodiscard]] bool FindProfilePref(const std::string& path); +[[nodiscard]] bool HasProfilePrefPath(const std::string& path); // Gets local state preference values. bool GetLocalStateBooleanPref(const std::string& path); @@ -67,8 +67,8 @@ void SetLocalStateTimePref(const std::string& path, base::Time value); void SetLocalStateTimeDeltaPref(const std::string& path, base::TimeDelta value); void ClearLocalStatePref(const std::string& path); -bool FindLocalStatePref(const std::string& path); -bool HasLocalStatePrefPath(const std::string& path); +[[nodiscard]] bool FindLocalStatePref(const std::string& path); +[[nodiscard]] bool HasLocalStatePrefPath(const std::string& path); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/reminders/reminder/clicked_same_ad_multiple_times_reminder_util.h b/components/brave_ads/core/internal/reminders/reminder/clicked_same_ad_multiple_times_reminder_util.h index 80080d039f76..91d38820c6da 100644 --- a/components/brave_ads/core/internal/reminders/reminder/clicked_same_ad_multiple_times_reminder_util.h +++ b/components/brave_ads/core/internal/reminders/reminder/clicked_same_ad_multiple_times_reminder_util.h @@ -12,10 +12,11 @@ namespace brave_ads { -bool ShouldRemindUser(); +[[nodiscard]] bool ShouldRemindUser(); -bool DidUserClickTheSameAdMultipleTimes(const std::string& creative_instance_id, - const AdHistoryList& ad_history); +[[nodiscard]] bool DidUserClickTheSameAdMultipleTimes( + const std::string& creative_instance_id, + const AdHistoryList& ad_history); void RemindUserTheyDoNotNeedToClickToEarnRewards(); diff --git a/components/brave_ads/core/internal/reminders/reminders.h b/components/brave_ads/core/internal/reminders/reminders.h index 98307613cec6..450ed1c858f7 100644 --- a/components/brave_ads/core/internal/reminders/reminders.h +++ b/components/brave_ads/core/internal/reminders/reminders.h @@ -28,7 +28,7 @@ class Reminders : public AdHistoryManagerObserver { private: void MaybeShowReminders(const AdHistoryItemInfo& ad_history_item); - bool CanShowUserClickTheSameAdMultipleTimesReminder( + [[nodiscard]] bool CanShowUserClickTheSameAdMultipleTimesReminder( const AdHistoryItemInfo& ad_history_item); void MaybeShowUserClickTheSameAdMultipleTimesReminderAfterDelay( const AdHistoryItemInfo& ad_history_item); diff --git a/components/brave_ads/core/internal/segments/segment_util.h b/components/brave_ads/core/internal/segments/segment_util.h index f524aa63a7d5..2a2ebb8d4fca 100644 --- a/components/brave_ads/core/internal/segments/segment_util.h +++ b/components/brave_ads/core/internal/segments/segment_util.h @@ -35,9 +35,9 @@ SegmentList GetSegments(const T& creative_ads) { std::string GetParentSegment(const std::string& segment); SegmentList GetParentSegments(const SegmentList& segments); -bool HasChildSegment(const std::string& segment); +[[nodiscard]] bool HasChildSegment(const std::string& segment); -bool ShouldFilterSegment(const std::string& segment); +[[nodiscard]] bool ShouldFilterSegment(const std::string& segment); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/anti_targeting_exclusion_rule.h b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/anti_targeting_exclusion_rule.h index 129edd430955..5549f85cb166 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/anti_targeting_exclusion_rule.h +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/anti_targeting_exclusion_rule.h @@ -35,7 +35,7 @@ class AntiTargetingExclusionRule final const CreativeAdInfo& creative_ad) const override; private: - bool DoesRespectCap(const CreativeAdInfo& creative_ad) const; + [[nodiscard]] bool DoesRespectCap(const CreativeAdInfo& creative_ad) const; const raw_ref resource_; diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/anti_targeting_exclusion_rule_util.h b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/anti_targeting_exclusion_rule_util.h index 6f4c515e894a..558a7d79679b 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/anti_targeting_exclusion_rule_util.h +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/anti_targeting_exclusion_rule_util.h @@ -11,8 +11,9 @@ namespace brave_ads { -bool HasVisitedAntiTargetedSites(const SiteHistoryList& site_history, - const AntiTargetingSiteList& sites); +[[nodiscard]] bool HasVisitedAntiTargetedSites( + const SiteHistoryList& site_history, + const AntiTargetingSiteList& sites); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daypart_exclusion_rule.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daypart_exclusion_rule.cc index d2b92f398476..53ac8bcaa85d 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daypart_exclusion_rule.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daypart_exclusion_rule.cc @@ -19,7 +19,7 @@ namespace brave_ads { namespace { -bool DoesRespectCap(const CreativeAdInfo& creative_ad) { +[[nodiscard]] bool DoesRespectCap(const CreativeAdInfo& creative_ad) { if (creative_ad.dayparts.empty()) { // Always respect cap if there are no dayparts specified. return true; diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daypart_exclusion_rule_util.h b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daypart_exclusion_rule_util.h index a8da14d55222..bd8437694edd 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daypart_exclusion_rule_util.h +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daypart_exclusion_rule_util.h @@ -10,9 +10,11 @@ namespace brave_ads { struct CreativeDaypartInfo; -bool MatchDayOfWeek(const CreativeDaypartInfo& daypart, int day_of_week); +[[nodiscard]] bool MatchDayOfWeek(const CreativeDaypartInfo& daypart, + int day_of_week); -bool MatchTimeSlot(const CreativeDaypartInfo& daypart, int minutes); +[[nodiscard]] bool MatchTimeSlot(const CreativeDaypartInfo& daypart, + int minutes); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/dislike_exclusion_rule.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/dislike_exclusion_rule.cc index 3894b6007b9f..ff4f981f4d2c 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/dislike_exclusion_rule.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/dislike_exclusion_rule.cc @@ -14,7 +14,7 @@ namespace brave_ads { namespace { -bool DoesRespectCap(const CreativeAdInfo& creative_ad) { +[[nodiscard]] bool DoesRespectCap(const CreativeAdInfo& creative_ad) { return GetReactions().AdReactionTypeForId(creative_ad.advertiser_id) != mojom::ReactionType::kDisliked; } diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/dislike_segment_exclusion_rule.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/dislike_segment_exclusion_rule.cc index 5d8f5e1032f2..a0e6a02b54eb 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/dislike_segment_exclusion_rule.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/dislike_segment_exclusion_rule.cc @@ -13,7 +13,7 @@ namespace brave_ads { namespace { -bool DoesRespectCap(const CreativeAdInfo& creative_ad) { +[[nodiscard]] bool DoesRespectCap(const CreativeAdInfo& creative_ad) { return !ShouldFilterSegment(creative_ad.segment); } diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rule_util.h b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rule_util.h index a136facd859e..54a9871ec99b 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rule_util.h +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rule_util.h @@ -22,39 +22,46 @@ namespace brave_ads { struct CreativeAdInfo; -bool DoesRespectCampaignCap(const CreativeAdInfo& creative_ad, - const AdEventList& ad_events, - mojom::ConfirmationType mojom_confirmation_type, - base::TimeDelta time_constraint, - size_t cap); -bool DoesRespectCampaignCap(const CreativeAdInfo& creative_ad, - const AdEventList& ad_events, - mojom::ConfirmationType mojom_confirmation_type, - size_t cap); +[[nodiscard]] bool DoesRespectCampaignCap( + const CreativeAdInfo& creative_ad, + const AdEventList& ad_events, + mojom::ConfirmationType mojom_confirmation_type, + base::TimeDelta time_constraint, + size_t cap); +[[nodiscard]] bool DoesRespectCampaignCap( + const CreativeAdInfo& creative_ad, + const AdEventList& ad_events, + mojom::ConfirmationType mojom_confirmation_type, + size_t cap); -bool DoesRespectCreativeSetCap(const CreativeAdInfo& creative_ad, - const AdEventList& ad_events, - mojom::ConfirmationType mojom_confirmation_type, - base::TimeDelta time_constraint, - size_t cap); -bool DoesRespectCreativeSetCap(const CreativeAdInfo& creative_ad, - const AdEventList& ad_events, - mojom::ConfirmationType mojom_confirmation_type, - size_t cap); +[[nodiscard]] bool DoesRespectCreativeSetCap( + const CreativeAdInfo& creative_ad, + const AdEventList& ad_events, + mojom::ConfirmationType mojom_confirmation_type, + base::TimeDelta time_constraint, + size_t cap); +[[nodiscard]] bool DoesRespectCreativeSetCap( + const CreativeAdInfo& creative_ad, + const AdEventList& ad_events, + mojom::ConfirmationType mojom_confirmation_type, + size_t cap); -bool DoesRespectCreativeCap(const CreativeAdInfo& creative_ad, - const AdEventList& ad_events, - mojom::ConfirmationType mojom_confirmation_type, - base::TimeDelta time_constraint, - size_t cap); -bool DoesRespectCreativeCap(const CreativeAdInfo& creative_ad, - const AdEventList& ad_events, - mojom::ConfirmationType mojom_confirmation_type, - size_t cap); +[[nodiscard]] bool DoesRespectCreativeCap( + const CreativeAdInfo& creative_ad, + const AdEventList& ad_events, + mojom::ConfirmationType mojom_confirmation_type, + base::TimeDelta time_constraint, + size_t cap); +[[nodiscard]] bool DoesRespectCreativeCap( + const CreativeAdInfo& creative_ad, + const AdEventList& ad_events, + mojom::ConfirmationType mojom_confirmation_type, + size_t cap); template -bool ShouldInclude(const T& ad, - const ExclusionRuleInterface* const exclusion_rule) { +[[nodiscard]] bool ShouldInclude( + const T& ad, + const ExclusionRuleInterface* const exclusion_rule) { CHECK(exclusion_rule); const auto result = exclusion_rule->ShouldInclude(ad); diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_base.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_base.cc index 10bcb5d846eb..4019e3dfa29a 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_base.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_base.cc @@ -79,11 +79,11 @@ bool ExclusionRulesBase::ShouldExcludeCreativeAd( exclusion_rules_, [&](const std::unique_ptr>& exclusion_rule) { - return AddToCacheIfNeeded(creative_ad, exclusion_rule); + return MaybeAddToCache(creative_ad, exclusion_rule); }); } -bool ExclusionRulesBase::AddToCacheIfNeeded( +bool ExclusionRulesBase::MaybeAddToCache( const CreativeAdInfo& creative_ad, const std::unique_ptr>& exclusion_rule) { diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_base.h b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_base.h index cd6108aae7ec..b42575c79de4 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_base.h +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_base.h @@ -40,13 +40,13 @@ class ExclusionRulesBase { exclusion_rules_; std::set uuids_; - bool AddToCacheIfNeeded( + bool MaybeAddToCache( const CreativeAdInfo& creative_ad, const std::unique_ptr>& exclusion_rule); private: - bool IsCached(const CreativeAdInfo& creative_ad) const; + [[nodiscard]] bool IsCached(const CreativeAdInfo& creative_ad) const; void AddToCache(const std::string& uuid); }; diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_util.h b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_util.h index d800abe1b207..1c4929c18c49 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_util.h +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/exclusion_rules_util.h @@ -16,7 +16,7 @@ namespace brave_ads { template -bool CanCapLastServedCreativeAd(T& creative_ads) { +[[nodiscard]] bool CanCapLastServedCreativeAd(T& creative_ads) { return creative_ads.size() != 1; } diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/marked_as_inappropriate_exclusion_rule.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/marked_as_inappropriate_exclusion_rule.cc index ca3dba35cccb..10eb628c2402 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/marked_as_inappropriate_exclusion_rule.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/marked_as_inappropriate_exclusion_rule.cc @@ -14,7 +14,7 @@ namespace brave_ads { namespace { -bool DoesRespectCap(const CreativeAdInfo& creative_ad) { +[[nodiscard]] bool DoesRespectCap(const CreativeAdInfo& creative_ad) { return !GetReactions().IsAdMarkedAsInappropriate(creative_ad.creative_set_id); } diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/notification_ads/notification_ad_dismissed_exclusion_rule.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/notification_ads/notification_ad_dismissed_exclusion_rule.cc index eeafa04f0ece..232beffd2205 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/notification_ads/notification_ad_dismissed_exclusion_rule.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/notification_ads/notification_ad_dismissed_exclusion_rule.cc @@ -19,7 +19,7 @@ namespace brave_ads { namespace { -bool DoesRespectCap(const AdEventList& ad_events) { +[[nodiscard]] bool DoesRespectCap(const AdEventList& ad_events) { int count = 0; for (const auto& ad_event : ad_events) { diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule.cc index c00e796a149e..45b4af768cb5 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule.cc @@ -16,7 +16,8 @@ namespace brave_ads { namespace { -bool DoesCreativeAdTargetSubdivision(const CreativeAdInfo& creative_ad) { +[[nodiscard]] bool DoesCreativeAdTargetSubdivision( + const CreativeAdInfo& creative_ad) { const auto iter = std::ranges::find_if( creative_ad.geo_targets, [](const std::string& geo_target) { return std::count(geo_target.cbegin(), geo_target.cend(), '-') == 1; @@ -25,8 +26,9 @@ bool DoesCreativeAdTargetSubdivision(const CreativeAdInfo& creative_ad) { return iter != creative_ad.geo_targets.cend(); } -bool DoesCreativeAdTargetSubdivision(const CreativeAdInfo& creative_ad, - const std::string& subdivision) { +[[nodiscard]] bool DoesCreativeAdTargetSubdivision( + const CreativeAdInfo& creative_ad, + const std::string& subdivision) { return creative_ad.geo_targets.contains(subdivision) || creative_ad.geo_targets.contains( GetSubdivisionCountryCode(subdivision)); diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule.h b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule.h index a53da2427081..5b378fb54beb 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule.h +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule.h @@ -35,7 +35,7 @@ class SubdivisionTargetingExclusionRule final const CreativeAdInfo& creative_ad) const override; private: - bool DoesRespectCap(const CreativeAdInfo& creative_ad) const; + [[nodiscard]] bool DoesRespectCap(const CreativeAdInfo& creative_ad) const; const raw_ref subdivision_targeting_; }; diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/total_max_exclusion_rule.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/total_max_exclusion_rule.cc index 641a43594de7..863961b65a2a 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/total_max_exclusion_rule.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/total_max_exclusion_rule.cc @@ -14,8 +14,8 @@ namespace brave_ads { namespace { -bool DoesRespectCap(const AdEventList& ad_events, - const CreativeAdInfo& creative_ad) { +[[nodiscard]] bool DoesRespectCap(const AdEventList& ad_events, + const CreativeAdInfo& creative_ad) { if (creative_ad.total_max == 0) { // Always respect cap if set to 0. return true; diff --git a/components/brave_ads/core/internal/serving/eligible_ads/pacing/pacing_util.h b/components/brave_ads/core/internal/serving/eligible_ads/pacing/pacing_util.h index 582b679f224a..c1859c83f780 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/pacing/pacing_util.h +++ b/components/brave_ads/core/internal/serving/eligible_ads/pacing/pacing_util.h @@ -17,7 +17,7 @@ namespace brave_ads { // ad's pass-through rate. If the random number is less than the pass-through // rate, the ad is not paced. Otherwise, it is paced. template -bool ShouldPaceAd(const T& ad) { +[[nodiscard]] bool ShouldPaceAd(const T& ad) { const double rand = GeneratePacingRandomNumber(); if (rand < ad.pass_through_rate) { return false; diff --git a/components/brave_ads/core/internal/serving/inline_content_ad_serving.h b/components/brave_ads/core/internal/serving/inline_content_ad_serving.h index 8c72d95af2da..3fa7b945c858 100644 --- a/components/brave_ads/core/internal/serving/inline_content_ad_serving.h +++ b/components/brave_ads/core/internal/serving/inline_content_ad_serving.h @@ -45,9 +45,9 @@ class InlineContentAdServing final { MaybeServeInlineContentAdCallback callback); private: - bool IsSupported() const { return !!eligible_ads_; } + [[nodiscard]] bool IsSupported() const { return !!eligible_ads_; } - bool CanServeAd(const AdEventList& ad_events) const; + [[nodiscard]] bool CanServeAd(const AdEventList& ad_events) const; void GetAdEvents(int32_t tab_id, const std::string& dimensions, diff --git a/components/brave_ads/core/internal/serving/new_tab_page_ad_serving.h b/components/brave_ads/core/internal/serving/new_tab_page_ad_serving.h index f59d6f98fbd2..7657bb31c4f4 100644 --- a/components/brave_ads/core/internal/serving/new_tab_page_ad_serving.h +++ b/components/brave_ads/core/internal/serving/new_tab_page_ad_serving.h @@ -43,9 +43,9 @@ class NewTabPageAdServing final { void MaybeServeAd(MaybeServeNewTabPageAdCallback callback); private: - bool IsSupported() const { return !!eligible_ads_; } + [[nodiscard]] bool IsSupported() const { return !!eligible_ads_; } - bool CanServeAd(const AdEventList& ad_events) const; + [[nodiscard]] bool CanServeAd(const AdEventList& ad_events) const; void GetAdEvents(MaybeServeNewTabPageAdCallback callback); void GetAdEventsCallback(MaybeServeNewTabPageAdCallback callback, diff --git a/components/brave_ads/core/internal/serving/notification_ad_serving.h b/components/brave_ads/core/internal/serving/notification_ad_serving.h index c61e26f5bf92..0ffc3e60726b 100644 --- a/components/brave_ads/core/internal/serving/notification_ad_serving.h +++ b/components/brave_ads/core/internal/serving/notification_ad_serving.h @@ -54,9 +54,9 @@ class NotificationAdServing final : public AdsClientNotifierObserver { void MaybeServeAdAtNextRegularInterval(); private: - bool IsSupported() const { return !!eligible_ads_; } + [[nodiscard]] bool IsSupported() const { return !!eligible_ads_; } - bool CanServeAd(const AdEventList& ad_events) const; + [[nodiscard]] bool CanServeAd(const AdEventList& ad_events) const; void GetAdEvents(); void GetAdEventsCallback(bool success, const AdEventList& ad_events); diff --git a/components/brave_ads/core/internal/serving/notification_ad_serving_util.h b/components/brave_ads/core/internal/serving/notification_ad_serving_util.h index 20af13d6c675..dc12d21b5143 100644 --- a/components/brave_ads/core/internal/serving/notification_ad_serving_util.h +++ b/components/brave_ads/core/internal/serving/notification_ad_serving_util.h @@ -13,7 +13,7 @@ class TimeDelta; namespace brave_ads { -bool ShouldServeAdsAtRegularIntervals(); +[[nodiscard]] bool ShouldServeAdsAtRegularIntervals(); void SetServeAdAt(base::Time serve_ad_at); base::Time ServeAdAt(); diff --git a/components/brave_ads/core/internal/serving/permission_rules/ads_per_day_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/ads_per_day_permission_rule.h index 7893003c835a..c57f8243e37f 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/ads_per_day_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/ads_per_day_permission_rule.h @@ -15,7 +15,9 @@ class Time; namespace brave_ads { -bool HasAdsPerDayPermission(const std::vector& history, size_t cap); +[[nodiscard]] bool HasAdsPerDayPermission( + const std::vector& history, + size_t cap); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/ads_per_hour_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/ads_per_hour_permission_rule.h index 732dcbb1821e..9cbf3eb09793 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/ads_per_hour_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/ads_per_hour_permission_rule.h @@ -15,8 +15,9 @@ class Time; namespace brave_ads { -bool HasAdsPerHourPermission(const std::vector& history, - size_t cap); +[[nodiscard]] bool HasAdsPerHourPermission( + const std::vector& history, + size_t cap); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/browser_is_active_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/browser_is_active_permission_rule.h index 651964299a28..3d7925b773d2 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/browser_is_active_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/browser_is_active_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasBrowserIsActivePermission(); +[[nodiscard]] bool HasBrowserIsActivePermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/catalog_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/catalog_permission_rule.h index 9556a4297829..5fff9222f2c4 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/catalog_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/catalog_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasCatalogPermission(); +[[nodiscard]] bool HasCatalogPermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/command_line_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/command_line_permission_rule.h index 6265fe924725..514afb3ff455 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/command_line_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/command_line_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasCommandLinePermission(); +[[nodiscard]] bool HasCommandLinePermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/confirmation_tokens_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/confirmation_tokens_permission_rule.h index c57c2f0488b8..6f7a34c47895 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/confirmation_tokens_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/confirmation_tokens_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasConfirmationTokensPermission(); +[[nodiscard]] bool HasConfirmationTokensPermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/do_not_disturb_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/do_not_disturb_permission_rule.h index c5f9bcbad168..ba662f247bed 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/do_not_disturb_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/do_not_disturb_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasDoNotDisturbPermission(); +[[nodiscard]] bool HasDoNotDisturbPermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/full_screen_mode_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/full_screen_mode_permission_rule.h index a47f39cad250..79449cce592e 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/full_screen_mode_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/full_screen_mode_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasFullScreenModePermission(); +[[nodiscard]] bool HasFullScreenModePermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/issuers_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/issuers_permission_rule.h index b6ea53aea58f..c4f07fbfc5d2 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/issuers_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/issuers_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasIssuersPermission(); +[[nodiscard]] bool HasIssuersPermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/media_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/media_permission_rule.h index 3dd6f026f739..0de2d649e300 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/media_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/media_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasMediaPermission(); +[[nodiscard]] bool HasMediaPermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/minimum_wait_time_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/minimum_wait_time_permission_rule.h index 95a3dbd1040b..227d4955ff96 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/minimum_wait_time_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/minimum_wait_time_permission_rule.h @@ -16,8 +16,9 @@ class TimeDelta; namespace brave_ads { -bool HasMinimumWaitTimePermission(const std::vector& history, - base::TimeDelta time_constraint); +[[nodiscard]] bool HasMinimumWaitTimePermission( + const std::vector& history, + base::TimeDelta time_constraint); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/network_connection_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/network_connection_permission_rule.h index 697eb3214c87..53670bbcba65 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/network_connection_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/network_connection_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasNetworkConnectionPermission(); +[[nodiscard]] bool HasNetworkConnectionPermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/notification_ads/can_show_notifications_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/notification_ads/can_show_notifications_permission_rule.h index 968480289f79..b23ca0a506d1 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/notification_ads/can_show_notifications_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/notification_ads/can_show_notifications_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasCanShowNotificationsPermission(); +[[nodiscard]] bool HasCanShowNotificationsPermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/permission_rules/user_activity_permission_rule.h b/components/brave_ads/core/internal/serving/permission_rules/user_activity_permission_rule.h index ba9e6c500c0a..df6cda8192f7 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/user_activity_permission_rule.h +++ b/components/brave_ads/core/internal/serving/permission_rules/user_activity_permission_rule.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool HasUserActivityPermission(); +[[nodiscard]] bool HasUserActivityPermission(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.h b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.h index a4ae8f603e6f..c4f3a69f47da 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.h +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.h @@ -11,12 +11,13 @@ namespace brave_ads { // Returns true if the condition is an epoch operator. -bool IsEpochOperator(std::string_view condition); +[[nodiscard]] bool IsEpochOperator(std::string_view condition); // Matches a value against a condition using epoch operators. Supports equality, // greater than, greater than or equal, less than. and less than or equal // operators. -bool MatchEpochOperator(std::string_view value, std::string_view condition); +[[nodiscard]] bool MatchEpochOperator(std::string_view value, + std::string_view condition); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/internal/epoch_operator_condition_matcher_util_internal.cc b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/internal/epoch_operator_condition_matcher_util_internal.cc index d17aadc64f96..8ab585a11793 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/internal/epoch_operator_condition_matcher_util_internal.cc +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/internal/epoch_operator_condition_matcher_util_internal.cc @@ -79,7 +79,7 @@ std::optional ParseTimeDelta(std::string_view value) { } base::Time time; - if (base::Time::FromUTCString(value.data(), &time)) { + if (base::Time::FromUTCString(std::string(value).c_str(), &time)) { return TimeDeltaSinceEpoch(time.ToTimeT()); } diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/internal/epoch_operator_condition_matcher_util_internal.h b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/internal/epoch_operator_condition_matcher_util_internal.h index e00ba69d37c0..560bbbe8a4af 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/internal/epoch_operator_condition_matcher_util_internal.h +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/internal/epoch_operator_condition_matcher_util_internal.h @@ -22,7 +22,7 @@ inline constexpr char kEpochOperatorConditionMatcherPrefixPattern[] = "[T?]:*"; std::optional ParseDays(std::string_view condition); // Returns `true` if a Unix epoch timestamp. -bool IsUnixEpochTimestamp(int64_t timestamp); +[[nodiscard]] bool IsUnixEpochTimestamp(int64_t timestamp); // Converts a Windows timestamp to a Unix timestamp. int64_t WindowsToUnixEpoch(int64_t timestamp); diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/numerical_operator_condition_matcher_util.h b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/numerical_operator_condition_matcher_util.h index 0423e91eab7f..aa9f4dea18ff 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/numerical_operator_condition_matcher_util.h +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/numerical_operator_condition_matcher_util.h @@ -11,12 +11,13 @@ namespace brave_ads { // Returns true if the condition is a numerical operator. -bool IsNumericalOperator(std::string_view condition); +[[nodiscard]] bool IsNumericalOperator(std::string_view condition); // Matches a value against a condition using numerical operators. Supports // equality, greater than, greater than or equal, less than, less than or equal // and not equal operators. -bool MatchNumericalOperator(std::string_view value, std::string_view condition); +[[nodiscard]] bool MatchNumericalOperator(std::string_view value, + std::string_view condition); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/pattern_condition_matcher_util.h b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/pattern_condition_matcher_util.h index cd644bd362f4..0939dc612926 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/pattern_condition_matcher_util.h +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/pattern_condition_matcher_util.h @@ -11,7 +11,8 @@ namespace brave_ads { // Matches a value against a pattern condition. -bool MatchPattern(std::string_view value, std::string_view condition); +[[nodiscard]] bool MatchPattern(std::string_view value, + std::string_view condition); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/regex_condition_matcher_util.h b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/regex_condition_matcher_util.h index ffa9283bb86d..3ce3850eea70 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/regex_condition_matcher_util.h +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/regex_condition_matcher_util.h @@ -11,7 +11,8 @@ namespace brave_ads { // Matches a value against a regular expression condition. -bool MatchRegex(std::string_view value, std::string_view condition); +[[nodiscard]] bool MatchRegex(std::string_view value, + std::string_view condition); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/settings/settings.h b/components/brave_ads/core/internal/settings/settings.h index 885d0e5f573b..9dfa3feecc1f 100644 --- a/components/brave_ads/core/internal/settings/settings.h +++ b/components/brave_ads/core/internal/settings/settings.h @@ -8,16 +8,16 @@ namespace brave_ads { -bool UserHasJoinedBraveRewards(); +[[nodiscard]] bool UserHasJoinedBraveRewards(); -bool UserHasOptedInToBraveNewsAds(); +[[nodiscard]] bool UserHasOptedInToBraveNewsAds(); -bool UserHasOptedInToNewTabPageAds(); +[[nodiscard]] bool UserHasOptedInToNewTabPageAds(); -bool UserHasOptedInToNotificationAds(); +[[nodiscard]] bool UserHasOptedInToNotificationAds(); int GetMaximumNotificationAdsPerHour(); -bool UserHasOptedInToSearchResultAds(); +[[nodiscard]] bool UserHasOptedInToSearchResultAds(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/tabs/tab_manager.h b/components/brave_ads/core/internal/tabs/tab_manager.h index ca7aa92830fa..44541c717ec7 100644 --- a/components/brave_ads/core/internal/tabs/tab_manager.h +++ b/components/brave_ads/core/internal/tabs/tab_manager.h @@ -35,15 +35,17 @@ class TabManager final : public AdsClientNotifierObserver { void AddObserver(TabManagerObserver* observer); void RemoveObserver(TabManagerObserver* observer); - bool IsVisible(int32_t tab_id) const { return visible_tab_id_ == tab_id; } + [[nodiscard]] bool IsVisible(int32_t tab_id) const { + return visible_tab_id_ == tab_id; + } std::optional MaybeGetVisible() const; std::optional MaybeGetForId(int32_t tab_id) const; - bool IsPlayingMedia(int32_t tab_id) const; + [[nodiscard]] bool IsPlayingMedia(int32_t tab_id) const; private: - bool DoesExistForId(int32_t tab_id) const; + [[nodiscard]] bool DoesExistForId(int32_t tab_id) const; TabInfo& GetOrCreateForId(int32_t tab_id); void RemoveForId(int32_t tab_id); diff --git a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.cc b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.cc index 92223b9f9bb4..552bc788c5a8 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.cc @@ -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 has either joined Brave // Rewards or new tab page ad events should always be triggered. @@ -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 diff --git a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.h b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.h index d0a5a86894ce..bd1bb1bfe4e6 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.h +++ b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.h @@ -25,7 +25,7 @@ class AntiTargetingResource final : public AdsClientNotifierObserver { ~AntiTargetingResource() override; - bool IsLoaded() const { return !!resource_; } + [[nodiscard]] bool IsLoaded() const { return !!resource_; } std::optional GetManifestVersion() const { return manifest_version_; diff --git a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.h b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.h index 74ba27943b74..209c96f71744 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.h +++ b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.h @@ -37,7 +37,7 @@ class PurchaseIntentProcessor final : public TabManagerObserver { void Process(const GURL& url); private: - bool ShouldProcess(int32_t tab_id, const GURL& url) const; + [[nodiscard]] bool ShouldProcess(int32_t tab_id, const GURL& url) const; void MaybeProcess(int32_t tab_id, const GURL& url); std::optional MaybeExtractSignal( diff --git a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.cc b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.cc index ccd685c170d4..cc1e202b4b72 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.cc @@ -20,7 +20,7 @@ namespace brave_ads { namespace { -bool DoesRequireResource() { +[[nodiscard]] bool DoesRequireResource() { // Require resource only if: // - The user has joined Brave Rewards and opted into notification ads. return UserHasOptedInToNotificationAds(); diff --git a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.h b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.h index 91bb15a163fc..7e90e587d9d0 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.h +++ b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.h @@ -25,7 +25,7 @@ class PurchaseIntentResource final : public AdsClientNotifierObserver { ~PurchaseIntentResource() override; - bool IsLoaded() const { return !!resource_; } + [[nodiscard]] bool IsLoaded() const { return !!resource_; } std::optional GetManifestVersion() const { return manifest_version_; diff --git a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc index 12f412b5e411..5cac4e8c124e 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc @@ -23,7 +23,7 @@ namespace brave_ads { namespace { -bool DoesRequireResource() { +[[nodiscard]] bool DoesRequireResource() { // Require resource only if: // - The user has joined Brave Rewards and opted into notification ads. return UserHasOptedInToNotificationAds(); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.h b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.h index eef14d189d39..5e4861d65c6e 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.h +++ b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.h @@ -33,7 +33,7 @@ class TextClassificationResource final : public AdsClientNotifierObserver { ~TextClassificationResource() override; - bool IsLoaded() const { return !!text_processing_pipeline_; } + [[nodiscard]] bool IsLoaded() const { return !!text_processing_pipeline_; } std::optional GetManifestVersion() const { return manifest_version_; diff --git a/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting.cc b/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting.cc index dea6f37fc841..3d7d404d9e53 100644 --- a/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting.cc +++ b/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting.cc @@ -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 has either joined Brave // Rewards or new tab page ad events should always be triggered. @@ -32,7 +32,7 @@ bool DoesRequireResourceForNewTabPageAds() { ShouldAlwaysTriggerNewTabPageAdEvents()); } -bool DoesRequireResource() { +[[nodiscard]] bool DoesRequireResource() { // Require resource only if: // - User has opted into Brave News ads. // - User has opted into new tab page ads and either joined Brave Rewards or diff --git a/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting.h b/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting.h index 2af757c86ccb..4a6b6c03a46e 100644 --- a/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting.h +++ b/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting.h @@ -24,9 +24,9 @@ class SubdivisionTargeting final : public AdsClientNotifierObserver, ~SubdivisionTargeting() override; - bool IsDisabled() const; + [[nodiscard]] bool IsDisabled() const; - bool ShouldAutoDetect() const; + [[nodiscard]] bool ShouldAutoDetect() const; static bool ShouldAllow(); @@ -43,7 +43,7 @@ class SubdivisionTargeting final : public AdsClientNotifierObserver, void MaybeAllowForCountry(const std::string& country_code); - bool ShouldFetchSubdivision(); + [[nodiscard]] bool ShouldFetchSubdivision(); void MaybeFetchSubdivision(); void MaybeAllowAndFetchSubdivisionForLocale(const std::string& locale); diff --git a/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting_util.h b/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting_util.h index 6d61b7fd5019..9dd3a11ab695 100644 --- a/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting_util.h +++ b/components/brave_ads/core/internal/targeting/geographical/subdivision/subdivision_targeting_util.h @@ -10,10 +10,11 @@ namespace brave_ads { -bool ShouldTargetSubdivisionCountryCode(const std::string& country_code); +[[nodiscard]] bool ShouldTargetSubdivisionCountryCode( + const std::string& country_code); -bool ShouldTargetSubdivision(const std::string& country_code, - const std::string& subdivision); +[[nodiscard]] bool ShouldTargetSubdivision(const std::string& country_code, + const std::string& subdivision); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/user_attention/user_activity/page_transition_util.h b/components/brave_ads/core/internal/user_attention/user_activity/page_transition_util.h index 160a3180874a..a163889419e8 100644 --- a/components/brave_ads/core/internal/user_attention/user_activity/page_transition_util.h +++ b/components/brave_ads/core/internal/user_attention/user_activity/page_transition_util.h @@ -13,15 +13,17 @@ namespace brave_ads { -bool IsNewNavigation(PageTransitionType type); +[[nodiscard]] bool IsNewNavigation(PageTransitionType type); -bool DidUseBackOrFowardButtonToTriggerNavigation(PageTransitionType type); +[[nodiscard]] bool DidUseBackOrFowardButtonToTriggerNavigation( + PageTransitionType type); -bool DidUseAddressBarToTriggerNavigation(PageTransitionType type); +[[nodiscard]] bool DidUseAddressBarToTriggerNavigation(PageTransitionType type); -bool DidNavigateToHomePage(PageTransitionType type); +[[nodiscard]] bool DidNavigateToHomePage(PageTransitionType type); -bool DidTransitionFromExternalApplication(PageTransitionType type); +[[nodiscard]] bool DidTransitionFromExternalApplication( + PageTransitionType type); std::optional ToUserActivityEventType( PageTransitionType type); diff --git a/components/brave_ads/core/internal/user_attention/user_activity/user_activity_scoring_util.h b/components/brave_ads/core/internal/user_attention/user_activity/user_activity_scoring_util.h index ff133aab11bb..47a6f568dd7d 100644 --- a/components/brave_ads/core/internal/user_attention/user_activity/user_activity_scoring_util.h +++ b/components/brave_ads/core/internal/user_attention/user_activity/user_activity_scoring_util.h @@ -8,7 +8,7 @@ namespace brave_ads { -bool WasUserActive(); +[[nodiscard]] bool WasUserActive(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/user_attention/user_idle_detection/user_idle_detection_util.h b/components/brave_ads/core/internal/user_attention/user_idle_detection/user_idle_detection_util.h index 02f27b38d9e4..7cc85d8ff8f5 100644 --- a/components/brave_ads/core/internal/user_attention/user_idle_detection/user_idle_detection_util.h +++ b/components/brave_ads/core/internal/user_attention/user_idle_detection/user_idle_detection_util.h @@ -12,9 +12,9 @@ class TimeDelta; namespace brave_ads { -bool MaybeScreenWasLocked(bool screen_was_locked); +[[nodiscard]] bool MaybeScreenWasLocked(bool screen_was_locked); -bool HasExceededMaximumIdleTime(base::TimeDelta idle_time); +[[nodiscard]] bool HasExceededMaximumIdleTime(base::TimeDelta idle_time); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_handler_util.h b/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_handler_util.h index d9eef6a928f7..e9a68c962c50 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_handler_util.h +++ b/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_handler_util.h @@ -18,30 +18,31 @@ namespace brave_ads { struct AdInfo; -bool HasFiredAdEvent(const AdInfo& ad, - const AdEventList& ad_events, - mojom::ConfirmationType mojom_confirmation_type); +[[nodiscard]] bool HasFiredAdEvent( + const AdInfo& ad, + const AdEventList& ad_events, + mojom::ConfirmationType mojom_confirmation_type); // Set `time_window` to 0 to ignore the time window. -bool HasFiredAdEventWithinTimeWindow( +[[nodiscard]] bool HasFiredAdEventWithinTimeWindow( const AdInfo& ad, const AdEventList& ad_events, mojom::ConfirmationType mojom_confirmation_type, base::TimeDelta time_window); template -bool WasAdServed(const AdInfo& ad, - const AdEventList& ad_events, - const T mojom_ad_event_type) { +[[nodiscard]] bool WasAdServed(const AdInfo& ad, + const AdEventList& ad_events, + const T mojom_ad_event_type) { return mojom_ad_event_type == T::kServedImpression || HasFiredAdEvent(ad, ad_events, mojom::ConfirmationType::kServedImpression); } template -bool ShouldDeduplicateViewedAdEvent(const AdInfo& ad, - const AdEventList& ad_events, - const T mojom_ad_event_type) { +[[nodiscard]] bool ShouldDeduplicateViewedAdEvent(const AdInfo& ad, + const AdEventList& ad_events, + const T mojom_ad_event_type) { return mojom_ad_event_type == T::kViewedImpression && HasFiredAdEventWithinTimeWindow( ad, ad_events, mojom::ConfirmationType::kViewedImpression, @@ -49,9 +50,10 @@ bool ShouldDeduplicateViewedAdEvent(const AdInfo& ad, } template -bool ShouldDeduplicateClickedAdEvent(const AdInfo& ad, - const AdEventList& ad_events, - const T mojom_ad_event_type) { +[[nodiscard]] bool ShouldDeduplicateClickedAdEvent( + const AdInfo& ad, + const AdEventList& ad_events, + const T mojom_ad_event_type) { return mojom_ad_event_type == T::kClicked && HasFiredAdEventWithinTimeWindow( ad, ad_events, mojom::ConfirmationType::kClicked, @@ -59,9 +61,9 @@ bool ShouldDeduplicateClickedAdEvent(const AdInfo& ad, } template -bool ShouldDeduplicateAdEvent(const AdInfo& ad, - const AdEventList& ad_events, - const T mojom_ad_event_type) { +[[nodiscard]] bool ShouldDeduplicateAdEvent(const AdInfo& ad, + const AdEventList& ad_events, + const T mojom_ad_event_type) { return ShouldDeduplicateViewedAdEvent(ad, ad_events, mojom_ad_event_type) || ShouldDeduplicateClickedAdEvent(ad, ad_events, mojom_ad_event_type); } diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/search_result_ads/search_result_ad_event_handler_util.h b/components/brave_ads/core/internal/user_engagement/ad_events/search_result_ads/search_result_ad_event_handler_util.h index 65dce165e82c..fdf08a91fb75 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/search_result_ads/search_result_ad_event_handler_util.h +++ b/components/brave_ads/core/internal/user_engagement/ad_events/search_result_ads/search_result_ad_event_handler_util.h @@ -17,13 +17,14 @@ void MaybeBuildAndSaveCreativeSetConversion( const mojom::CreativeSearchResultAdInfoPtr& mojom_creative_ad, mojom::SearchResultAdEventType mojom_ad_event_type); -bool IsAllowedToFireAdEvent( +[[nodiscard]] bool IsAllowedToFireAdEvent( const mojom::CreativeSearchResultAdInfoPtr& mojom_creative_ad, mojom::SearchResultAdEventType mojom_ad_event_type); -bool ShouldFireAdEvent(const SearchResultAdInfo& ad, - const AdEventList& ad_events, - mojom::SearchResultAdEventType mojom_ad_event_type); +[[nodiscard]] bool ShouldFireAdEvent( + const SearchResultAdInfo& ad, + const AdEventList& ad_events, + mojom::SearchResultAdEventType mojom_ad_event_type); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/user_engagement/conversions/conversions_util.h b/components/brave_ads/core/internal/user_engagement/conversions/conversions_util.h index 1717c93335af..dbe5e4fe5edc 100644 --- a/components/brave_ads/core/internal/user_engagement/conversions/conversions_util.h +++ b/components/brave_ads/core/internal/user_engagement/conversions/conversions_util.h @@ -14,10 +14,11 @@ namespace brave_ads { struct AdEventInfo; -bool IsAllowedToConvertAdEvent(const AdEventInfo& ad_event); +[[nodiscard]] bool IsAllowedToConvertAdEvent(const AdEventInfo& ad_event); -bool DidAdEventOccurWithinObservationWindow(const AdEventInfo& ad_event, - base::TimeDelta observation_window); +[[nodiscard]] bool DidAdEventOccurWithinObservationWindow( + const AdEventInfo& ad_event, + base::TimeDelta observation_window); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/user_engagement/conversions/conversions_util_internal.h b/components/brave_ads/core/internal/user_engagement/conversions/conversions_util_internal.h index 549da5e925e9..9d596dd4829d 100644 --- a/components/brave_ads/core/internal/user_engagement/conversions/conversions_util_internal.h +++ b/components/brave_ads/core/internal/user_engagement/conversions/conversions_util_internal.h @@ -10,7 +10,7 @@ namespace brave_ads { struct AdEventInfo; -bool CanConvertAdEvent(const AdEventInfo& ad_event); +[[nodiscard]] bool CanConvertAdEvent(const AdEventInfo& ad_event); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/user_engagement/conversions/resource/conversion_resource.cc b/components/brave_ads/core/internal/user_engagement/conversions/resource/conversion_resource.cc index 6bd37b44a6ce..543d93acfd15 100644 --- a/components/brave_ads/core/internal/user_engagement/conversions/resource/conversion_resource.cc +++ b/components/brave_ads/core/internal/user_engagement/conversions/resource/conversion_resource.cc @@ -22,7 +22,7 @@ namespace brave_ads { namespace { -bool DoesRequireResource() { +[[nodiscard]] bool DoesRequireResource() { // Require resource only if: // - The user has joined Brave Rewards and opted into Brave News ads, new tab // page ads, notification ads, or search result ads. diff --git a/components/brave_ads/core/internal/user_engagement/conversions/resource/conversion_resource.h b/components/brave_ads/core/internal/user_engagement/conversions/resource/conversion_resource.h index 1183576d3eac..40833664b8af 100644 --- a/components/brave_ads/core/internal/user_engagement/conversions/resource/conversion_resource.h +++ b/components/brave_ads/core/internal/user_engagement/conversions/resource/conversion_resource.h @@ -25,7 +25,7 @@ class ConversionResource final : public AdsClientNotifierObserver { ~ConversionResource() override; - bool IsLoaded() const { return !!resource_; } + [[nodiscard]] bool IsLoaded() const { return !!resource_; } std::optional GetManifestVersion() const { return manifest_version_; diff --git a/components/brave_ads/core/internal/user_engagement/conversions/types/default_conversion/creative_set_conversion_url_pattern/creative_set_conversion_url_pattern_util.h b/components/brave_ads/core/internal/user_engagement/conversions/types/default_conversion/creative_set_conversion_url_pattern/creative_set_conversion_url_pattern_util.h index a39cf9cd9ad2..f4665cf1a767 100644 --- a/components/brave_ads/core/internal/user_engagement/conversions/types/default_conversion/creative_set_conversion_url_pattern/creative_set_conversion_url_pattern_util.h +++ b/components/brave_ads/core/internal/user_engagement/conversions/types/default_conversion/creative_set_conversion_url_pattern/creative_set_conversion_url_pattern_util.h @@ -14,7 +14,7 @@ namespace brave_ads { struct CreativeSetConversionInfo; -bool DoesCreativeSetConversionUrlPatternMatchRedirectChain( +[[nodiscard]] bool DoesCreativeSetConversionUrlPatternMatchRedirectChain( const CreativeSetConversionInfo& creative_set_conversion, const std::vector& redirect_chain); diff --git a/components/brave_ads/core/internal/user_engagement/reactions/reactions.h b/components/brave_ads/core/internal/user_engagement/reactions/reactions.h index 0cd8a99d06ef..ede3d9f12090 100644 --- a/components/brave_ads/core/internal/user_engagement/reactions/reactions.h +++ b/components/brave_ads/core/internal/user_engagement/reactions/reactions.h @@ -54,12 +54,13 @@ class Reactions final { void ToggleSaveAd(mojom::ReactionInfoPtr mojom_reaction, ToggleReactionCallback callback); - bool IsAdSaved(const std::string& creative_instance_id) const; + [[nodiscard]] bool IsAdSaved(const std::string& creative_instance_id) const; ReactionSet& SavedAdsForTesting() { return saved_ads_; } void ToggleMarkAdAsInappropriate(mojom::ReactionInfoPtr mojom_reaction, ToggleReactionCallback callback); - bool IsAdMarkedAsInappropriate(const std::string& creative_set_id) const; + [[nodiscard]] bool IsAdMarkedAsInappropriate( + const std::string& creative_set_id) const; ReactionSet& MarkedAdsAsInappropriateForTesting() { return marked_as_inappropriate_; } diff --git a/components/brave_ads/core/internal/user_engagement/site_visit/site_visit.h b/components/brave_ads/core/internal/user_engagement/site_visit/site_visit.h index d2073ec70fbc..242d2a54f00d 100644 --- a/components/brave_ads/core/internal/user_engagement/site_visit/site_visit.h +++ b/components/brave_ads/core/internal/user_engagement/site_visit/site_visit.h @@ -53,7 +53,7 @@ class SiteVisit final : public BrowserManagerObserver, private: // Returns true if the tab is currently landing on a page. - bool IsLandingOnPage(int32_t tab_id) const; + [[nodiscard]] bool IsLandingOnPage(int32_t tab_id) const; void MaybeLandOnPage(const TabInfo& tab, int http_status_code); void MaybeLandOnPageAfter(const TabInfo& tab, diff --git a/components/brave_ads/core/internal/user_engagement/site_visit/site_visit_util.h b/components/brave_ads/core/internal/user_engagement/site_visit/site_visit_util.h index 1d5787dff160..520ff52a2dfb 100644 --- a/components/brave_ads/core/internal/user_engagement/site_visit/site_visit_util.h +++ b/components/brave_ads/core/internal/user_engagement/site_visit/site_visit_util.h @@ -14,11 +14,11 @@ class GURL; namespace brave_ads { -bool IsAllowedToLandOnPage(mojom::AdType mojom_ad_type); +[[nodiscard]] bool IsAllowedToLandOnPage(mojom::AdType mojom_ad_type); -bool ShouldResumePageLand(int32_t tab_id); +[[nodiscard]] bool ShouldResumePageLand(int32_t tab_id); -bool DidLandOnPage(int32_t tab_id, const GURL& url); +[[nodiscard]] bool DidLandOnPage(int32_t tab_id, const GURL& url); } // namespace brave_ads diff --git a/components/brave_ads/core/public/ads_feature.h b/components/brave_ads/core/public/ads_feature.h index 71f9142d1be9..2652fbdd6b82 100644 --- a/components/brave_ads/core/public/ads_feature.h +++ b/components/brave_ads/core/public/ads_feature.h @@ -14,27 +14,27 @@ namespace brave_ads { // disabled. BASE_DECLARE_FEATURE(kShouldAlwaysRunBraveAdsServiceFeature); -bool ShouldAlwaysRunService(); +[[nodiscard]] bool ShouldAlwaysRunService(); // Set to `true` to always trigger new tab page ad events even if Brave Private // Ads are disabled. `ShouldAlwaysRunService()` must be set to `true`, otherwise // this feature param will be ignored. BASE_DECLARE_FEATURE(kShouldAlwaysTriggerBraveNewTabPageAdEventsFeature); -bool ShouldAlwaysTriggerNewTabPageAdEvents(); +[[nodiscard]] bool ShouldAlwaysTriggerNewTabPageAdEvents(); // Set to `true` to support search result ads. `ShouldAlwaysRunService()` must // be set to `true`, otherwise this feature param will be ignored. BASE_DECLARE_FEATURE(kShouldSupportSearchResultAdsFeature); -bool ShouldSupportSearchResultAds(); +[[nodiscard]] bool ShouldSupportSearchResultAds(); // Set to `true` to always trigger search result ad events even if Brave Private // Ads are disabled. `ShouldAlwaysRunService()` must be set to `true`, otherwise // this feature param will be ignored. BASE_DECLARE_FEATURE(kShouldAlwaysTriggerBraveSearchResultAdEventsFeature); -bool ShouldAlwaysTriggerSearchResultAdEvents(); +[[nodiscard]] bool ShouldAlwaysTriggerSearchResultAdEvents(); } // namespace brave_ads diff --git a/components/brave_ads/core/public/ads_util.h b/components/brave_ads/core/public/ads_util.h index b1ac44e21f4e..eef2abef7f36 100644 --- a/components/brave_ads/core/public/ads_util.h +++ b/components/brave_ads/core/public/ads_util.h @@ -10,7 +10,7 @@ namespace brave_ads { // Determines whether ads are supported in the user's region, returning `true` // if so, otherwise `false`. -bool IsSupportedRegion(); +[[nodiscard]] bool IsSupportedRegion(); } // namespace brave_ads diff --git a/components/brave_ads/core/public/prefs/pref_provider.h b/components/brave_ads/core/public/prefs/pref_provider.h index 2f5b8dc415b2..b5821c0e61a5 100644 --- a/components/brave_ads/core/public/prefs/pref_provider.h +++ b/components/brave_ads/core/public/prefs/pref_provider.h @@ -32,11 +32,13 @@ class PrefProvider : public PrefProviderInterface { std::optional 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 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 GetVirtualPref( const std::string& pref_path) const override; diff --git a/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h b/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h index 2e93752f3e01..8a087cb26737 100644 --- a/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h +++ b/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h @@ -195,8 +195,9 @@ class PrefProviderInterface; // malformed condition matchers will be logged to the console, they are not // logged to the Rewards log. -bool MatchConditions(const PrefProviderInterface* pref_provider, - const ConditionMatcherMap& condition_matchers); +[[nodiscard]] bool MatchConditions( + const PrefProviderInterface* pref_provider, + const ConditionMatcherMap& condition_matchers); } // namespace brave_ads