Skip to content

Commit

Permalink
Add MaybeCreateThrottleFor
Browse files Browse the repository at this point in the history
Add user pref deps
  • Loading branch information
deeppandya committed Dec 9, 2024
1 parent bb36500 commit c2fde0e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
11 changes: 4 additions & 7 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include "brave/components/body_sniffer/body_sniffer_throttle.h"
#include "brave/components/brave_federated/features.h"
#include "brave/components/brave_rewards/browser/rewards_protocol_navigation_throttle.h"
#include "brave/components/brave_rewards/common/pref_names.h"
#include "brave/components/brave_search/browser/brave_search_default_host.h"
#include "brave/components/brave_search/browser/brave_search_default_host_private.h"
#include "brave/components/brave_search/browser/brave_search_fallback_host.h"
Expand Down Expand Up @@ -1171,12 +1170,10 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
// navigation happens
content::BrowserContext* context =
handle->GetWebContents()->GetBrowserContext();
PrefService* pref_service = user_prefs::UserPrefs::Get(context);
if (pref_service->GetBoolean(brave_rewards::prefs::kEnabled)) {
throttles.insert(
throttles.begin(),
std::make_unique<brave_rewards::RewardsProtocolNavigationThrottle>(
handle));

if (auto rewards_throttle = brave_rewards::RewardsProtocolNavigationThrottle::
MaybeCreateThrottleFor(handle)) {
throttles.insert(throttles.begin(), std::move(rewards_throttle));
}

#if !BUILDFLAG(IS_ANDROID)
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static_library("browser") {
"//components/os_crypt/sync:os_crypt",
"//components/prefs",
"//components/sessions",
"//components/user_prefs",
"//content/public/browser",
"//extensions/buildflags",
"//mojo/public/cpp/bindings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#include "base/strings/strcat.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "brave/components/brave_rewards/common/pref_names.h"
#include "brave/components/brave_rewards/core/buildflags.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/navigation_throttle.h"
Expand All @@ -33,6 +37,19 @@ using content::WebContents;

namespace brave_rewards {

// static
std::unique_ptr<RewardsProtocolNavigationThrottle>
RewardsProtocolNavigationThrottle::MaybeCreateThrottleFor(
content::NavigationHandle* navigation_handle) {
auto* pref_service = user_prefs::UserPrefs::Get(
navigation_handle->GetWebContents()->GetBrowserContext());
if (!pref_service->GetBoolean(brave_rewards::prefs::kEnabled)) {
return nullptr;
}

return std::make_unique<RewardsProtocolNavigationThrottle>(navigation_handle);
}

RewardsProtocolNavigationThrottle::RewardsProtocolNavigationThrottle(
NavigationHandle* handle)
: NavigationThrottle(handle) {
Expand Down

0 comments on commit c2fde0e

Please sign in to comment.