Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement debouncing #9065

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "brave/components/brave_talk/features.h"
#include "brave/components/brave_vpn/buildflags/buildflags.h"
#include "brave/components/brave_wallet/common/buildflags/buildflags.h"
#include "brave/components/debounce/common/features.h"
#include "brave/components/decentralized_dns/buildflags/buildflags.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/ntp_background_images/browser/features.h"
Expand Down Expand Up @@ -56,6 +57,7 @@ using brave_shields::features::kBraveAdblockDefault1pBlocking;
using brave_shields::features::kBraveDarkModeBlock;
using brave_shields::features::kBraveDomainBlock;
using brave_shields::features::kBraveExtensionNetworkBlocking;
using debounce::features::kBraveDebounce;
using ntp_background_images::features::kBraveNTPBrandedWallpaper;
using ntp_background_images::features::kBraveNTPBrandedWallpaperDemo;
using ntp_background_images::features::kBraveNTPSuperReferralWallpaper;
Expand Down Expand Up @@ -105,6 +107,10 @@ constexpr char kBraveDomainBlockName[] = "Enable domain blocking";
constexpr char kBraveDomainBlockDescription[] =
"Enable support for blocking domains with an interstitial page";

constexpr char kBraveDebounceName[] = "Enable debouncing";
constexpr char kBraveDebounceDescription[] =
"Enable support for skipping top-level redirect tracking URLs";

constexpr char kBraveExtensionNetworkBlockingName[] =
"Enable extension network blocking";
constexpr char kBraveExtensionNetworkBlockingDescription[] =
Expand Down Expand Up @@ -333,6 +339,10 @@ constexpr char kUseDevUpdaterUrlDescription[] =
flag_descriptions::kBraveDomainBlockName, \
flag_descriptions::kBraveDomainBlockDescription, kOsAll, \
FEATURE_VALUE_TYPE(kBraveDomainBlock)}, \
{"brave-debounce", \
flag_descriptions::kBraveDebounceName, \
flag_descriptions::kBraveDebounceDescription, kOsAll, \
FEATURE_VALUE_TYPE(kBraveDebounce)}, \
{"brave-extension-network-blocking", \
flag_descriptions::kBraveExtensionNetworkBlockingName, \
flag_descriptions::kBraveExtensionNetworkBlockingDescription, kOsAll, \
Expand Down
6 changes: 6 additions & 0 deletions browser/brave_browser_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class GreaselionDownloadService;
#endif
} // namespace greaselion

namespace debounce {
class DebounceComponentInstaller;
} // namespace debounce

namespace ntp_background_images {
class NTPBackgroundImagesService;
} // namespace ntp_background_images
Expand Down Expand Up @@ -85,6 +89,8 @@ class BraveBrowserProcess {
virtual greaselion::GreaselionDownloadService*
greaselion_download_service() = 0;
#endif
virtual debounce::DebounceComponentInstaller*
debounce_component_installer() = 0;
virtual brave_shields::HTTPSEverywhereService* https_everywhere_service() = 0;
virtual brave_component_updater::LocalDataFilesService*
local_data_files_service() = 0;
Expand Down
36 changes: 25 additions & 11 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "brave/components/brave_shields/browser/ad_block_subscription_service_manager.h"
#include "brave/components/brave_shields/browser/https_everywhere_service.h"
#include "brave/components/brave_sync/network_time_helper.h"
#include "brave/components/debounce/browser/debounce_component_installer.h"
#include "brave/components/debounce/common/features.h"
#include "brave/components/ntp_background_images/browser/features.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_service.h"
#include "brave/components/p3a/brave_p3a_service.h"
Expand All @@ -49,8 +51,8 @@
#include "services/network/public/cpp/shared_url_loader_factory.h"

#if BUILDFLAG(ENABLE_SYSTEM_NOTIFICATIONS)
#include "chrome/browser/notifications/notification_platform_bridge.h"
#include "brave/browser/notifications/brave_notification_platform_bridge.h"
#include "chrome/browser/notifications/notification_platform_bridge.h"
#endif

#if BUILDFLAG(ENABLE_BRAVE_REFERRALS)
Expand Down Expand Up @@ -88,8 +90,8 @@
#endif

using brave_component_updater::BraveComponent;
using ntp_background_images::features::kBraveNTPBrandedWallpaper;
using ntp_background_images::NTPBackgroundImagesService;
using ntp_background_images::features::kBraveNTPBrandedWallpaper;

namespace {

Expand Down Expand Up @@ -137,8 +139,8 @@ void BraveBrowserProcessImpl::Init() {
content::ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme(
ipfs::kIPNSScheme);
#endif
brave_component_updater::BraveOnDemandUpdater::GetInstance()->
RegisterOnDemandUpdateCallback(
brave_component_updater::BraveOnDemandUpdater::GetInstance()
->RegisterOnDemandUpdateCallback(
base::BindRepeating(&component_updater::BraveOnDemandUpdate));
UpdateBraveDarkMode();
pref_change_registrar_.Add(
Expand Down Expand Up @@ -186,14 +188,15 @@ void BraveBrowserProcessImpl::StartBraveServices() {
#if BUILDFLAG(ENABLE_GREASELION)
greaselion_download_service();
#endif
debounce_component_installer();
#if BUILDFLAG(ENABLE_SPEEDREADER)
speedreader_rewriter_service();
#endif
// Now start the local data files service, which calls all observers.
local_data_files_service()->Start();

brave_sync::NetworkTimeHelper::GetInstance()
->SetNetworkTimeTracker(g_browser_process->network_time_tracker());
brave_sync::NetworkTimeHelper::GetInstance()->SetNetworkTimeTracker(
g_browser_process->network_time_tracker());
}

brave_shields::AdBlockService* BraveBrowserProcessImpl::ad_block_service() {
Expand Down Expand Up @@ -257,6 +260,18 @@ BraveBrowserProcessImpl::greaselion_download_service() {
}
#endif

debounce::DebounceComponentInstaller*
BraveBrowserProcessImpl::debounce_component_installer() {
if (!base::FeatureList::IsEnabled(debounce::features::kBraveDebounce))
return nullptr;
if (!debounce_component_installer_) {
pilgrim-brave marked this conversation as resolved.
Show resolved Hide resolved
debounce_component_installer_ =
std::make_unique<debounce::DebounceComponentInstaller>(
local_data_files_service());
}
return debounce_component_installer_.get();
}

brave_shields::HTTPSEverywhereService*
BraveBrowserProcessImpl::https_everywhere_service() {
if (!https_everywhere_service_)
Expand Down Expand Up @@ -285,8 +300,7 @@ void BraveBrowserProcessImpl::OnBraveDarkModeChanged() {
}

#if BUILDFLAG(ENABLE_TOR)
tor::BraveTorClientUpdater*
BraveBrowserProcessImpl::tor_client_updater() {
tor::BraveTorClientUpdater* BraveBrowserProcessImpl::tor_client_updater() {
if (tor_client_updater_)
return tor_client_updater_.get();

Expand All @@ -302,7 +316,8 @@ void BraveBrowserProcessImpl::OnTorEnabledChanged() {
// Update all browsers' tor command status.
for (Browser* browser : *BrowserList::GetInstance()) {
static_cast<chrome::BraveBrowserCommandController*>(
browser->command_controller())->UpdateCommandForTor();
browser->command_controller())
->UpdateCommandForTor();
}
}
#endif
Expand Down Expand Up @@ -400,8 +415,7 @@ BraveBrowserProcessImpl::speedreader_rewriter_service() {
#endif // BUILDFLAG(ENABLE_SPEEDREADER)

#if BUILDFLAG(ENABLE_IPFS)
ipfs::BraveIpfsClientUpdater*
BraveBrowserProcessImpl::ipfs_client_updater() {
ipfs::BraveIpfsClientUpdater* BraveBrowserProcessImpl::ipfs_client_updater() {
if (ipfs_client_updater_)
return ipfs_client_updater_.get();

Expand Down
7 changes: 7 additions & 0 deletions browser/brave_browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class GreaselionDownloadService;
#endif
} // namespace greaselion

namespace debounce {
class DebounceComponentInstaller;
} // namespace debounce

namespace ntp_background_images {
class NTPBackgroundImagesService;
} // namespace ntp_background_images
Expand Down Expand Up @@ -96,6 +100,7 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess,
#if BUILDFLAG(ENABLE_GREASELION)
greaselion::GreaselionDownloadService* greaselion_download_service() override;
#endif
debounce::DebounceComponentInstaller* debounce_component_installer() override;
brave_shields::HTTPSEverywhereService* https_everywhere_service() override;
brave_component_updater::LocalDataFilesService* local_data_files_service()
override;
Expand Down Expand Up @@ -149,6 +154,8 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess,
std::unique_ptr<greaselion::GreaselionDownloadService>
greaselion_download_service_;
#endif
std::unique_ptr<debounce::DebounceComponentInstaller>
debounce_component_installer_;
std::unique_ptr<brave_shields::HTTPSEverywhereService>
https_everywhere_service_;
std::unique_ptr<brave_stats::BraveStatsUpdater> brave_stats_updater_;
Expand Down
12 changes: 12 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "brave/browser/brave_browser_main_extra_parts.h"
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/brave_shields/brave_shields_web_contents_observer.h"
#include "brave/browser/debounce/debounce_service_factory.h"
#include "brave/browser/ethereum_remote_client/buildflags/buildflags.h"
#include "brave/browser/net/brave_proxying_url_loader_factory.h"
#include "brave/browser/net/brave_proxying_web_socket.h"
Expand All @@ -43,6 +44,7 @@
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/cosmetic_filters/browser/cosmetic_filters_resources.h"
#include "brave/components/cosmetic_filters/common/cosmetic_filters.mojom.h"
#include "brave/components/debounce/browser/debounce_throttle.h"
#include "brave/components/decentralized_dns/buildflags/buildflags.h"
#include "brave/components/ftx/browser/buildflags/buildflags.h"
#include "brave/components/gemini/browser/buildflags/buildflags.h"
Expand Down Expand Up @@ -528,6 +530,16 @@ BraveContentBrowserClient::CreateURLLoaderThrottles(
}
}
#endif // ENABLE_SPEEDREADER

auto* settings_map = HostContentSettingsMapFactory::GetForProfile(
Profile::FromBrowserContext(browser_context));
if (std::unique_ptr<blink::URLLoaderThrottle> debounce_throttle =
debounce::DebounceThrottle::MaybeCreateThrottleFor(
debounce::DebounceServiceFactory::GetForBrowserContext(
browser_context),
settings_map))
result.push_back(std::move(debounce_throttle));

return result;
}

Expand Down
2 changes: 2 additions & 0 deletions browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/browser/brave_shields/ad_block_pref_service_factory.h"
#include "brave/browser/brave_shields/cookie_pref_service_factory.h"
#include "brave/browser/debounce/debounce_service_factory.h"
#include "brave/browser/ethereum_remote_client/buildflags/buildflags.h"
#include "brave/browser/ntp_background_images/view_counter_service_factory.h"
#include "brave/browser/permissions/permission_lifetime_manager_factory.h"
Expand Down Expand Up @@ -61,6 +62,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
brave_rewards::RewardsServiceFactory::GetInstance();
brave_shields::AdBlockPrefServiceFactory::GetInstance();
brave_shields::CookiePrefServiceFactory::GetInstance();
debounce::DebounceServiceFactory::GetInstance();
#if BUILDFLAG(ENABLE_GREASELION)
greaselion::GreaselionServiceFactory::GetInstance();
#endif
Expand Down
Loading