Skip to content

Commit

Permalink
Implement debouncing
Browse files Browse the repository at this point in the history
  • Loading branch information
pilgrim-brave committed Aug 20, 2021
1 parent e398b7b commit c790771
Show file tree
Hide file tree
Showing 33 changed files with 1,206 additions and 28 deletions.
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 @@ -57,6 +58,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 @@ -111,6 +113,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 tracking URLs";

constexpr char kBraveExtensionNetworkBlockingName[] =
"Enable extension network blocking";
constexpr char kBraveExtensionNetworkBlockingDescription[] =
Expand Down Expand Up @@ -344,6 +350,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 @@ -29,6 +29,8 @@
#include "brave/components/brave_shields/browser/ad_block_service.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 @@ -47,8 +49,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 @@ -86,8 +88,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 @@ -135,8 +137,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 @@ -184,14 +186,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 @@ -251,6 +254,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_) {
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 @@ -279,8 +294,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 @@ -296,7 +310,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 @@ -394,8 +409,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 @@ -523,6 +525,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 @@ -55,6 +56,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

0 comments on commit c790771

Please sign in to comment.