From e4bcce8cd384d49ae0698b29c561c71fd9bd6d2c Mon Sep 17 00:00:00 2001 From: bridiver Date: Mon, 20 May 2019 15:40:10 -0700 Subject: [PATCH 01/13] use public static ComponentsUI::OnDemandUpdate method --- browser/extensions/brave_component_extension.cc | 16 +++++----------- browser/extensions/brave_component_extension.h | 14 ++------------ browser/extensions/brave_component_loader.cc | 17 ++++++++++++----- browser/extensions/brave_component_loader.h | 2 ++ .../crl_set_component_installer.cc | 5 ++--- .../widevine_cdm_component_installer.cc | 7 ++----- components/brave_shields/browser/BUILD.gn | 1 + .../ad_block_regional_service_manager.cc | 2 +- .../brave_shields/browser/ad_block_service.h | 1 + 9 files changed, 28 insertions(+), 37 deletions(-) diff --git a/browser/extensions/brave_component_extension.cc b/browser/extensions/brave_component_extension.cc index ffb34dcefdc8..31d592988e64 100644 --- a/browser/extensions/brave_component_extension.cc +++ b/browser/extensions/brave_component_extension.cc @@ -12,14 +12,9 @@ #include "base/callback.h" #include "brave/browser/component_updater/brave_component_installer.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/ui/webui/components_ui.h" +#include "components/component_updater/component_updater_service.h" -void ComponentsUI::OnDemandUpdate( - component_updater::ComponentUpdateService* cus, - const std::string& component_id) { - cus->GetOnDemandUpdater().OnDemandUpdate( - component_id, component_updater::OnDemandUpdater::Priority::FOREGROUND, - component_updater::Callback()); -} BraveComponentExtension::BraveComponentExtension() { } @@ -46,14 +41,13 @@ void BraveComponentExtension::Register( registered_callback, ready_callback); } -// static -bool BraveComponentExtension::Unregister(const std::string& component_id) { +bool BraveComponentExtension::Unregister() { return g_browser_process->component_updater()->UnregisterComponent( - component_id); + component_id_); } void BraveComponentExtension::OnComponentRegistered(const std::string& component_id) { - OnDemandUpdate(g_browser_process->component_updater(), component_id); + ComponentsUI::OnDemandUpdate(component_id); } void BraveComponentExtension::OnComponentReady( diff --git a/browser/extensions/brave_component_extension.h b/browser/extensions/brave_component_extension.h index f9a5f783dfb7..50348a492770 100644 --- a/browser/extensions/brave_component_extension.h +++ b/browser/extensions/brave_component_extension.h @@ -9,25 +9,15 @@ #include #include "base/files/file_path.h" -#include "components/component_updater/component_updater_service.h" -// Just used to give access to OnDemandUpdater since it's private. -// Chromium has ComponentsUI which is a friend class, so we just -// do this hack here to gain access. -class ComponentsUI { - public: - void OnDemandUpdate(component_updater::ComponentUpdateService* cus, - const std::string& component_id); -}; - -class BraveComponentExtension : public ComponentsUI { +class BraveComponentExtension { public: BraveComponentExtension(); virtual ~BraveComponentExtension(); void Register(const std::string& component_name, const std::string& component_id, const std::string& component_base64_public_key); - static bool Unregister(const std::string& component_id); + bool Unregister(); protected: virtual void OnComponentRegistered(const std::string& component_id); diff --git a/browser/extensions/brave_component_loader.cc b/browser/extensions/brave_component_loader.cc index 11f0ab83a4db..a95ea5dbfb67 100644 --- a/browser/extensions/brave_component_loader.cc +++ b/browser/extensions/brave_component_loader.cc @@ -19,6 +19,7 @@ #include "brave/components/brave_rewards/resources/extension/grit/brave_rewards_extension_resources.h" #include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/webui/components_ui.h" #include "chrome/common/pref_names.h" #include "components/grit/brave_components_resources.h" #include "extensions/browser/extension_prefs.h" @@ -27,9 +28,13 @@ namespace extensions { // static bool BraveComponentLoader::IsPdfjsDisabled() { +#if defined(OS_ANDROID) + return true; +#else const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); return command_line.HasSwitch(switches::kDisablePDFJSExtension); +#endif } BraveComponentLoader::BraveComponentLoader( @@ -41,18 +46,18 @@ BraveComponentLoader::BraveComponentLoader( profile_(profile), profile_prefs_(profile_prefs), testing_callbacks_(nullptr) { +// TODO(bridiver) - this doesn't belong here +#if !defined(OS_ANDROID) ObserveOpenPdfExternallySetting(); +#endif } BraveComponentLoader::~BraveComponentLoader() { } void BraveComponentLoader::OnComponentRegistered(std::string extension_id) { - ComponentsUI demand_updater; - // This weird looking call is ok, it is just like this to not need - // to patch for friend access. - demand_updater.OnDemandUpdate(g_browser_process->component_updater(), - extension_id); + // TODO(bridiver) - I don't think this is correct + ComponentsUI::OnDemandUpdate(extension_id); } void BraveComponentLoader::OnComponentReady(std::string extension_id, @@ -126,6 +131,7 @@ void BraveComponentLoader::AddDefaultComponentExtensions( } } +#if !defined(OS_ANDROID) void BraveComponentLoader::ObserveOpenPdfExternallySetting() { // Observe the setting change only in regular profiles since the PDF settings // page is not available in Guest/Tor profiles. @@ -137,6 +143,7 @@ void BraveComponentLoader::ObserveOpenPdfExternallySetting() { base::Unretained(this))); } } +#endif void BraveComponentLoader::UpdatePdfExtension(const std::string& pref_name) { DCHECK(pref_name == prefs::kPluginsAlwaysOpenPdfExternally); diff --git a/browser/extensions/brave_component_loader.h b/browser/extensions/brave_component_loader.h index 96aac12a09e0..8bd95731a4f4 100644 --- a/browser/extensions/brave_component_loader.h +++ b/browser/extensions/brave_component_loader.h @@ -48,7 +48,9 @@ class BraveComponentLoader : public ComponentLoader { void AddHangoutServicesExtension() override; #endif // BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION) friend class ::BraveComponentLoaderTest; +#if !defined(OS_ANDROID) void ObserveOpenPdfExternallySetting(); +#endif // Callback for changes to the AlwaysOpenPdfExternally setting. void UpdatePdfExtension(const std::string& pref_name); diff --git a/chromium_src/chrome/browser/component_updater/crl_set_component_installer.cc b/chromium_src/chrome/browser/component_updater/crl_set_component_installer.cc index 33f235d8683e..aabbe79119cd 100644 --- a/chromium_src/chrome/browser/component_updater/crl_set_component_installer.cc +++ b/chromium_src/chrome/browser/component_updater/crl_set_component_installer.cc @@ -12,6 +12,7 @@ #if !defined(OS_ANDROID) #include "brave/browser/extensions/brave_component_extension.h" #include "brave/common/extensions/extension_constants.h" +#include "chrome/browser/ui/webui/components_ui.h" #endif namespace component_updater { @@ -19,9 +20,7 @@ namespace component_updater { void OnCRLSetRegistered() { // https://github.com/brave/browser-android-tabs/issues/857 #if !defined(OS_ANDROID) - ComponentsUI demand_updater; - demand_updater.OnDemandUpdate(g_browser_process->component_updater(), - crl_set_extension_id); + ComponentsUI::OnDemandUpdate(crl_set_extension_id); #endif } diff --git a/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc b/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc index ebecea6f4610..f3d6a1419803 100644 --- a/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc +++ b/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc @@ -10,6 +10,7 @@ #include "brave/browser/extensions/brave_component_extension.h" #include "brave/common/pref_names.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/ui/webui/components_ui.h" #include "brave/common/extensions/extension_constants.h" #include "components/component_updater/component_updater_service.h" #include "components/prefs/pref_service.h" @@ -21,11 +22,7 @@ namespace component_updater { void OnWidevineRegistered() { - ComponentsUI demand_updater; - // This weird looking call is ok, it is just like this to not need - // to patch for friend access. - demand_updater.OnDemandUpdate(g_browser_process->component_updater(), - widevine_extension_id); + ComponentsUI::OnDemandUpdate(widevine_extension_id); } void RegisterAndInstallWidevine() { diff --git a/components/brave_shields/browser/BUILD.gn b/components/brave_shields/browser/BUILD.gn index 9167db9b0588..265bda48d03f 100644 --- a/components/brave_shields/browser/BUILD.gn +++ b/components/brave_shields/browser/BUILD.gn @@ -59,6 +59,7 @@ source_set("brave_shields") { "//brave/vendor/tracking-protection/brave:tracking-protection", "//brave/vendor/autoplay-whitelist/brave:autoplay-whitelist", "//chrome/common", + "//components/prefs", "//third_party/leveldatabase", ] diff --git a/components/brave_shields/browser/ad_block_regional_service_manager.cc b/components/brave_shields/browser/ad_block_regional_service_manager.cc index dd0e80f5462e..445743a78804 100644 --- a/components/brave_shields/browser/ad_block_regional_service_manager.cc +++ b/components/brave_shields/browser/ad_block_regional_service_manager.cc @@ -164,7 +164,7 @@ void AdBlockRegionalServiceManager::EnableFilterList(const std::string& uuid, } else { DCHECK(it != regional_services_.end()); it->second->Stop(); - BraveComponentExtension::Unregister(uuid); + it->second->Unregister(); regional_services_.erase(it); } } diff --git a/components/brave_shields/browser/ad_block_service.h b/components/brave_shields/browser/ad_block_service.h index 193f315a20f9..afe0a31d869f 100644 --- a/components/brave_shields/browser/ad_block_service.h +++ b/components/brave_shields/browser/ad_block_service.h @@ -13,6 +13,7 @@ #include #include "brave/components/brave_shields/browser/ad_block_base_service.h" +#include "components/prefs/pref_registry_simple.h" #include "content/public/common/resource_type.h" class AdBlockServiceTest; From d00fdec246c03e274ef73c5a627cc1c092cdf479 Mon Sep 17 00:00:00 2001 From: bridiver Date: Mon, 20 May 2019 16:04:32 -0700 Subject: [PATCH 02/13] remove redundant methods --- components/brave_shields/browser/ad_block_base_service.cc | 1 - .../browser/ad_block_custom_filters_service.cc | 6 ------ .../browser/ad_block_custom_filters_service.h | 1 - .../brave_shields/browser/ad_block_regional_service.cc | 8 -------- .../brave_shields/browser/ad_block_regional_service.h | 1 - .../browser/ad_block_regional_service_manager.cc | 6 ------ .../browser/ad_block_regional_service_manager.h | 1 - 7 files changed, 24 deletions(-) diff --git a/components/brave_shields/browser/ad_block_base_service.cc b/components/brave_shields/browser/ad_block_base_service.cc index 5a6c82bdeeb7..e2abb0d250f0 100644 --- a/components/brave_shields/browser/ad_block_base_service.cc +++ b/components/brave_shields/browser/ad_block_base_service.cc @@ -17,7 +17,6 @@ #include "base/memory/ptr_util.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" -#include "brave/browser/brave_browser_process_impl.h" #include "brave/browser/net/url_context.h" #include "brave/common/pref_names.h" #include "brave/components/brave_shields/browser/dat_file_util.h" diff --git a/components/brave_shields/browser/ad_block_custom_filters_service.cc b/components/brave_shields/browser/ad_block_custom_filters_service.cc index 9540ae207f77..fb3c8950704d 100644 --- a/components/brave_shields/browser/ad_block_custom_filters_service.cc +++ b/components/brave_shields/browser/ad_block_custom_filters_service.cc @@ -58,12 +58,6 @@ void AdBlockCustomFiltersService::UpdateCustomFiltersOnFileTaskRunner( ad_block_client_->parse(custom_filters.c_str()); } -scoped_refptr -AdBlockCustomFiltersService::GetTaskRunner() { - // We share the same task runner for all ad-block and TP code - return g_brave_browser_process->ad_block_service()->GetTaskRunner(); -} - /////////////////////////////////////////////////////////////////////////////// std::unique_ptr diff --git a/components/brave_shields/browser/ad_block_custom_filters_service.h b/components/brave_shields/browser/ad_block_custom_filters_service.h index 8e580f3e4e9a..fa00e49204a3 100644 --- a/components/brave_shields/browser/ad_block_custom_filters_service.h +++ b/components/brave_shields/browser/ad_block_custom_filters_service.h @@ -24,7 +24,6 @@ class AdBlockCustomFiltersService : public AdBlockBaseService { std::string GetCustomFilters(); bool UpdateCustomFilters(const std::string& custom_filters); - scoped_refptr GetTaskRunner() override; protected: bool Init() override; diff --git a/components/brave_shields/browser/ad_block_regional_service.cc b/components/brave_shields/browser/ad_block_regional_service.cc index f50f93447e8b..5aac1930f2f1 100644 --- a/components/brave_shields/browser/ad_block_regional_service.cc +++ b/components/brave_shields/browser/ad_block_regional_service.cc @@ -18,14 +18,12 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" -#include "brave/browser/brave_browser_process_impl.h" #include "brave/common/pref_names.h" #include "brave/components/brave_shields/browser/ad_block_service.h" #include "brave/components/brave_shields/browser/ad_block_service_helper.h" #include "brave/vendor/ad-block/ad_block_client.h" #include "brave/vendor/ad-block/data_file_version.h" #include "brave/vendor/ad-block/lists/regions.h" -#include "chrome/browser/profiles/profile_manager.h" #include "components/prefs/pref_service.h" namespace brave_shields { @@ -88,12 +86,6 @@ void AdBlockRegionalService::SetDATFileVersionForTest( g_ad_block_regional_dat_file_version_ = dat_file_version; } -scoped_refptr -AdBlockRegionalService::GetTaskRunner() { - // We share the same task runner for all ad-block and TP code - return g_brave_browser_process->ad_block_service()->GetTaskRunner(); -} - /////////////////////////////////////////////////////////////////////////////// std::unique_ptr AdBlockRegionalServiceFactory( diff --git a/components/brave_shields/browser/ad_block_regional_service.h b/components/brave_shields/browser/ad_block_regional_service.h index 005fe7664339..a6f493e62efa 100644 --- a/components/brave_shields/browser/ad_block_regional_service.h +++ b/components/brave_shields/browser/ad_block_regional_service.h @@ -29,7 +29,6 @@ class AdBlockRegionalService : public AdBlockBaseService { std::string GetUUID() const { return uuid_; } std::string GetTitle() const { return title_; } - scoped_refptr GetTaskRunner() override; protected: bool Init() override; diff --git a/components/brave_shields/browser/ad_block_regional_service_manager.cc b/components/brave_shields/browser/ad_block_regional_service_manager.cc index 445743a78804..2da187d7cfcf 100644 --- a/components/brave_shields/browser/ad_block_regional_service_manager.cc +++ b/components/brave_shields/browser/ad_block_regional_service_manager.cc @@ -177,12 +177,6 @@ void AdBlockRegionalServiceManager::EnableFilterList(const std::string& uuid, base::Unretained(this), uuid, enabled)); } -scoped_refptr -AdBlockRegionalServiceManager::GetTaskRunner() { - // We share the same task runner for all ad-block and TP code - return g_brave_browser_process->ad_block_service()->GetTaskRunner(); -} - // static bool AdBlockRegionalServiceManager::IsSupportedLocale( const std::string& locale) { diff --git a/components/brave_shields/browser/ad_block_regional_service_manager.h b/components/brave_shields/browser/ad_block_regional_service_manager.h index 4564612f28cb..28120fce3b69 100644 --- a/components/brave_shields/browser/ad_block_regional_service_manager.h +++ b/components/brave_shields/browser/ad_block_regional_service_manager.h @@ -46,7 +46,6 @@ class AdBlockRegionalServiceManager { bool* cancel_request_explicitly); void EnableTag(const std::string& tag, bool enabled); void EnableFilterList(const std::string& uuid, bool enabled); - scoped_refptr GetTaskRunner(); private: friend class ::AdBlockServiceTest; From 32f2432c8a53a62ae865bdef5469d47636ce0c33 Mon Sep 17 00:00:00 2001 From: bridiver Date: Mon, 20 May 2019 16:33:57 -0700 Subject: [PATCH 03/13] move datfile utilities to brave_component_updater --- components/brave_component_updater/browser/BUILD.gn | 6 ++++++ .../browser/dat_file_util.cc | 6 +++--- .../browser/dat_file_util.h | 10 +++++----- components/brave_shields/browser/BUILD.gn | 3 +-- .../brave_shields/browser/ad_block_base_service.cc | 5 ++--- .../brave_shields/browser/ad_block_base_service.h | 4 ++-- .../browser/autoplay_whitelist_service.cc | 6 ++++-- .../brave_shields/browser/autoplay_whitelist_service.h | 4 ++-- .../browser/extension_whitelist_service.cc | 6 ++++-- .../browser/extension_whitelist_service.h | 4 ++-- .../brave_shields/browser/https_everywhere_service.cc | 3 +-- .../browser/referrer_whitelist_service.cc | 6 ++++-- .../brave_shields/browser/referrer_whitelist_service.h | 1 - .../browser/tracking_protection_service.cc | 8 +++++--- .../browser/tracking_protection_service.h | 6 +++--- 15 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 components/brave_component_updater/browser/BUILD.gn rename components/{brave_shields => brave_component_updater}/browser/dat_file_util.cc (89%) rename components/{brave_shields => brave_component_updater}/browser/dat_file_util.h (69%) diff --git a/components/brave_component_updater/browser/BUILD.gn b/components/brave_component_updater/browser/BUILD.gn new file mode 100644 index 000000000000..b976096f55d8 --- /dev/null +++ b/components/brave_component_updater/browser/BUILD.gn @@ -0,0 +1,6 @@ +source_set("browser") { + sources = [ + "dat_file_util.cc", + "dat_file_util.h", + ] +} diff --git a/components/brave_shields/browser/dat_file_util.cc b/components/brave_component_updater/browser/dat_file_util.cc similarity index 89% rename from components/brave_shields/browser/dat_file_util.cc rename to components/brave_component_updater/browser/dat_file_util.cc index 40d1fa009fa7..42f61f9e14c8 100644 --- a/components/brave_shields/browser/dat_file_util.cc +++ b/components/brave_component_updater/browser/dat_file_util.cc @@ -3,14 +3,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "brave/components/brave_shields/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/dat_file_util.h" #include #include "base/files/file_path.h" #include "base/files/file_util.h" -namespace brave_shields { +namespace brave_component_updater { void GetDATFileData(const base::FilePath& file_path, DATFileDataBuffer* buffer) { @@ -42,4 +42,4 @@ void GetDATFileAsString(const base::FilePath& file_path, } } -} // namespace brave_shields +} // namespace brave_component_updater diff --git a/components/brave_shields/browser/dat_file_util.h b/components/brave_component_updater/browser/dat_file_util.h similarity index 69% rename from components/brave_shields/browser/dat_file_util.h rename to components/brave_component_updater/browser/dat_file_util.h index adc4e7a76a36..d0da8a9e45ab 100644 --- a/components/brave_shields/browser/dat_file_util.h +++ b/components/brave_component_updater/browser/dat_file_util.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DAT_FILE_UTIL_H_ -#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DAT_FILE_UTIL_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_DAT_FILE_UTIL_H_ +#define BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_DAT_FILE_UTIL_H_ #include #include @@ -15,7 +15,7 @@ namespace base { class FilePath; } -namespace brave_shields { +namespace brave_component_updater { using DATFileDataBuffer = std::vector; @@ -24,6 +24,6 @@ void GetDATFileData(const base::FilePath& file_path, void GetDATFileAsString(const base::FilePath& file_path, std::string* contents); -} // namespace brave_shields +} // namespace brave_component_updater -#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DAT_FILE_UTIL_H_ +#endif // BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_DAT_FILE_UTIL_H_ diff --git a/components/brave_shields/browser/BUILD.gn b/components/brave_shields/browser/BUILD.gn index 265bda48d03f..2a4dc53a445a 100644 --- a/components/brave_shields/browser/BUILD.gn +++ b/components/brave_shields/browser/BUILD.gn @@ -33,8 +33,6 @@ source_set("brave_shields") { "brave_shields_web_contents_observer.h", "brave_resource_dispatcher_host_delegate.cc", "brave_resource_dispatcher_host_delegate.h", - "dat_file_util.cc", - "dat_file_util.h", "https_everywhere_recently_used_cache.h", "https_everywhere_service.cc", "https_everywhere_service.h", @@ -54,6 +52,7 @@ source_set("brave_shields") { } deps = [ + "//brave/components/brave_component_updater/browser", "//brave/content:common", "//brave/vendor/ad-block/brave:ad-block", "//brave/vendor/tracking-protection/brave:tracking-protection", diff --git a/components/brave_shields/browser/ad_block_base_service.cc b/components/brave_shields/browser/ad_block_base_service.cc index e2abb0d250f0..f26efb02eba0 100644 --- a/components/brave_shields/browser/ad_block_base_service.cc +++ b/components/brave_shields/browser/ad_block_base_service.cc @@ -19,10 +19,9 @@ #include "base/threading/thread_restrictions.h" #include "brave/browser/net/url_context.h" #include "brave/common/pref_names.h" -#include "brave/components/brave_shields/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/dat_file_util.h" #include "brave/components/brave_shields/common/brave_shield_constants.h" #include "brave/vendor/ad-block/ad_block_client.h" -#include "chrome/browser/profiles/profile_manager.h" #include "components/prefs/pref_service.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "url/origin.h" @@ -182,7 +181,7 @@ void AdBlockBaseService::EnableTagOnFileTaskRunner( void AdBlockBaseService::GetDATFileData(const base::FilePath& dat_file_path) { GetTaskRunner()->PostTaskAndReply( FROM_HERE, - base::Bind(&brave_shields::GetDATFileData, dat_file_path, &buffer_), + base::Bind(&brave_component_updater::GetDATFileData, dat_file_path, &buffer_), base::Bind(&AdBlockBaseService::OnDATFileDataReady, weak_factory_.GetWeakPtr())); } diff --git a/components/brave_shields/browser/ad_block_base_service.h b/components/brave_shields/browser/ad_block_base_service.h index 0e8980075220..504bf92eb807 100644 --- a/components/brave_shields/browser/ad_block_base_service.h +++ b/components/brave_shields/browser/ad_block_base_service.h @@ -16,7 +16,7 @@ #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" #include "brave/components/brave_shields/browser/base_brave_shields_service.h" -#include "brave/components/brave_shields/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/dat_file_util.h" #include "content/public/common/resource_type.h" class AdBlockClient; @@ -47,7 +47,7 @@ class AdBlockBaseService : public BaseBraveShieldsService { SEQUENCE_CHECKER(sequence_checker_); std::unique_ptr ad_block_client_; - DATFileDataBuffer buffer_; + brave_component_updater::DATFileDataBuffer buffer_; private: void OnDATFileDataReady(); diff --git a/components/brave_shields/browser/autoplay_whitelist_service.cc b/components/brave_shields/browser/autoplay_whitelist_service.cc index 96cec9c760a7..9d37c6390430 100644 --- a/components/brave_shields/browser/autoplay_whitelist_service.cc +++ b/components/brave_shields/browser/autoplay_whitelist_service.cc @@ -18,7 +18,7 @@ #include "brave/browser/brave_browser_process_impl.h" #include "brave/components/brave_shields/browser/ad_block_service.h" #include "brave/components/brave_shields/browser/local_data_files_service.h" -#include "brave/components/brave_shields/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/dat_file_util.h" #include "brave/vendor/autoplay-whitelist/autoplay_whitelist_parser.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" @@ -67,7 +67,9 @@ void AutoplayWhitelistService::OnComponentReady( GetTaskRunner()->PostTaskAndReply( FROM_HERE, - base::Bind(&GetDATFileData, dat_file_path, &buffer_), + base::Bind(&brave_component_updater::GetDATFileData, + dat_file_path, + &buffer_), base::Bind(&AutoplayWhitelistService::OnDATFileDataReady, weak_factory_.GetWeakPtr())); } diff --git a/components/brave_shields/browser/autoplay_whitelist_service.h b/components/brave_shields/browser/autoplay_whitelist_service.h index 9734c04d650c..f254e69ebd73 100644 --- a/components/brave_shields/browser/autoplay_whitelist_service.h +++ b/components/brave_shields/browser/autoplay_whitelist_service.h @@ -18,7 +18,7 @@ #include "base/sequence_checker.h" #include "base/sequenced_task_runner.h" #include "brave/components/brave_shields/browser/base_local_data_files_observer.h" -#include "brave/components/brave_shields/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/dat_file_util.h" #include "content/public/common/resource_type.h" #include "url/gurl.h" @@ -46,7 +46,7 @@ class AutoplayWhitelistService : public BaseLocalDataFilesObserver { void OnDATFileDataReady(); - brave_shields::DATFileDataBuffer buffer_; + brave_component_updater::DATFileDataBuffer buffer_; std::unique_ptr autoplay_whitelist_client_; diff --git a/components/brave_shields/browser/extension_whitelist_service.cc b/components/brave_shields/browser/extension_whitelist_service.cc index 7379cf9aa491..2fa5532b5985 100644 --- a/components/brave_shields/browser/extension_whitelist_service.cc +++ b/components/brave_shields/browser/extension_whitelist_service.cc @@ -18,7 +18,7 @@ #include "brave/browser/brave_browser_process_impl.h" #include "brave/components/brave_shields/browser/ad_block_service.h" #include "brave/components/brave_shields/browser/local_data_files_service.h" -#include "brave/components/brave_shields/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/dat_file_util.h" #include "brave/vendor/extension-whitelist/extension_whitelist_parser.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" @@ -68,7 +68,9 @@ void ExtensionWhitelistService::OnComponentReady( GetTaskRunner()->PostTaskAndReply( FROM_HERE, - base::Bind(&GetDATFileData, dat_file_path, &buffer_), + base::Bind(&brave_component_updater::GetDATFileData, + dat_file_path, + &buffer_), base::Bind(&ExtensionWhitelistService::OnDATFileDataReady, weak_factory_.GetWeakPtr())); } diff --git a/components/brave_shields/browser/extension_whitelist_service.h b/components/brave_shields/browser/extension_whitelist_service.h index 56ab51dd55d0..4870ee7abf3c 100644 --- a/components/brave_shields/browser/extension_whitelist_service.h +++ b/components/brave_shields/browser/extension_whitelist_service.h @@ -18,7 +18,7 @@ #include "base/sequence_checker.h" #include "base/sequenced_task_runner.h" #include "brave/components/brave_shields/browser/base_local_data_files_observer.h" -#include "brave/components/brave_shields/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/dat_file_util.h" #include "content/public/common/resource_type.h" #include "url/gurl.h" @@ -49,7 +49,7 @@ class ExtensionWhitelistService : public BaseLocalDataFilesObserver { void OnDATFileDataReady(); - brave_shields::DATFileDataBuffer buffer_; + brave_component_updater::DATFileDataBuffer buffer_; std::unique_ptr extension_whitelist_client_; diff --git a/components/brave_shields/browser/https_everywhere_service.cc b/components/brave_shields/browser/https_everywhere_service.cc index ba1ece7162a2..e25a111adbf3 100644 --- a/components/brave_shields/browser/https_everywhere_service.cc +++ b/components/brave_shields/browser/https_everywhere_service.cc @@ -11,6 +11,7 @@ #include #include "base/base_paths.h" +#include "base/bind.h" #include "base/json/json_reader.h" #include "base/logging.h" #include "base/macros.h" @@ -18,8 +19,6 @@ #include "base/strings/utf_string_conversions.h" #include "base/threading/scoped_blocking_call.h" #include "base/values.h" -#include "brave/components/brave_shields/browser/dat_file_util.h" -#include "chrome/browser/browser_process.h" #include "third_party/leveldatabase/src/include/leveldb/db.h" #include "third_party/re2/src/re2/re2.h" #include "third_party/zlib/google/zip.h" diff --git a/components/brave_shields/browser/referrer_whitelist_service.cc b/components/brave_shields/browser/referrer_whitelist_service.cc index ee7ffe85ef89..d04870abb4ef 100644 --- a/components/brave_shields/browser/referrer_whitelist_service.cc +++ b/components/brave_shields/browser/referrer_whitelist_service.cc @@ -19,7 +19,7 @@ #include "brave/browser/brave_browser_process_impl.h" #include "brave/components/brave_shields/browser/ad_block_service.h" #include "brave/components/brave_shields/browser/local_data_files_service.h" -#include "brave/components/brave_shields/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/dat_file_util.h" namespace brave_shields { @@ -93,7 +93,9 @@ void ReferrerWhitelistService::OnComponentReady( REFERRER_DAT_FILE_VERSION).AppendASCII(REFERRER_DAT_FILE); GetTaskRunner()->PostTaskAndReply( FROM_HERE, - base::Bind(&GetDATFileAsString, dat_file_path, &file_contents_), + base::Bind(&brave_component_updater::GetDATFileAsString, + dat_file_path, + &file_contents_), base::Bind(&ReferrerWhitelistService::OnDATFileDataReady, weak_factory_.GetWeakPtr())); } diff --git a/components/brave_shields/browser/referrer_whitelist_service.h b/components/brave_shields/browser/referrer_whitelist_service.h index 941d14197356..fc3eb5b3280e 100644 --- a/components/brave_shields/browser/referrer_whitelist_service.h +++ b/components/brave_shields/browser/referrer_whitelist_service.h @@ -19,7 +19,6 @@ #include "base/sequenced_task_runner.h" #include "base/values.h" #include "brave/components/brave_shields/browser/base_local_data_files_observer.h" -#include "brave/components/brave_shields/browser/dat_file_util.h" #include "content/public/common/resource_type.h" #include "extensions/common/url_pattern.h" #include "url/gurl.h" diff --git a/components/brave_shields/browser/tracking_protection_service.cc b/components/brave_shields/browser/tracking_protection_service.cc index 03bb6fcce287..a3525068d299 100644 --- a/components/brave_shields/browser/tracking_protection_service.cc +++ b/components/brave_shields/browser/tracking_protection_service.cc @@ -18,7 +18,7 @@ #include "base/threading/thread_restrictions.h" #include "brave/browser/brave_browser_process_impl.h" #include "brave/components/brave_shields/browser/ad_block_service.h" -#include "brave/components/brave_shields/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/dat_file_util.h" #include "brave/components/brave_shields/browser/local_data_files_service.h" #include "brave/components/content_settings/core/browser/brave_cookie_settings.h" #include "brave/vendor/tracking-protection/TPParser.h" @@ -275,7 +275,8 @@ void TrackingProtectionService::OnComponentReady( GetTaskRunner()->PostTaskAndReply( FROM_HERE, - base::Bind(&GetDATFileData, navigation_tracking_protection_path, + base::Bind(&brave_component_updater::GetDATFileData, + navigation_tracking_protection_path, &buffer_), base::Bind(&TrackingProtectionService::OnDATFileDataReady, weak_factory_.GetWeakPtr())); @@ -290,7 +291,8 @@ void TrackingProtectionService::OnComponentReady( GetTaskRunner()->PostTaskAndReply( FROM_HERE, - base::Bind(&GetDATFileData, storage_tracking_protection_path, + base::Bind(&brave_component_updater::GetDATFileData, + storage_tracking_protection_path, &storage_trackers_buffer_), base::Bind(&TrackingProtectionService::ParseStorageTrackersData, weak_factory_.GetWeakPtr())); diff --git a/components/brave_shields/browser/tracking_protection_service.h b/components/brave_shields/browser/tracking_protection_service.h index fde162479211..1622ba16a4ec 100644 --- a/components/brave_shields/browser/tracking_protection_service.h +++ b/components/brave_shields/browser/tracking_protection_service.h @@ -23,7 +23,7 @@ #include "base/synchronization/lock.h" #include "brave/components/brave_shields/browser/base_local_data_files_observer.h" #include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP -#include "brave/components/brave_shields/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/dat_file_util.h" #include "content/public/common/resource_type.h" #include "url/gurl.h" @@ -116,9 +116,9 @@ class TrackingProtectionService : public BaseLocalDataFilesObserver { base::flat_set first_party_storage_trackers_; std::map render_frame_key_to_starting_site_url; - brave_shields::DATFileDataBuffer storage_trackers_buffer_; + brave_component_updater::DATFileDataBuffer storage_trackers_buffer_; #endif - brave_shields::DATFileDataBuffer buffer_; + brave_component_updater::DATFileDataBuffer buffer_; std::unique_ptr tracking_protection_client_; std::vector third_party_base_hosts_; From 1f1468fa32469ba47bffe321c227d93345eb0321 Mon Sep 17 00:00:00 2001 From: bridiver Date: Mon, 20 May 2019 20:29:34 -0700 Subject: [PATCH 04/13] replace BraveComponentExtension with BraveComponent fix https://github.com/brave/brave-browser/issues/4577 --- browser/BUILD.gn | 7 +-- browser/brave_browser_process_impl.cc | 28 +++++++-- browser/brave_browser_process_impl.h | 6 ++ .../brave_component_installer.cc | 23 ++++---- .../brave_component_installer.h | 12 ++-- .../brave_component_updater_delegate.cc | 44 ++++++++++++++ .../brave_component_updater_delegate.h | 36 +++++++++++ browser/extensions/BUILD.gn | 1 + .../extensions/brave_component_extension.cc | 57 ------------------ .../extensions/brave_component_extension.h | 34 ----------- browser/extensions/brave_component_loader.cc | 1 - .../extensions/brave_tor_client_updater.cc | 18 +++--- browser/extensions/brave_tor_client_updater.h | 11 ++-- .../crl_set_component_installer.cc | 1 - .../widevine_cdm_component_installer.cc | 1 - .../brave_component_updater/browser/BUILD.gn | 6 ++ .../browser/brave_component.cc | 53 +++++++++++++++++ .../browser/brave_component.h | 59 +++++++++++++++++++ .../browser/dat_file_util.h | 2 - .../browser/ad_block_base_service.cc | 5 +- .../browser/ad_block_base_service.h | 4 +- .../ad_block_custom_filters_service.cc | 9 ++- .../browser/ad_block_custom_filters_service.h | 6 +- .../browser/ad_block_regional_service.cc | 12 ++-- .../browser/ad_block_regional_service.h | 7 ++- .../ad_block_regional_service_manager.cc | 14 +++-- .../ad_block_regional_service_manager.h | 8 ++- .../brave_shields/browser/ad_block_service.cc | 16 +++-- .../brave_shields/browser/ad_block_service.h | 5 +- .../browser/base_brave_shields_service.cc | 9 ++- .../browser/base_brave_shields_service.h | 9 +-- .../browser/https_everywhere_service.cc | 13 ++-- .../browser/https_everywhere_service.h | 7 ++- .../browser/local_data_files_service.cc | 20 +++---- .../browser/local_data_files_service.h | 12 ++-- 35 files changed, 362 insertions(+), 194 deletions(-) create mode 100644 browser/component_updater/brave_component_updater_delegate.cc create mode 100644 browser/component_updater/brave_component_updater_delegate.h delete mode 100644 browser/extensions/brave_component_extension.cc delete mode 100644 browser/extensions/brave_component_extension.h create mode 100644 components/brave_component_updater/browser/brave_component.cc create mode 100644 components/brave_component_updater/browser/brave_component.h diff --git a/browser/BUILD.gn b/browser/BUILD.gn index d50e2d85d14c..009e08298ac0 100644 --- a/browser/BUILD.gn +++ b/browser/BUILD.gn @@ -46,14 +46,12 @@ source_set("browser_process") { "component_updater/brave_component_installer.h", "component_updater/brave_component_updater_configurator.cc", "component_updater/brave_component_updater_configurator.h", + "component_updater/brave_component_updater_delegate.cc", + "component_updater/brave_component_updater_delegate.h", "component_updater/brave_crx_update_service.cc", "component_updater/brave_crx_update_service.h", "content_settings/brave_cookie_settings_factory.cc", "content_settings/brave_cookie_settings_factory.h", - # TODO(bridiver) - move this from extensions -> component_updater - # and rename to BraveComponent - "extensions/brave_component_extension.cc", - "extensions/brave_component_extension.h", "geolocation/brave_geolocation_permission_context.cc", "geolocation/brave_geolocation_permission_context.h", "mac/sparkle_glue.mm", @@ -91,6 +89,7 @@ source_set("browser_process") { "//brave/browser/tor", "//brave/common", "//brave/components/brave_ads/browser", + "//brave/components/brave_component_updater/browser", "//brave/components/brave_referrals/browser", "//brave/components/brave_rewards/browser", "//brave/components/brave_shields/browser:brave_shields", diff --git a/browser/brave_browser_process_impl.cc b/browser/brave_browser_process_impl.cc index c6267149bac2..e85feb7060d4 100644 --- a/browser/brave_browser_process_impl.cc +++ b/browser/brave_browser_process_impl.cc @@ -13,6 +13,7 @@ #include "base/threading/sequenced_task_runner_handle.h" #include "brave/browser/brave_stats_updater.h" #include "brave/browser/component_updater/brave_component_updater_configurator.h" +#include "brave/browser/component_updater/brave_component_updater_delegate.h" #include "brave/browser/extensions/brave_tor_client_updater.h" #include "brave/browser/profiles/brave_profile_manager.h" #include "brave/components/brave_shields/browser/ad_block_custom_filters_service.h" @@ -76,6 +77,15 @@ BraveBrowserProcessImpl::BraveBrowserProcessImpl(StartupData* startup_data) base::Unretained(brave_stats_updater_.get()))); } +brave_component_updater::BraveComponent::Delegate* +BraveBrowserProcessImpl::brave_component_updater_delegate() { + if (!brave_component_updater_delegate_) + brave_component_updater_delegate_ = + std::make_unique(); + + return brave_component_updater_delegate_.get(); +} + component_updater::ComponentUpdateService* BraveBrowserProcessImpl::component_updater() { if (component_updater_) @@ -117,7 +127,8 @@ BraveBrowserProcessImpl::ad_block_service() { if (ad_block_service_) return ad_block_service_.get(); - ad_block_service_ = brave_shields::AdBlockServiceFactory(); + ad_block_service_ = + brave_shields::AdBlockServiceFactory(brave_component_updater_delegate()); return ad_block_service_.get(); } @@ -125,7 +136,8 @@ brave_shields::AdBlockCustomFiltersService* BraveBrowserProcessImpl::ad_block_custom_filters_service() { if (!ad_block_custom_filters_service_) ad_block_custom_filters_service_ = - brave_shields::AdBlockCustomFiltersServiceFactory(); + brave_shields::AdBlockCustomFiltersServiceFactory( + brave_component_updater_delegate()); return ad_block_custom_filters_service_.get(); } @@ -133,7 +145,8 @@ brave_shields::AdBlockRegionalServiceManager* BraveBrowserProcessImpl::ad_block_regional_service_manager() { if (!ad_block_regional_service_manager_) ad_block_regional_service_manager_ = - brave_shields::AdBlockRegionalServiceManagerFactory(); + brave_shields::AdBlockRegionalServiceManagerFactory( + brave_component_updater_delegate()); return ad_block_regional_service_manager_.get(); } @@ -179,7 +192,8 @@ brave_shields::HTTPSEverywhereService* BraveBrowserProcessImpl::https_everywhere_service() { if (!https_everywhere_service_) https_everywhere_service_ = - brave_shields::HTTPSEverywhereServiceFactory(); + brave_shields::HTTPSEverywhereServiceFactory( + brave_component_updater_delegate()); return https_everywhere_service_.get(); } @@ -187,7 +201,8 @@ brave_shields::LocalDataFilesService* BraveBrowserProcessImpl::local_data_files_service() { if (!local_data_files_service_) local_data_files_service_ = - brave_shields::LocalDataFilesServiceFactory(); + brave_shields::LocalDataFilesServiceFactory( + brave_component_updater_delegate()); return local_data_files_service_.get(); } @@ -197,7 +212,8 @@ BraveBrowserProcessImpl::tor_client_updater() { if (tor_client_updater_) return tor_client_updater_.get(); - tor_client_updater_ = extensions::BraveTorClientUpdaterFactory(); + tor_client_updater_ = extensions::BraveTorClientUpdaterFactory( + brave_component_updater_delegate()); return tor_client_updater_.get(); } #endif diff --git a/browser/brave_browser_process_impl.h b/browser/brave_browser_process_impl.h index 0acde8c42eae..96e2f158a54b 100644 --- a/browser/brave_browser_process_impl.h +++ b/browser/brave_browser_process_impl.h @@ -9,6 +9,7 @@ #include #include "brave/browser/tor/buildflags.h" +#include "brave/components/brave_component_updater/browser/brave_component.h" #include "brave/components/brave_referrals/buildflags/buildflags.h" #include "chrome/browser/browser_process_impl.h" #include "extensions/buildflags/buildflags.h" @@ -39,6 +40,8 @@ namespace extensions { class BraveTorClientUpdater; } +using brave_component_updater::BraveComponent; + class BraveBrowserProcessImpl : public BrowserProcessImpl { public: explicit BraveBrowserProcessImpl(StartupData* startup_data); @@ -71,6 +74,9 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl { private: void CreateProfileManager(); + BraveComponent::Delegate* brave_component_updater_delegate(); + + std::unique_ptr brave_component_updater_delegate_; std::unique_ptr ad_block_service_; std::unique_ptr ad_block_custom_filters_service_; diff --git a/browser/component_updater/brave_component_installer.cc b/browser/component_updater/brave_component_installer.cc index 7382813f0775..2b4be0864ad9 100644 --- a/browser/component_updater/brave_component_installer.cc +++ b/browser/component_updater/brave_component_installer.cc @@ -77,10 +77,10 @@ namespace brave { BraveComponentInstallerPolicy::BraveComponentInstallerPolicy( const std::string& name, const std::string& base64_public_key, - const ReadyCallback& ready_callback) + ReadyCallback ready_callback) : name_(name), base64_public_key_(base64_public_key), - ready_callback_(ready_callback) { + ready_callback_(std::move(ready_callback)) { base::Base64Decode(base64_public_key, &public_key_); } @@ -117,10 +117,12 @@ void BraveComponentInstallerPolicy::OnCustomUninstall() { } void BraveComponentInstallerPolicy::ComponentReady( - const base::Version& version, - const base::FilePath& install_dir, - std::unique_ptr manifest) { - ready_callback_.Run(install_dir, GetManifestString(*manifest, base64_public_key_)); + const base::Version& version, + const base::FilePath& install_dir, + std::unique_ptr manifest) { + std::move(ready_callback_).Run( + install_dir, + GetManifestString(*manifest, base64_public_key_)); } base::FilePath BraveComponentInstallerPolicy::GetRelativeInstallDir() const { @@ -152,11 +154,12 @@ void RegisterComponent( component_updater::ComponentUpdateService* cus, const std::string& name, const std::string& base64_public_key, - const base::Closure& registered_callback, - const ReadyCallback& ready_callback) { + base::OnceClosure registered_callback, + ReadyCallback ready_callback) { auto installer = base::MakeRefCounted( - std::make_unique(name, base64_public_key, ready_callback)); - installer->Register(cus, registered_callback); + std::make_unique( + name, base64_public_key, std::move(ready_callback))); + installer->Register(cus, std::move(registered_callback)); } } // namespace brave diff --git a/browser/component_updater/brave_component_installer.h b/browser/component_updater/brave_component_installer.h index 520b885e16c7..a2cafa316ba1 100644 --- a/browser/component_updater/brave_component_installer.h +++ b/browser/component_updater/brave_component_installer.h @@ -18,11 +18,7 @@ #include "components/component_updater/component_installer.h" #include "components/update_client/update_client.h" -namespace base { -class FilePath; -} // namespace base - -using ReadyCallback = base::Callback; namespace brave { @@ -32,7 +28,7 @@ class BraveComponentInstallerPolicy : public: explicit BraveComponentInstallerPolicy(const std::string& name, const std::string& base64_public_key, - const ReadyCallback& ready_callback); + ReadyCallback ready_callback); ~BraveComponentInstallerPolicy() override; @@ -67,8 +63,8 @@ class BraveComponentInstallerPolicy : void RegisterComponent(component_updater::ComponentUpdateService* cus, const std::string& name, const std::string& base64_public_key, - const base::Closure& registered_callback, - const ReadyCallback& ready_callback); + base::OnceClosure registered_callback, + ReadyCallback ready_callback); } // namespace brave diff --git a/browser/component_updater/brave_component_updater_delegate.cc b/browser/component_updater/brave_component_updater_delegate.cc new file mode 100644 index 000000000000..d3826d38ca8b --- /dev/null +++ b/browser/component_updater/brave_component_updater_delegate.cc @@ -0,0 +1,44 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/component_updater/brave_component_updater_delegate.h" + +#include "brave/browser/component_updater/brave_component_installer.h" +#include "chrome/browser/ui/webui/components_ui.h" +#include "chrome/browser/browser_process.h" +#include "components/component_updater/component_updater_service.h" + +using brave_component_updater::BraveComponent; + +namespace brave { + +BraveComponentUpdaterDelegate::BraveComponentUpdaterDelegate() { +} + +BraveComponentUpdaterDelegate::~BraveComponentUpdaterDelegate() {} + +void BraveComponentUpdaterDelegate::Register( + const std::string& component_name, + const std::string& component_base64_public_key, + base::OnceClosure registered_callback, + BraveComponent::ReadyCallback ready_callback) { + brave::RegisterComponent(g_browser_process->component_updater(), + component_name, + component_base64_public_key, + std::move(registered_callback), + std::move(ready_callback)); +} + +bool BraveComponentUpdaterDelegate::Unregister( + const std::string& component_id) { + return g_browser_process->component_updater()->UnregisterComponent( + component_id); +} + +void BraveComponentUpdaterDelegate::OnDemandUpdate( + const std::string& component_id) { + ComponentsUI::OnDemandUpdate(component_id); +} + +} // namespace brave diff --git a/browser/component_updater/brave_component_updater_delegate.h b/browser/component_updater/brave_component_updater_delegate.h new file mode 100644 index 000000000000..6b4d1293536f --- /dev/null +++ b/browser/component_updater/brave_component_updater_delegate.h @@ -0,0 +1,36 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_UPDATER_DELEGATE_H_ +#define BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_UPDATER_DELEGATE_H_ + +#include + +#include "base/macros.h" +#include "brave/components/brave_component_updater/browser/brave_component.h" + +using brave_component_updater::BraveComponent; + +namespace brave { + +class BraveComponentUpdaterDelegate : public BraveComponent::Delegate { + public: + BraveComponentUpdaterDelegate(); + ~BraveComponentUpdaterDelegate() override; + + // brave_component_updater::BraveComponent::Delegate implementation + void Register(const std::string& component_name, + const std::string& component_base64_public_key, + base::OnceClosure registered_callback, + BraveComponent::ReadyCallback ready_callback) override; + bool Unregister(const std::string& component_id) override; + void OnDemandUpdate(const std::string& component_id) override; + + private: + DISALLOW_COPY_AND_ASSIGN(BraveComponentUpdaterDelegate); +}; + +} // namespace brave + +#endif // BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_UPDATER_DELEGATE_H_ diff --git a/browser/extensions/BUILD.gn b/browser/extensions/BUILD.gn index e9b1c55fe5c6..458fb23096f1 100644 --- a/browser/extensions/BUILD.gn +++ b/browser/extensions/BUILD.gn @@ -45,6 +45,7 @@ source_set("extensions") { "//brave/app:brave_generated_resources_grit", "//brave/common:pref_names", "//brave/common/extensions/api", + "//brave/components/brave_component_updater/browser", "//brave/components/brave_extension:static_resources", "//brave/components/brave_extension:generated_resources", "//brave/components/brave_sync", diff --git a/browser/extensions/brave_component_extension.cc b/browser/extensions/brave_component_extension.cc deleted file mode 100644 index 31d592988e64..000000000000 --- a/browser/extensions/brave_component_extension.cc +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/browser/extensions/brave_component_extension.h" - -#include - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/callback.h" -#include "brave/browser/component_updater/brave_component_installer.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/ui/webui/components_ui.h" -#include "components/component_updater/component_updater_service.h" - - -BraveComponentExtension::BraveComponentExtension() { -} - -BraveComponentExtension::~BraveComponentExtension() { -} - -void BraveComponentExtension::Register( - const std::string& component_name, - const std::string& component_id, - const std::string& component_base64_public_key) { - component_name_ = component_name; - component_id_ = component_id; - component_base64_public_key_ = component_base64_public_key; - - base::Closure registered_callback = - base::Bind(&BraveComponentExtension::OnComponentRegistered, - base::Unretained(this), component_id_); - ReadyCallback ready_callback = - base::Bind(&BraveComponentExtension::OnComponentReady, - base::Unretained(this), component_id_); - brave::RegisterComponent(g_browser_process->component_updater(), - component_name_, component_base64_public_key_, - registered_callback, ready_callback); -} - -bool BraveComponentExtension::Unregister() { - return g_browser_process->component_updater()->UnregisterComponent( - component_id_); -} - -void BraveComponentExtension::OnComponentRegistered(const std::string& component_id) { - ComponentsUI::OnDemandUpdate(component_id); -} - -void BraveComponentExtension::OnComponentReady( - const std::string& component_id, - const base::FilePath& install_dir, - const std::string& manifest) { -} diff --git a/browser/extensions/brave_component_extension.h b/browser/extensions/brave_component_extension.h deleted file mode 100644 index 50348a492770..000000000000 --- a/browser/extensions/brave_component_extension.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_BROWSER_EXTENSIONS_BRAVE_COMPONENT_EXTENSION_H_ -#define BRAVE_BROWSER_EXTENSIONS_BRAVE_COMPONENT_EXTENSION_H_ - -#include - -#include "base/files/file_path.h" - -class BraveComponentExtension { - public: - BraveComponentExtension(); - virtual ~BraveComponentExtension(); - void Register(const std::string& component_name, - const std::string& component_id, - const std::string& component_base64_public_key); - bool Unregister(); - - protected: - virtual void OnComponentRegistered(const std::string& component_id); - virtual void OnComponentReady(const std::string& component_id, - const base::FilePath& install_dir, - const std::string& manifest); - - private: - std::string component_name_; - std::string component_id_; - std::string component_base64_public_key_; -}; - -#endif // BRAVE_BROWSER_EXTENSIONS_BRAVE_COMPONENT_EXTENSION_H_ diff --git a/browser/extensions/brave_component_loader.cc b/browser/extensions/brave_component_loader.cc index a95ea5dbfb67..27ce4c616f51 100644 --- a/browser/extensions/brave_component_loader.cc +++ b/browser/extensions/brave_component_loader.cc @@ -10,7 +10,6 @@ #include "base/command_line.h" #include "brave/browser/brave_browser_process_impl.h" #include "brave/browser/component_updater/brave_component_installer.h" -#include "brave/browser/extensions/brave_component_extension.h" #include "brave/common/brave_switches.h" #include "brave/common/extensions/extension_constants.h" #include "brave/common/pref_names.h" diff --git a/browser/extensions/brave_tor_client_updater.cc b/browser/extensions/brave_tor_client_updater.cc index 8550b7f47516..7e119fe1d389 100644 --- a/browser/extensions/brave_tor_client_updater.cc +++ b/browser/extensions/brave_tor_client_updater.cc @@ -10,6 +10,8 @@ #include "base/task/post_task.h" #include "third_party/re2/src/re2/re2.h" +using brave_component_updater::BraveComponent; + namespace extensions { std::string BraveTorClientUpdater::g_tor_client_component_id_( @@ -17,8 +19,9 @@ std::string BraveTorClientUpdater::g_tor_client_component_id_( std::string BraveTorClientUpdater::g_tor_client_component_base64_public_key_( kTorClientComponentBase64PublicKey); -BraveTorClientUpdater::BraveTorClientUpdater() - : task_runner_( +BraveTorClientUpdater::BraveTorClientUpdater(BraveComponent::Delegate* delegate) + : BraveComponent(delegate), + task_runner_( base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()})), registered_(false) { } @@ -30,9 +33,9 @@ void BraveTorClientUpdater::Register() { if (registered_) return; - BraveComponentExtension::Register(kTorClientComponentName, - g_tor_client_component_id_, - g_tor_client_component_base64_public_key_); + BraveComponent::Register(kTorClientComponentName, + g_tor_client_component_id_, + g_tor_client_component_base64_public_key_); registered_ = true; } @@ -96,8 +99,9 @@ void BraveTorClientUpdater::SetComponentIdAndBase64PublicKeyForTest( /////////////////////////////////////////////////////////////////////////////// // The Brave Tor client extension factory. -std::unique_ptr BraveTorClientUpdaterFactory() { - return std::make_unique(); +std::unique_ptr +BraveTorClientUpdaterFactory(BraveComponent::Delegate* delegate) { + return std::make_unique(delegate); } } // namespace extensions diff --git a/browser/extensions/brave_tor_client_updater.h b/browser/extensions/brave_tor_client_updater.h index 0ddfabc3757f..32a25c725a04 100644 --- a/browser/extensions/brave_tor_client_updater.h +++ b/browser/extensions/brave_tor_client_updater.h @@ -7,10 +7,12 @@ #include "base/files/file_path.h" #include "base/sequenced_task_runner.h" -#include "brave/browser/extensions/brave_component_extension.h" +#include "brave/components/brave_component_updater/browser/brave_component.h" class BraveTorClientUpdaterTest; +using brave_component_updater::BraveComponent; + namespace extensions { #if defined(OS_WIN) @@ -48,9 +50,9 @@ const std::string kTorClientComponentBase64PublicKey = "2QIDAQAB"; #endif -class BraveTorClientUpdater : public BraveComponentExtension { +class BraveTorClientUpdater : public BraveComponent { public: - BraveTorClientUpdater(); + BraveTorClientUpdater(BraveComponent::Delegate* delegate); ~BraveTorClientUpdater() override; void Register(); @@ -81,7 +83,8 @@ class BraveTorClientUpdater : public BraveComponentExtension { }; // Creates the BraveTorClientUpdater -std::unique_ptr BraveTorClientUpdaterFactory(); +std::unique_ptr +BraveTorClientUpdaterFactory(BraveComponent::Delegate* delegate); } // namespace extensions diff --git a/chromium_src/chrome/browser/component_updater/crl_set_component_installer.cc b/chromium_src/chrome/browser/component_updater/crl_set_component_installer.cc index aabbe79119cd..868e66846c2f 100644 --- a/chromium_src/chrome/browser/component_updater/crl_set_component_installer.cc +++ b/chromium_src/chrome/browser/component_updater/crl_set_component_installer.cc @@ -10,7 +10,6 @@ #include "chrome/browser/browser_process.h" #if !defined(OS_ANDROID) -#include "brave/browser/extensions/brave_component_extension.h" #include "brave/common/extensions/extension_constants.h" #include "chrome/browser/ui/webui/components_ui.h" #endif diff --git a/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc b/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc index f3d6a1419803..e2ea79a836de 100644 --- a/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc +++ b/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc @@ -7,7 +7,6 @@ #undef RegisterWidevineCdmComponent #include "brave/browser/brave_browser_process_impl.h" -#include "brave/browser/extensions/brave_component_extension.h" #include "brave/common/pref_names.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/webui/components_ui.h" diff --git a/components/brave_component_updater/browser/BUILD.gn b/components/brave_component_updater/browser/BUILD.gn index b976096f55d8..f782a061a2d0 100644 --- a/components/brave_component_updater/browser/BUILD.gn +++ b/components/brave_component_updater/browser/BUILD.gn @@ -1,6 +1,12 @@ source_set("browser") { sources = [ + "brave_component.cc", + "brave_component.h", "dat_file_util.cc", "dat_file_util.h", ] + + deps = [ + "//base", + ] } diff --git a/components/brave_component_updater/browser/brave_component.cc b/components/brave_component_updater/browser/brave_component.cc new file mode 100644 index 000000000000..fa79bb0c5938 --- /dev/null +++ b/components/brave_component_updater/browser/brave_component.cc @@ -0,0 +1,53 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/brave_component_updater/browser/brave_component.h" + +#include "base/bind.h" +#include "base/bind_helpers.h" + +namespace brave_component_updater { + +BraveComponent::BraveComponent(Delegate* delegate) : delegate_(delegate) {} + +BraveComponent::~BraveComponent() { +} + +void BraveComponent::Register(const std::string& component_name, + const std::string& component_id, + const std::string& component_base64_public_key) { + auto registered_callback = + base::BindOnce(&BraveComponent::OnComponentRegistered, + delegate_, + component_id); + auto ready_callback = + base::BindOnce(&BraveComponent::OnComponentReady, + AsWeakPtr(), + component_id); + + delegate_->Register(component_name_, + component_base64_public_key_, + std::move(registered_callback), + std::move(ready_callback)); +} + +bool BraveComponent::Unregister() { + return delegate_->Unregister(component_id_); +} + +// static +void BraveComponent::OnComponentRegistered( + Delegate* delegate, + const std::string& component_id) { + delegate->OnDemandUpdate(component_id); +} + +void BraveComponent::OnComponentReady( + const std::string& component_id, + const base::FilePath& install_dir, + const std::string& manifest) { +} + +} // namespace brave_component_updater diff --git a/components/brave_component_updater/browser/brave_component.h b/components/brave_component_updater/browser/brave_component.h new file mode 100644 index 000000000000..998189bc69d2 --- /dev/null +++ b/components/brave_component_updater/browser/brave_component.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_BRAVE_COMPONENT_H_ +#define BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_BRAVE_COMPONENT_H_ + +#include + +#include "base/callback.h" +#include "base/files/file_path.h" +#include "base/macros.h" +#include "base/memory/weak_ptr.h" + +namespace brave_component_updater { + +class BraveComponent : public base::SupportsWeakPtr { + public: + using ReadyCallback = base::OnceCallback; + class Delegate { + public: + virtual ~Delegate() = default; + virtual void Register(const std::string& component_name, + const std::string& component_base64_public_key, + base::OnceClosure registered_callback, + ReadyCallback ready_callback) = 0; + virtual bool Unregister(const std::string& component_id) = 0; + virtual void OnDemandUpdate(const std::string& component_id) = 0; + }; + + BraveComponent(Delegate* delegate); + virtual ~BraveComponent(); + void Register(const std::string& component_name, + const std::string& component_id, + const std::string& component_base64_public_key); + bool Unregister(); + + protected: + virtual void OnComponentReady(const std::string& component_id, + const base::FilePath& install_dir, + const std::string& manifest); + + private: + static void OnComponentRegistered(Delegate* delegate, + const std::string& component_id); + + std::string component_name_; + std::string component_id_; + std::string component_base64_public_key_; + Delegate* delegate_; // NOT OWNED + + DISALLOW_COPY_AND_ASSIGN(BraveComponent); +}; + +} // namespace brave_component_updater + +#endif // BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_BRAVE_COMPONENT_H_ diff --git a/components/brave_component_updater/browser/dat_file_util.h b/components/brave_component_updater/browser/dat_file_util.h index d0da8a9e45ab..d660232c03cd 100644 --- a/components/brave_component_updater/browser/dat_file_util.h +++ b/components/brave_component_updater/browser/dat_file_util.h @@ -9,8 +9,6 @@ #include #include -#include "base/callback_forward.h" - namespace base { class FilePath; } diff --git a/components/brave_shields/browser/ad_block_base_service.cc b/components/brave_shields/browser/ad_block_base_service.cc index f26efb02eba0..fb24024fccb7 100644 --- a/components/brave_shields/browser/ad_block_base_service.cc +++ b/components/brave_shields/browser/ad_block_base_service.cc @@ -26,6 +26,7 @@ #include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "url/origin.h" +using brave_component_updater::BraveComponent; using namespace net::registry_controlled_domains; // NOLINT namespace { @@ -104,8 +105,8 @@ FilterOption ResourceTypeToFilterOption(content::ResourceType resource_type) { namespace brave_shields { -AdBlockBaseService::AdBlockBaseService() - : BaseBraveShieldsService(), +AdBlockBaseService::AdBlockBaseService(BraveComponent::Delegate* delegate) + : BaseBraveShieldsService(delegate), ad_block_client_(new AdBlockClient()), weak_factory_(this) { DETACH_FROM_SEQUENCE(sequence_checker_); diff --git a/components/brave_shields/browser/ad_block_base_service.h b/components/brave_shields/browser/ad_block_base_service.h index 504bf92eb807..c147a3f1ce33 100644 --- a/components/brave_shields/browser/ad_block_base_service.h +++ b/components/brave_shields/browser/ad_block_base_service.h @@ -22,13 +22,15 @@ class AdBlockClient; class AdBlockServiceTest; +using brave_component_updater::BraveComponent; + namespace brave_shields { // The base class of the brave shields service in charge of ad-block // checking and init. class AdBlockBaseService : public BaseBraveShieldsService { public: - AdBlockBaseService(); + AdBlockBaseService(BraveComponent::Delegate* delegate); ~AdBlockBaseService() override; bool ShouldStartRequest(const GURL &url, content::ResourceType resource_type, diff --git a/components/brave_shields/browser/ad_block_custom_filters_service.cc b/components/brave_shields/browser/ad_block_custom_filters_service.cc index fb3c8950704d..f75c65e849ab 100644 --- a/components/brave_shields/browser/ad_block_custom_filters_service.cc +++ b/components/brave_shields/browser/ad_block_custom_filters_service.cc @@ -13,9 +13,12 @@ #include "components/prefs/pref_service.h" #include "content/public/browser/browser_thread.h" +using brave_component_updater::BraveComponent; + namespace brave_shields { -AdBlockCustomFiltersService::AdBlockCustomFiltersService() { +AdBlockCustomFiltersService::AdBlockCustomFiltersService( + BraveComponent::Delegate* delegate) : AdBlockBaseService(delegate) { } AdBlockCustomFiltersService::~AdBlockCustomFiltersService() { @@ -61,8 +64,8 @@ void AdBlockCustomFiltersService::UpdateCustomFiltersOnFileTaskRunner( /////////////////////////////////////////////////////////////////////////////// std::unique_ptr -AdBlockCustomFiltersServiceFactory() { - return std::make_unique(); +AdBlockCustomFiltersServiceFactory(BraveComponent::Delegate* delegate) { + return std::make_unique(delegate); } } // namespace brave_shields diff --git a/components/brave_shields/browser/ad_block_custom_filters_service.h b/components/brave_shields/browser/ad_block_custom_filters_service.h index fa00e49204a3..e2bd4ac85430 100644 --- a/components/brave_shields/browser/ad_block_custom_filters_service.h +++ b/components/brave_shields/browser/ad_block_custom_filters_service.h @@ -13,13 +13,15 @@ class AdBlockServiceTest; +using brave_component_updater::BraveComponent; + namespace brave_shields { // The brave shields service in charge of custom filter ad-block // checking and init. class AdBlockCustomFiltersService : public AdBlockBaseService { public: - AdBlockCustomFiltersService(); + AdBlockCustomFiltersService(BraveComponent::Delegate* delegate); ~AdBlockCustomFiltersService() override; std::string GetCustomFilters(); @@ -37,7 +39,7 @@ class AdBlockCustomFiltersService : public AdBlockBaseService { // Creates the AdBlockCustomFiltersService std::unique_ptr -AdBlockCustomFiltersServiceFactory(); +AdBlockCustomFiltersServiceFactory(BraveComponent::Delegate* delegate); } // namespace brave_shields diff --git a/components/brave_shields/browser/ad_block_regional_service.cc b/components/brave_shields/browser/ad_block_regional_service.cc index 5aac1930f2f1..1cacf96ea888 100644 --- a/components/brave_shields/browser/ad_block_regional_service.cc +++ b/components/brave_shields/browser/ad_block_regional_service.cc @@ -34,8 +34,11 @@ std::string std::string AdBlockRegionalService::g_ad_block_regional_dat_file_version_( base::NumberToString(DATA_FILE_VERSION)); -AdBlockRegionalService::AdBlockRegionalService(const std::string& uuid) - : uuid_(uuid) { +AdBlockRegionalService::AdBlockRegionalService( + const std::string& uuid, + brave_component_updater::BraveComponent::Delegate* delegate) + : AdBlockBaseService(delegate), + uuid_(uuid) { } AdBlockRegionalService::~AdBlockRegionalService() { @@ -89,8 +92,9 @@ void AdBlockRegionalService::SetDATFileVersionForTest( /////////////////////////////////////////////////////////////////////////////// std::unique_ptr AdBlockRegionalServiceFactory( - const std::string& uuid) { - return std::make_unique(uuid); + const std::string& uuid, + brave_component_updater::BraveComponent::Delegate* delegate) { + return std::make_unique(uuid, delegate); } } // namespace brave_shields diff --git a/components/brave_shields/browser/ad_block_regional_service.h b/components/brave_shields/browser/ad_block_regional_service.h index a6f493e62efa..a0e488ebe122 100644 --- a/components/brave_shields/browser/ad_block_regional_service.h +++ b/components/brave_shields/browser/ad_block_regional_service.h @@ -24,7 +24,9 @@ namespace brave_shields { // for a specific region. class AdBlockRegionalService : public AdBlockBaseService { public: - explicit AdBlockRegionalService(const std::string& uuid); + explicit AdBlockRegionalService( + const std::string& uuid, + brave_component_updater::BraveComponent::Delegate* delegate); ~AdBlockRegionalService() override; std::string GetUUID() const { return uuid_; } @@ -54,7 +56,8 @@ class AdBlockRegionalService : public AdBlockBaseService { // Creates the AdBlockRegionalService std::unique_ptr AdBlockRegionalServiceFactory( - const std::string& uuid); + const std::string& uuid, + brave_component_updater::BraveComponent::Delegate* delegate); } // namespace brave_shields diff --git a/components/brave_shields/browser/ad_block_regional_service_manager.cc b/components/brave_shields/browser/ad_block_regional_service_manager.cc index 2da187d7cfcf..2afe25b6a3a9 100644 --- a/components/brave_shields/browser/ad_block_regional_service_manager.cc +++ b/components/brave_shields/browser/ad_block_regional_service_manager.cc @@ -25,8 +25,10 @@ namespace brave_shields { -AdBlockRegionalServiceManager::AdBlockRegionalServiceManager() - : initialized_(false) { +AdBlockRegionalServiceManager::AdBlockRegionalServiceManager( + brave_component_updater::BraveComponent::Delegate* delegate) + : delegate_(delegate), + initialized_(false) { if (Init()) { initialized_ = true; } @@ -76,7 +78,7 @@ void AdBlockRegionalServiceManager::StartRegionalServices() { if (regional_filter_dict) regional_filter_dict->GetBoolean("enabled", &enabled); if (enabled) { - auto regional_service = AdBlockRegionalServiceFactory(uuid); + auto regional_service = AdBlockRegionalServiceFactory(uuid, delegate_); regional_service->Start(); regional_services_.insert( std::make_pair(uuid, std::move(regional_service))); @@ -157,7 +159,7 @@ void AdBlockRegionalServiceManager::EnableFilterList(const std::string& uuid, auto it = regional_services_.find(uuid); if (enabled) { DCHECK(it == regional_services_.end()); - auto regional_service = AdBlockRegionalServiceFactory(uuid); + auto regional_service = AdBlockRegionalServiceFactory(uuid, delegate_); regional_service->Start(); regional_services_.insert( std::make_pair(uuid, std::move(regional_service))); @@ -224,8 +226,8 @@ AdBlockRegionalServiceManager::GetRegionalLists() { /////////////////////////////////////////////////////////////////////////////// std::unique_ptr -AdBlockRegionalServiceManagerFactory() { - return std::make_unique(); +AdBlockRegionalServiceManagerFactory(BraveComponent::Delegate* delegate) { + return std::make_unique(delegate); } } // namespace brave_shields diff --git a/components/brave_shields/browser/ad_block_regional_service_manager.h b/components/brave_shields/browser/ad_block_regional_service_manager.h index 28120fce3b69..e4a3820f12c1 100644 --- a/components/brave_shields/browser/ad_block_regional_service_manager.h +++ b/components/brave_shields/browser/ad_block_regional_service_manager.h @@ -13,6 +13,7 @@ #include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "base/synchronization/lock.h" +#include "brave/components/brave_component_updater/browser/brave_component.h" #include "content/public/common/resource_type.h" #include "url/gurl.h" @@ -22,6 +23,8 @@ class ListValue; class AdBlockServiceTest; +using brave_component_updater::BraveComponent; + namespace brave_shields { class AdBlockRegionalService; @@ -30,7 +33,7 @@ class AdBlockRegionalService; // managing regional AdBlock clients. class AdBlockRegionalServiceManager { public: - AdBlockRegionalServiceManager(); + AdBlockRegionalServiceManager(BraveComponent::Delegate* delegate); ~AdBlockRegionalServiceManager(); static bool IsSupportedLocale(const std::string& locale); @@ -53,6 +56,7 @@ class AdBlockRegionalServiceManager { void StartRegionalServices(); void UpdateFilterListPrefs(const std::string& uuid, bool enabled); + brave_component_updater::BraveComponent::Delegate* delegate_; // NOT OWNED bool initialized_; base::Lock regional_services_lock_; std::map> @@ -63,7 +67,7 @@ class AdBlockRegionalServiceManager { // Creates the AdBlockRegionalServiceManager std::unique_ptr -AdBlockRegionalServiceManagerFactory(); +AdBlockRegionalServiceManagerFactory(BraveComponent::Delegate* delegate); } // namespace brave_shields diff --git a/components/brave_shields/browser/ad_block_service.cc b/components/brave_shields/browser/ad_block_service.cc index 179ec852e9d2..6161c31a84ab 100644 --- a/components/brave_shields/browser/ad_block_service.cc +++ b/components/brave_shields/browser/ad_block_service.cc @@ -33,15 +33,20 @@ std::string AdBlockService::g_ad_block_component_base64_public_key_( std::string AdBlockService::g_ad_block_dat_file_version_( base::NumberToString(DATA_FILE_VERSION)); -AdBlockService::AdBlockService() { +AdBlockService::AdBlockService( + brave_component_updater::BraveComponent::Delegate* delegate) + : AdBlockBaseService(delegate) { } AdBlockService::~AdBlockService() { } bool AdBlockService::Init() { - AdBlockBaseService::Init(); - Register(kAdBlockComponentName, g_ad_block_component_id_, + if (!AdBlockBaseService::Init()) + return false; + + Register(kAdBlockComponentName, + g_ad_block_component_id_, g_ad_block_component_base64_public_key_); return true; } @@ -72,8 +77,9 @@ void AdBlockService::SetDATFileVersionForTest( /////////////////////////////////////////////////////////////////////////////// // The Adblock service factory. -std::unique_ptr AdBlockServiceFactory() { - return std::make_unique(); +std::unique_ptr AdBlockServiceFactory( + brave_component_updater::BraveComponent::Delegate* delegate) { + return std::make_unique(delegate); } void RegisterPrefsForAdBlockService(PrefRegistrySimple* registry) { diff --git a/components/brave_shields/browser/ad_block_service.h b/components/brave_shields/browser/ad_block_service.h index afe0a31d869f..6440a5c9ecae 100644 --- a/components/brave_shields/browser/ad_block_service.h +++ b/components/brave_shields/browser/ad_block_service.h @@ -34,7 +34,7 @@ const char kAdBlockComponentBase64PublicKey[] = // The brave shields service in charge of ad-block checking and init. class AdBlockService : public AdBlockBaseService { public: - AdBlockService(); + AdBlockService(brave_component_updater::BraveComponent::Delegate* delegate); ~AdBlockService() override; protected: @@ -57,7 +57,8 @@ class AdBlockService : public AdBlockBaseService { }; // Creates the AdBlockService -std::unique_ptr AdBlockServiceFactory(); +std::unique_ptr AdBlockServiceFactory( + brave_component_updater::BraveComponent::Delegate* delegate); // Registers the local_state preferences used by Adblock void RegisterPrefsForAdBlockService(PrefRegistrySimple* registry); diff --git a/components/brave_shields/browser/base_brave_shields_service.cc b/components/brave_shields/browser/base_brave_shields_service.cc index 11c6a5f673b5..c4e1fe409228 100644 --- a/components/brave_shields/browser/base_brave_shields_service.cc +++ b/components/brave_shields/browser/base_brave_shields_service.cc @@ -17,12 +17,15 @@ #include "base/memory/ptr_util.h" #include "base/task_runner_util.h" #include "base/task/post_task.h" -#include "base/threading/thread_restrictions.h" + +using brave_component_updater::BraveComponent; namespace brave_shields { -BaseBraveShieldsService::BaseBraveShieldsService() - : initialized_(false), +BaseBraveShieldsService::BaseBraveShieldsService( + BraveComponent::Delegate* delegate) + : BraveComponent(delegate), + initialized_(false), task_runner_( base::CreateSequencedTaskRunnerWithTraits({base::MayBlock(), base::TaskPriority::USER_VISIBLE, diff --git a/components/brave_shields/browser/base_brave_shields_service.h b/components/brave_shields/browser/base_brave_shields_service.h index 9c9ff6063741..92c9288f3f33 100644 --- a/components/brave_shields/browser/base_brave_shields_service.h +++ b/components/brave_shields/browser/base_brave_shields_service.h @@ -10,23 +10,24 @@ #include #include -#include // TODO(brave): is an unapproved C++11 header #include // NOLINT #include "base/files/file_path.h" #include "base/sequenced_task_runner.h" -#include "brave/browser/extensions/brave_component_extension.h" +#include "brave/components/brave_component_updater/browser/brave_component.h" #include "content/public/common/resource_type.h" #include "url/gurl.h" +using brave_component_updater::BraveComponent; + namespace brave_shields { // The brave shields service in charge of checking brave shields like ad-block, // tracking protection, etc. -class BaseBraveShieldsService : public BraveComponentExtension { +class BaseBraveShieldsService : public brave_component_updater::BraveComponent { public: - BaseBraveShieldsService(); + BaseBraveShieldsService(BraveComponent::Delegate* delegate); ~BaseBraveShieldsService() override; bool Start(); void Stop(); diff --git a/components/brave_shields/browser/https_everywhere_service.cc b/components/brave_shields/browser/https_everywhere_service.cc index e25a111adbf3..517b015bbc8f 100644 --- a/components/brave_shields/browser/https_everywhere_service.cc +++ b/components/brave_shields/browser/https_everywhere_service.cc @@ -86,7 +86,10 @@ std::string HTTPSEverywhereService::g_https_everywhere_component_base64_public_key_( kHTTPSEverywhereComponentBase64PublicKey); -HTTPSEverywhereService::HTTPSEverywhereService() : level_db_(nullptr) { +HTTPSEverywhereService::HTTPSEverywhereService( + BraveComponent::Delegate* delegate) + : BaseBraveShieldsService(delegate), + level_db_(nullptr) { DETACH_FROM_SEQUENCE(sequence_checker_); } @@ -102,7 +105,8 @@ void HTTPSEverywhereService::Cleanup() { } bool HTTPSEverywhereService::Init() { - Register(kHTTPSEverywhereComponentName, g_https_everywhere_component_id_, + Register(kHTTPSEverywhereComponentName, + g_https_everywhere_component_id_, g_https_everywhere_component_base64_public_key_); return true; } @@ -391,8 +395,9 @@ void HTTPSEverywhereService::SetIgnorePortForTest(bool ignore) { // The brave shields factory. Using the Brave Shields as a singleton // is the job of the browser process. -std::unique_ptr HTTPSEverywhereServiceFactory() { - return std::make_unique(); +std::unique_ptr HTTPSEverywhereServiceFactory( + BraveComponent::Delegate* delegate) { + return std::make_unique(delegate); } } // namespace brave_shields diff --git a/components/brave_shields/browser/https_everywhere_service.h b/components/brave_shields/browser/https_everywhere_service.h index 9b90f10aa9f5..69a4e04b68ea 100644 --- a/components/brave_shields/browser/https_everywhere_service.h +++ b/components/brave_shields/browser/https_everywhere_service.h @@ -24,6 +24,8 @@ class DB; class HTTPSEverywhereServiceTest; +using brave_component_updater::BraveComponent; + namespace brave_shields { const std::string kHTTPSEverywhereComponentName("Brave HTTPS Everywhere Updater"); @@ -52,7 +54,7 @@ struct HTTPSE_REDIRECTS_COUNT_ST { class HTTPSEverywhereService : public BaseBraveShieldsService { public: - HTTPSEverywhereService(); + HTTPSEverywhereService(BraveComponent::Delegate* delegate); ~HTTPSEverywhereService() override; bool GetHTTPSURL(const GURL* url, const uint64_t& request_id, std::string& new_url); @@ -96,7 +98,8 @@ class HTTPSEverywhereService : public BaseBraveShieldsService { }; // Creates the HTTPSEverywhereService -std::unique_ptr HTTPSEverywhereServiceFactory(); +std::unique_ptr HTTPSEverywhereServiceFactory( + BraveComponent::Delegate* delegate); } // namespace brave_shields diff --git a/components/brave_shields/browser/local_data_files_service.cc b/components/brave_shields/browser/local_data_files_service.cc index b31fa50ee9ae..5dcea95550c5 100644 --- a/components/brave_shields/browser/local_data_files_service.cc +++ b/components/brave_shields/browser/local_data_files_service.cc @@ -4,19 +4,13 @@ #include "brave/components/brave_shields/browser/local_data_files_service.h" -#include #include #include "base/base_paths.h" -#include "base/bind.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/memory/ptr_util.h" -#include "base/strings/utf_string_conversions.h" -#include "base/threading/thread_restrictions.h" -#include "brave/browser/brave_browser_process_impl.h" #include "brave/components/brave_shields/browser/base_local_data_files_observer.h" +using brave_component_updater::BraveComponent; + namespace brave_shields { std::string LocalDataFilesService::g_local_data_files_component_id_( @@ -24,8 +18,9 @@ std::string LocalDataFilesService::g_local_data_files_component_id_( std::string LocalDataFilesService::g_local_data_files_component_base64_public_key_( kLocalDataFilesComponentBase64PublicKey); -LocalDataFilesService::LocalDataFilesService() - : initialized_(false), +LocalDataFilesService::LocalDataFilesService(BraveComponent::Delegate* delegate) + : BraveComponent(delegate), + initialized_(false), observers_already_called_(false), weak_factory_(this) { DETACH_FROM_SEQUENCE(sequence_checker_); @@ -69,8 +64,9 @@ void LocalDataFilesService::SetComponentIdAndBase64PublicKeyForTest( // The brave shields factory. Using the Brave Shields as a singleton // is the job of the browser process. -std::unique_ptr LocalDataFilesServiceFactory() { - return std::make_unique(); +std::unique_ptr +LocalDataFilesServiceFactory(BraveComponent::Delegate* delegate) { + return std::make_unique(delegate); } } // namespace brave_shields diff --git a/components/brave_shields/browser/local_data_files_service.h b/components/brave_shields/browser/local_data_files_service.h index 08982f6bc666..e9ba4b01843e 100644 --- a/components/brave_shields/browser/local_data_files_service.h +++ b/components/brave_shields/browser/local_data_files_service.h @@ -16,14 +16,15 @@ #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" -#include "brave/browser/extensions/brave_component_extension.h" -#include "content/public/common/resource_type.h" +#include "brave/components/brave_component_updater/browser/brave_component.h" class AdBlockServiceTest; class AutoplayWhitelistServiceTest; class ReferrerWhitelistServiceTest; class TrackingProtectionServiceTest; +using brave_component_updater::BraveComponent; + namespace brave_shields { class BaseLocalDataFilesObserver; @@ -41,9 +42,9 @@ const char kLocalDataFilesComponentBase64PublicKey[] = // The component in charge of delegating access to different DAT files // such as tracking protection and video autoplay whitelist -class LocalDataFilesService : public BraveComponentExtension { +class LocalDataFilesService : public BraveComponent { public: - LocalDataFilesService(); + LocalDataFilesService(BraveComponent::Delegate* delegate); ~LocalDataFilesService() override; bool Start(); bool IsInitialized() const { return initialized_; } @@ -75,7 +76,8 @@ class LocalDataFilesService : public BraveComponentExtension { }; // Creates the LocalDataFilesService -std::unique_ptr LocalDataFilesServiceFactory(); +std::unique_ptr +LocalDataFilesServiceFactory(BraveComponent::Delegate* delegate); } // namespace brave_shields From d2ab6d39cfb6093b2490f4d049b0b324703b2b07 Mon Sep 17 00:00:00 2001 From: bridiver Date: Mon, 20 May 2019 21:31:02 -0700 Subject: [PATCH 05/13] fix unsafe multithreaded access --- ...autoplay_permission_context_browsertest.cc | 2 +- browser/brave_browser_process_impl.cc | 38 +++-- browser/brave_browser_process_impl.h | 10 +- .../brave_component_updater_delegate.cc | 12 +- .../brave_component_updater_delegate.h | 7 + .../brave_crx_update_service.cc | 38 ----- .../brave_crx_update_service.h | 1 - .../extensions/brave_extension_provider.cc | 4 +- ...ave_ad_block_tp_network_delegate_helper.cc | 19 +-- .../chrome/browser/browser_process_impl.cc | 9 -- .../brave_component_updater/browser/BUILD.gn | 4 + .../browser/brave_component.cc | 27 ++-- .../browser/brave_component.h | 6 +- .../browser/dat_file_util.cc | 10 +- .../browser/dat_file_util.h | 22 ++- .../browser/local_data_files_observer.cc | 30 ++++ .../browser/local_data_files_observer.h | 39 +++++ .../browser/local_data_files_service.cc | 43 +++--- .../browser/local_data_files_service.h | 43 +++--- components/brave_shields/browser/BUILD.gn | 8 +- .../browser/ad_block_base_service.cc | 65 ++++++--- .../browser/ad_block_base_service.h | 15 +- .../browser/ad_block_regional_service.cc | 2 +- .../brave_shields/browser/ad_block_service.cc | 2 +- .../browser/autoplay_whitelist_service.cc | 91 +++++------- .../browser/autoplay_whitelist_service.h | 33 ++--- .../browser/base_brave_shields_service.cc | 13 +- .../browser/base_brave_shields_service.h | 3 +- .../browser/base_local_data_files_observer.cc | 13 -- .../browser/base_local_data_files_observer.h | 29 ---- ...brave_resource_dispatcher_host_delegate.cc | 45 ------ .../brave_resource_dispatcher_host_delegate.h | 31 ---- .../browser/extension_whitelist_service.cc | 84 +++++------ .../browser/extension_whitelist_service.h | 30 ++-- .../browser/https_everywhere_service.cc | 4 +- .../browser/https_everywhere_service.h | 23 ++- .../browser/referrer_whitelist_service.cc | 106 ++++++++------ .../browser/referrer_whitelist_service.h | 37 ++--- .../browser/tracking_protection_service.cc | 133 +++++++++--------- .../browser/tracking_protection_service.h | 38 ++--- 40 files changed, 573 insertions(+), 596 deletions(-) delete mode 100644 chromium_src/chrome/browser/browser_process_impl.cc create mode 100644 components/brave_component_updater/browser/local_data_files_observer.cc create mode 100644 components/brave_component_updater/browser/local_data_files_observer.h rename components/{brave_shields => brave_component_updater}/browser/local_data_files_service.cc (64%) rename components/{brave_shields => brave_component_updater}/browser/local_data_files_service.h (69%) delete mode 100644 components/brave_shields/browser/base_local_data_files_observer.cc delete mode 100644 components/brave_shields/browser/base_local_data_files_observer.h delete mode 100644 components/brave_shields/browser/brave_resource_dispatcher_host_delegate.cc delete mode 100644 components/brave_shields/browser/brave_resource_dispatcher_host_delegate.h diff --git a/browser/autoplay/autoplay_permission_context_browsertest.cc b/browser/autoplay/autoplay_permission_context_browsertest.cc index 8a51352595de..91b2bb071b67 100644 --- a/browser/autoplay/autoplay_permission_context_browsertest.cc +++ b/browser/autoplay/autoplay_permission_context_browsertest.cc @@ -10,7 +10,7 @@ #include "brave/browser/brave_content_browser_client.h" #include "brave/common/brave_paths.h" #include "brave/common/pref_names.h" -#include "brave/components/brave_shields/browser/local_data_files_service.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/components/brave_shields/browser/autoplay_whitelist_service.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/extensions/extension_browsertest.h" diff --git a/browser/brave_browser_process_impl.cc b/browser/brave_browser_process_impl.cc index e85feb7060d4..8c428cef1719 100644 --- a/browser/brave_browser_process_impl.cc +++ b/browser/brave_browser_process_impl.cc @@ -16,13 +16,13 @@ #include "brave/browser/component_updater/brave_component_updater_delegate.h" #include "brave/browser/extensions/brave_tor_client_updater.h" #include "brave/browser/profiles/brave_profile_manager.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/components/brave_shields/browser/ad_block_custom_filters_service.h" #include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h" #include "brave/components/brave_shields/browser/ad_block_service.h" #include "brave/components/brave_shields/browser/autoplay_whitelist_service.h" #include "brave/components/brave_shields/browser/extension_whitelist_service.h" #include "brave/components/brave_shields/browser/https_everywhere_service.h" -#include "brave/components/brave_shields/browser/local_data_files_service.h" #include "brave/components/brave_shields/browser/referrer_whitelist_service.h" #include "brave/components/brave_shields/browser/tracking_protection_service.h" #include "chrome/browser/io_thread.h" @@ -48,8 +48,7 @@ BraveBrowserProcessImpl* g_brave_browser_process = nullptr; using content::BrowserThread; -BraveBrowserProcessImpl::~BraveBrowserProcessImpl() { -} +BraveBrowserProcessImpl::~BraveBrowserProcessImpl() {} BraveBrowserProcessImpl::BraveBrowserProcessImpl(StartupData* startup_data) : BrowserProcessImpl(startup_data) { @@ -115,6 +114,23 @@ BraveBrowserProcessImpl::component_updater() { return component_updater_.get(); } +void BraveBrowserProcessImpl::ResourceDispatcherHostCreated() { + BrowserProcessImpl::ResourceDispatcherHostCreated(); + ad_block_service()->Start(); + ad_block_custom_filters_service()->Start(); + ad_block_regional_service_manager()->Start(); + https_everywhere_service()->Start(); + + autoplay_whitelist_service(); +#if BUILDFLAG(ENABLE_EXTENSIONS) + extension_whitelist_service(); +#endif + referrer_whitelist_service(); + tracking_protection_service(); + // Now start the local data files service, which calls all observers. + local_data_files_service()->Start(); +} + ProfileManager* BraveBrowserProcessImpl::profile_manager() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (!created_profile_manager_) @@ -154,7 +170,8 @@ brave_shields::AutoplayWhitelistService* BraveBrowserProcessImpl::autoplay_whitelist_service() { if (!autoplay_whitelist_service_) { autoplay_whitelist_service_ = - brave_shields::AutoplayWhitelistServiceFactory(); + brave_shields::AutoplayWhitelistServiceFactory( + local_data_files_service()); } return autoplay_whitelist_service_.get(); } @@ -164,7 +181,8 @@ brave_shields::ExtensionWhitelistService* BraveBrowserProcessImpl::extension_whitelist_service() { if (!extension_whitelist_service_) { extension_whitelist_service_ = - brave_shields::ExtensionWhitelistServiceFactory(); + brave_shields::ExtensionWhitelistServiceFactory( + local_data_files_service()); } return extension_whitelist_service_.get(); } @@ -174,7 +192,8 @@ brave_shields::ReferrerWhitelistService* BraveBrowserProcessImpl::referrer_whitelist_service() { if (!referrer_whitelist_service_) { referrer_whitelist_service_ = - brave_shields::ReferrerWhitelistServiceFactory(); + brave_shields::ReferrerWhitelistServiceFactory( + local_data_files_service()); } return referrer_whitelist_service_.get(); } @@ -183,7 +202,8 @@ brave_shields::TrackingProtectionService* BraveBrowserProcessImpl::tracking_protection_service() { if (!tracking_protection_service_) { tracking_protection_service_ = - brave_shields::TrackingProtectionServiceFactory(); + brave_shields::TrackingProtectionServiceFactory( + local_data_files_service()); } return tracking_protection_service_.get(); } @@ -197,11 +217,11 @@ BraveBrowserProcessImpl::https_everywhere_service() { return https_everywhere_service_.get(); } -brave_shields::LocalDataFilesService* +brave_component_updater::LocalDataFilesService* BraveBrowserProcessImpl::local_data_files_service() { if (!local_data_files_service_) local_data_files_service_ = - brave_shields::LocalDataFilesServiceFactory( + brave_component_updater::LocalDataFilesServiceFactory( brave_component_updater_delegate()); return local_data_files_service_.get(); } diff --git a/browser/brave_browser_process_impl.h b/browser/brave_browser_process_impl.h index 96e2f158a54b..08c97a2f62e2 100644 --- a/browser/brave_browser_process_impl.h +++ b/browser/brave_browser_process_impl.h @@ -24,6 +24,10 @@ class BraveStatsUpdater; class BraveWidevineBundleManager; #endif +namespace brave_component_updater { +class LocalDataFilesService; +} + namespace brave_shields { class AdBlockService; class AdBlockCustomFiltersService; @@ -31,7 +35,6 @@ class AdBlockRegionalServiceManager; class AutoplayWhitelistService; class ExtensionWhitelistService; class HTTPSEverywhereService; -class LocalDataFilesService; class ReferrerWhitelistService; class TrackingProtectionService; } // namespace brave_shields @@ -49,6 +52,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl { // BrowserProcess implementation. component_updater::ComponentUpdateService* component_updater() override; + void ResourceDispatcherHostCreated() override; ProfileManager* profile_manager() override; @@ -63,7 +67,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl { brave_shields::ReferrerWhitelistService* referrer_whitelist_service(); brave_shields::TrackingProtectionService* tracking_protection_service(); brave_shields::HTTPSEverywhereService* https_everywhere_service(); - brave_shields::LocalDataFilesService* local_data_files_service(); + brave_component_updater::LocalDataFilesService* local_data_files_service(); #if BUILDFLAG(ENABLE_TOR) extensions::BraveTorClientUpdater* tor_client_updater(); #endif @@ -92,7 +96,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl { tracking_protection_service_; std::unique_ptr https_everywhere_service_; - std::unique_ptr + std::unique_ptr local_data_files_service_; std::unique_ptr brave_stats_updater_; #if BUILDFLAG(ENABLE_BRAVE_REFERRALS) diff --git a/browser/component_updater/brave_component_updater_delegate.cc b/browser/component_updater/brave_component_updater_delegate.cc index d3826d38ca8b..0da8ccb2250a 100644 --- a/browser/component_updater/brave_component_updater_delegate.cc +++ b/browser/component_updater/brave_component_updater_delegate.cc @@ -4,6 +4,8 @@ #include "brave/browser/component_updater/brave_component_updater_delegate.h" +#include "base/sequenced_task_runner.h" +#include "base/task/post_task.h" #include "brave/browser/component_updater/brave_component_installer.h" #include "chrome/browser/ui/webui/components_ui.h" #include "chrome/browser/browser_process.h" @@ -13,7 +15,11 @@ using brave_component_updater::BraveComponent; namespace brave { -BraveComponentUpdaterDelegate::BraveComponentUpdaterDelegate() { +BraveComponentUpdaterDelegate::BraveComponentUpdaterDelegate() + : task_runner_( + base::CreateSequencedTaskRunnerWithTraits({base::MayBlock(), + base::TaskPriority::USER_VISIBLE, + base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})) { } BraveComponentUpdaterDelegate::~BraveComponentUpdaterDelegate() {} @@ -41,4 +47,8 @@ void BraveComponentUpdaterDelegate::OnDemandUpdate( ComponentsUI::OnDemandUpdate(component_id); } +scoped_refptr BraveComponentUpdaterDelegate::GetTaskRunner() { + return task_runner_; +} + } // namespace brave diff --git a/browser/component_updater/brave_component_updater_delegate.h b/browser/component_updater/brave_component_updater_delegate.h index 6b4d1293536f..8c278b08f19f 100644 --- a/browser/component_updater/brave_component_updater_delegate.h +++ b/browser/component_updater/brave_component_updater_delegate.h @@ -12,6 +12,10 @@ using brave_component_updater::BraveComponent; +namespace base { +class SequencedTaskRunner; +} + namespace brave { class BraveComponentUpdaterDelegate : public BraveComponent::Delegate { @@ -26,8 +30,11 @@ class BraveComponentUpdaterDelegate : public BraveComponent::Delegate { BraveComponent::ReadyCallback ready_callback) override; bool Unregister(const std::string& component_id) override; void OnDemandUpdate(const std::string& component_id) override; + scoped_refptr GetTaskRunner() override; private: + scoped_refptr task_runner_; + DISALLOW_COPY_AND_ASSIGN(BraveComponentUpdaterDelegate); }; diff --git a/browser/component_updater/brave_crx_update_service.cc b/browser/component_updater/brave_crx_update_service.cc index 8f9e98e17b1c..6988fe6e96fe 100644 --- a/browser/component_updater/brave_crx_update_service.cc +++ b/browser/component_updater/brave_crx_update_service.cc @@ -42,44 +42,6 @@ void BraveCrxUpdateService::Start() { base::DoNothing()); } -bool BraveCrxUpdateService::RegisterComponent(const CrxComponent& component) { - DCHECK(thread_checker_.CalledOnValidThread()); - if (component.pk_hash.empty() || !component.version.IsValid() || - !component.installer) { - return false; - } - - // Update the registration data if the component has been registered before. - const std::string id(GetCrxComponentID(component)); - auto it = components_.find(id); - if (it != components_.end()) { - it->second = component; - return true; - } - - components_.insert(std::make_pair(id, component)); - components_order_.push_back(id); - for (const auto& mime_type : component.handled_mime_types) - component_ids_by_mime_type_[mime_type] = id; - - // Create an initial state for this component. The state is mutated in - // response to events from the UpdateClient instance. - CrxUpdateItem item; - item.id = id; - item.component = component; - const auto inserted = component_states_.insert(std::make_pair(id, item)); - DCHECK(inserted.second); - - // Start the timer if this is the first component registered. The first timer - // event occurs after an interval defined by the component update - // configurator. The subsequent timer events are repeated with a period - // defined by the same configurator. - if (components_.size() == 1) - Start(); - - return true; -} - bool BraveCrxUpdateService::CheckForUpdates( UpdateScheduler::OnFinishedCallback on_finished) { DCHECK(thread_checker_.CalledOnValidThread()); diff --git a/browser/component_updater/brave_crx_update_service.h b/browser/component_updater/brave_crx_update_service.h index edfe6b63e972..41619c24dbed 100644 --- a/browser/component_updater/brave_crx_update_service.h +++ b/browser/component_updater/brave_crx_update_service.h @@ -23,7 +23,6 @@ class BraveCrxUpdateService : public CrxUpdateService { std::unique_ptr scheduler, scoped_refptr update_client); - bool RegisterComponent(const CrxComponent& component) override; ~BraveCrxUpdateService() override {} private: diff --git a/browser/extensions/brave_extension_provider.cc b/browser/extensions/brave_extension_provider.cc index f702f74217ea..2db1f5ca1031 100644 --- a/browser/extensions/brave_extension_provider.cc +++ b/browser/extensions/brave_extension_provider.cc @@ -12,8 +12,8 @@ #include "base/strings/utf_string_conversions.h" #include "brave/browser/brave_browser_process_impl.h" #include "brave/common/extensions/extension_constants.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/components/brave_shields/browser/extension_whitelist_service.h" -#include "brave/components/brave_shields/browser/local_data_files_service.h" #include "brave/grit/brave_generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -61,7 +61,7 @@ bool BraveExtensionProvider::IsVetted(const std::string id) { pdfjs_extension_id, hangouts_extension_id, widevine_extension_id, - brave_shields::kLocalDataFilesComponentId, + brave_component_updater::kLocalDataFilesComponentId, // Web Store "ahfgeienlihckogmohjhadlkjgocpleb", // Brave Automation Extension diff --git a/browser/net/brave_ad_block_tp_network_delegate_helper.cc b/browser/net/brave_ad_block_tp_network_delegate_helper.cc index d126cbece4f5..fc89a0b9d35b 100644 --- a/browser/net/brave_ad_block_tp_network_delegate_helper.cc +++ b/browser/net/brave_ad_block_tp_network_delegate_helper.cc @@ -85,8 +85,9 @@ bool GetPolyfillForAdBlock(bool allow_brave_shields, bool allow_ads, return false; } -void OnBeforeURLRequestAdBlockTPOnTaskRunner( +void OnBeforeURLRequestAdBlockTP( std::shared_ptr ctx) { + DCHECK_CURRENTLY_ON(content::BrowserThread::IO); // If the following info isn't available, then proper content settings can't // be looked up, so do nothing. if (ctx->tab_origin.is_empty() || !ctx->tab_origin.has_host() || @@ -120,12 +121,7 @@ void OnBeforeURLRequestAdBlockTPOnTaskRunner( &ctx->cancel_request_explicitly)) { ctx->blocked_by = kTrackerBlocked; } -} -void OnBeforeURLRequestDispatchOnIOThread( - const ResponseCallback& next_callback, - std::shared_ptr ctx) { - DCHECK_CURRENTLY_ON(content::BrowserThread::IO); if (ctx->blocked_by == kAdBlocked) { brave_shields::DispatchBlockedEventFromIO(ctx->request_url, ctx->render_frame_id, ctx->render_process_id, ctx->frame_tree_node_id, @@ -135,8 +131,6 @@ void OnBeforeURLRequestDispatchOnIOThread( ctx->render_frame_id, ctx->render_process_id, ctx->frame_tree_node_id, brave_shields::kTrackers); } - - next_callback.Run(); } int OnBeforeURLRequest_AdBlockTPPreWork( @@ -169,13 +163,10 @@ int OnBeforeURLRequest_AdBlockTPPreWork( return net::OK; } - g_brave_browser_process->ad_block_service()-> - GetTaskRunner()->PostTaskAndReply(FROM_HERE, - base::Bind(&OnBeforeURLRequestAdBlockTPOnTaskRunner, ctx), - base::Bind(base::IgnoreResult( - &OnBeforeURLRequestDispatchOnIOThread), next_callback, ctx)); + // TODO(bridiver) - fix this + OnBeforeURLRequestAdBlockTP(ctx); - return net::ERR_IO_PENDING; + return net::OK; } } // namespace brave diff --git a/chromium_src/chrome/browser/browser_process_impl.cc b/chromium_src/chrome/browser/browser_process_impl.cc deleted file mode 100644 index bae639d802fd..000000000000 --- a/chromium_src/chrome/browser/browser_process_impl.cc +++ /dev/null @@ -1,9 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/components/brave_shields/browser/brave_resource_dispatcher_host_delegate.h" - -#define ChromeResourceDispatcherHostDelegate BraveResourceDispatcherHostDelegate -#include "../../../../chrome/browser/browser_process_impl.cc" -#undef ChromeResourceDispatcherHostDelegate diff --git a/components/brave_component_updater/browser/BUILD.gn b/components/brave_component_updater/browser/BUILD.gn index f782a061a2d0..74bc19821188 100644 --- a/components/brave_component_updater/browser/BUILD.gn +++ b/components/brave_component_updater/browser/BUILD.gn @@ -4,6 +4,10 @@ source_set("browser") { "brave_component.h", "dat_file_util.cc", "dat_file_util.h", + "local_data_files_service.cc", + "local_data_files_service.h", + "local_data_files_observer.cc", + "local_data_files_observer.h", ] deps = [ diff --git a/components/brave_component_updater/browser/brave_component.cc b/components/brave_component_updater/browser/brave_component.cc index fa79bb0c5938..75c30402cfbf 100644 --- a/components/brave_component_updater/browser/brave_component.cc +++ b/components/brave_component_updater/browser/brave_component.cc @@ -6,11 +6,13 @@ #include "brave/components/brave_component_updater/browser/brave_component.h" #include "base/bind.h" -#include "base/bind_helpers.h" +#include "base/sequenced_task_runner.h" namespace brave_component_updater { -BraveComponent::BraveComponent(Delegate* delegate) : delegate_(delegate) {} +BraveComponent::BraveComponent(Delegate* delegate) + : delegate_(delegate), + weak_factory_(this) {} BraveComponent::~BraveComponent() { } @@ -18,13 +20,17 @@ BraveComponent::~BraveComponent() { void BraveComponent::Register(const std::string& component_name, const std::string& component_id, const std::string& component_base64_public_key) { + component_name_ = component_name; + component_id_ = component_id; + component_base64_public_key_ = component_base64_public_key; + auto registered_callback = base::BindOnce(&BraveComponent::OnComponentRegistered, delegate_, component_id); auto ready_callback = base::BindOnce(&BraveComponent::OnComponentReady, - AsWeakPtr(), + weak_factory_.GetWeakPtr(), component_id); delegate_->Register(component_name_, @@ -37,17 +43,20 @@ bool BraveComponent::Unregister() { return delegate_->Unregister(component_id_); } -// static -void BraveComponent::OnComponentRegistered( - Delegate* delegate, - const std::string& component_id) { - delegate->OnDemandUpdate(component_id); +scoped_refptr BraveComponent::GetTaskRunner() { + return delegate_->GetTaskRunner(); } void BraveComponent::OnComponentReady( const std::string& component_id, const base::FilePath& install_dir, - const std::string& manifest) { + const std::string& manifest) {} + +// static +void BraveComponent::OnComponentRegistered( + Delegate* delegate, + const std::string& component_id) { + delegate->OnDemandUpdate(component_id); } } // namespace brave_component_updater diff --git a/components/brave_component_updater/browser/brave_component.h b/components/brave_component_updater/browser/brave_component.h index 998189bc69d2..a2a287577a54 100644 --- a/components/brave_component_updater/browser/brave_component.h +++ b/components/brave_component_updater/browser/brave_component.h @@ -12,10 +12,11 @@ #include "base/files/file_path.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" +#include "base/sequenced_task_runner.h" namespace brave_component_updater { -class BraveComponent : public base::SupportsWeakPtr { +class BraveComponent { public: using ReadyCallback = base::OnceCallback; @@ -28,6 +29,7 @@ class BraveComponent : public base::SupportsWeakPtr { ReadyCallback ready_callback) = 0; virtual bool Unregister(const std::string& component_id) = 0; virtual void OnDemandUpdate(const std::string& component_id) = 0; + virtual scoped_refptr GetTaskRunner() = 0; }; BraveComponent(Delegate* delegate); @@ -36,6 +38,7 @@ class BraveComponent : public base::SupportsWeakPtr { const std::string& component_id, const std::string& component_base64_public_key); bool Unregister(); + scoped_refptr GetTaskRunner(); protected: virtual void OnComponentReady(const std::string& component_id, @@ -50,6 +53,7 @@ class BraveComponent : public base::SupportsWeakPtr { std::string component_id_; std::string component_base64_public_key_; Delegate* delegate_; // NOT OWNED + base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(BraveComponent); }; diff --git a/components/brave_component_updater/browser/dat_file_util.cc b/components/brave_component_updater/browser/dat_file_util.cc index 42f61f9e14c8..ea142ea3212b 100644 --- a/components/brave_component_updater/browser/dat_file_util.cc +++ b/components/brave_component_updater/browser/dat_file_util.cc @@ -7,6 +7,7 @@ #include +#include "base/logging.h" #include "base/files/file_path.h" #include "base/files/file_util.h" @@ -33,13 +34,14 @@ void GetDATFileData(const base::FilePath& file_path, } } -void GetDATFileAsString(const base::FilePath& file_path, - std::string* contents) { - bool success = base::ReadFileToString(file_path, contents); - if (!success || contents->empty()) { +std::string GetDATFileAsString(const base::FilePath& file_path) { + std::string contents; + bool success = base::ReadFileToString(file_path, &contents); + if (!success || contents.empty()) { LOG(ERROR) << "GetDATFileAsString: cannot " << "read dat file " << file_path; } + return contents; } } // namespace brave_component_updater diff --git a/components/brave_component_updater/browser/dat_file_util.h b/components/brave_component_updater/browser/dat_file_util.h index d660232c03cd..6d0d03596001 100644 --- a/components/brave_component_updater/browser/dat_file_util.h +++ b/components/brave_component_updater/browser/dat_file_util.h @@ -9,9 +9,7 @@ #include #include -namespace base { -class FilePath; -} +#include "base/files/file_path.h" namespace brave_component_updater { @@ -19,8 +17,22 @@ using DATFileDataBuffer = std::vector; void GetDATFileData(const base::FilePath& file_path, DATFileDataBuffer* buffer); -void GetDATFileAsString(const base::FilePath& file_path, - std::string* contents); +std::string GetDATFileAsString(const base::FilePath& file_path); + +template +std::pair, DATFileDataBuffer> LoadDATFileData( + const base::FilePath& dat_file_path) { + DATFileDataBuffer buffer; + GetDATFileData(dat_file_path, &buffer); + std::unique_ptr client; + client = std::make_unique(); + if (buffer.empty() || + !client->deserialize(reinterpret_cast(&buffer.front()))) + client.reset(); + + return std::pair, DATFileDataBuffer>( + std::move(client), std::move(buffer)); +} } // namespace brave_component_updater diff --git a/components/brave_component_updater/browser/local_data_files_observer.cc b/components/brave_component_updater/browser/local_data_files_observer.cc new file mode 100644 index 000000000000..9a2ba44b3728 --- /dev/null +++ b/components/brave_component_updater/browser/local_data_files_observer.cc @@ -0,0 +1,30 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/brave_component_updater/browser/local_data_files_observer.h" + +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" + +namespace brave_component_updater { + +LocalDataFilesObserver::LocalDataFilesObserver( + LocalDataFilesService* local_data_files_service) + : local_data_files_service_(local_data_files_service), + local_data_files_observer_(this) { + local_data_files_observer_.Add(local_data_files_service); +} + +LocalDataFilesObserver::~LocalDataFilesObserver() {} + +void LocalDataFilesObserver::OnLocalDataFilesServiceDestroyed() { + local_data_files_observer_.RemoveAll(); + local_data_files_service_ = nullptr; +} + +LocalDataFilesService* LocalDataFilesObserver::local_data_files_service() { + return local_data_files_service_; +} + +} // namespace brave_component_updater + diff --git a/components/brave_component_updater/browser/local_data_files_observer.h b/components/brave_component_updater/browser/local_data_files_observer.h new file mode 100644 index 000000000000..c4ee1bf179d1 --- /dev/null +++ b/components/brave_component_updater/browser/local_data_files_observer.h @@ -0,0 +1,39 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_LOCAL_DATA_FILES_OBSERVER_H_ +#define BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_LOCAL_DATA_FILES_OBSERVER_H_ + +#include + +#include "base/files/file_path.h" +#include "base/scoped_observer.h" + +namespace brave_component_updater { + +class LocalDataFilesService; + +// The abstract base class for observers of the local data files service, +// which is the component that arbitrates access to various DAT files +// like tracking protection, video autoplay whitelist, etc. +class LocalDataFilesObserver { + public: + explicit LocalDataFilesObserver( + LocalDataFilesService* local_data_files_service); + virtual ~LocalDataFilesObserver(); + virtual void OnComponentReady(const std::string& component_id, + const base::FilePath& install_dir, + const std::string& manifest) = 0; + virtual void OnLocalDataFilesServiceDestroyed(); + LocalDataFilesService* local_data_files_service(); + + protected: + LocalDataFilesService* local_data_files_service_; // NOT OWNED + ScopedObserver + local_data_files_observer_; +}; + +} // namespace brave_component_updater + +#endif // BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_LOCAL_DATA_FILES_OBSERVER_H_ diff --git a/components/brave_shields/browser/local_data_files_service.cc b/components/brave_component_updater/browser/local_data_files_service.cc similarity index 64% rename from components/brave_shields/browser/local_data_files_service.cc rename to components/brave_component_updater/browser/local_data_files_service.cc index 5dcea95550c5..2e152f29cb22 100644 --- a/components/brave_shields/browser/local_data_files_service.cc +++ b/components/brave_component_updater/browser/local_data_files_service.cc @@ -2,16 +2,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "brave/components/brave_shields/browser/local_data_files_service.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" -#include - -#include "base/base_paths.h" -#include "brave/components/brave_shields/browser/base_local_data_files_observer.h" +// #include "base/base_paths.h" +#include "brave/components/brave_component_updater/browser/local_data_files_observer.h" using brave_component_updater::BraveComponent; -namespace brave_shields { +namespace brave_component_updater { std::string LocalDataFilesService::g_local_data_files_component_id_( kLocalDataFilesComponentId); @@ -20,13 +18,12 @@ std::string LocalDataFilesService::g_local_data_files_component_base64_public_ke LocalDataFilesService::LocalDataFilesService(BraveComponent::Delegate* delegate) : BraveComponent(delegate), - initialized_(false), - observers_already_called_(false), - weak_factory_(this) { - DETACH_FROM_SEQUENCE(sequence_checker_); -} + initialized_(false) {} -LocalDataFilesService::~LocalDataFilesService() { } +LocalDataFilesService::~LocalDataFilesService() { + for (auto& observer : observers_) + observer.OnLocalDataFilesServiceDestroyed(); +} bool LocalDataFilesService::Start() { if (initialized_) @@ -38,18 +35,20 @@ bool LocalDataFilesService::Start() { return true; } -void LocalDataFilesService::AddObserver(BaseLocalDataFilesObserver* observer) { - DCHECK(!observers_already_called_); - observers_.push_back(observer); -} - void LocalDataFilesService::OnComponentReady( const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) { - observers_already_called_ = true; - for (BaseLocalDataFilesObserver* observer : observers_) - observer->OnComponentReady(component_id, install_dir, manifest); + for (auto& observer : observers_) + observer.OnComponentReady(component_id, install_dir, manifest); +} + +void LocalDataFilesService::AddObserver(LocalDataFilesObserver* observer) { + observers_.AddObserver(observer); +} + +void LocalDataFilesService::RemoveObserver(LocalDataFilesObserver* observer) { + observers_.RemoveObserver(observer); } // static @@ -62,11 +61,9 @@ void LocalDataFilesService::SetComponentIdAndBase64PublicKeyForTest( /////////////////////////////////////////////////////////////////////////////// -// The brave shields factory. Using the Brave Shields as a singleton -// is the job of the browser process. std::unique_ptr LocalDataFilesServiceFactory(BraveComponent::Delegate* delegate) { return std::make_unique(delegate); } -} // namespace brave_shields +} // namespace brave_component_updater diff --git a/components/brave_shields/browser/local_data_files_service.h b/components/brave_component_updater/browser/local_data_files_service.h similarity index 69% rename from components/brave_shields/browser/local_data_files_service.h rename to components/brave_component_updater/browser/local_data_files_service.h index e9ba4b01843e..38e37260083f 100644 --- a/components/brave_shields/browser/local_data_files_service.h +++ b/components/brave_component_updater/browser/local_data_files_service.h @@ -3,31 +3,26 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_LOCAL_DATA_FILES_SERVICE_H_ -#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_LOCAL_DATA_FILES_SERVICE_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_LOCAL_DATA_FILES_SERVICE_H_ +#define BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_LOCAL_DATA_FILES_SERVICE_H_ -#include - -#include #include #include -#include #include "base/files/file_path.h" -#include "base/memory/weak_ptr.h" -#include "base/sequence_checker.h" +#include "base/observer_list.h" #include "brave/components/brave_component_updater/browser/brave_component.h" +namespace brave_shields { class AdBlockServiceTest; class AutoplayWhitelistServiceTest; class ReferrerWhitelistServiceTest; class TrackingProtectionServiceTest; +} -using brave_component_updater::BraveComponent; - -namespace brave_shields { +namespace brave_component_updater { -class BaseLocalDataFilesObserver; +class LocalDataFilesObserver; const char kLocalDataFilesComponentName[] = "Brave Local Data Updater"; const char kLocalDataFilesComponentId[] = "afalakplffnnnlkncjhbmahjfjhmlkal"; @@ -44,11 +39,12 @@ const char kLocalDataFilesComponentBase64PublicKey[] = // such as tracking protection and video autoplay whitelist class LocalDataFilesService : public BraveComponent { public: - LocalDataFilesService(BraveComponent::Delegate* delegate); + explicit LocalDataFilesService(BraveComponent::Delegate* delegate); ~LocalDataFilesService() override; bool Start(); bool IsInitialized() const { return initialized_; } - void AddObserver(BaseLocalDataFilesObserver* observer); + void AddObserver(LocalDataFilesObserver* observer); + void RemoveObserver(LocalDataFilesObserver* observer); protected: void OnComponentReady(const std::string& component_id, @@ -56,22 +52,19 @@ class LocalDataFilesService : public BraveComponent { const std::string& manifest) override; private: - friend class ::AdBlockServiceTest; - friend class ::AutoplayWhitelistServiceTest; - friend class ::ReferrerWhitelistServiceTest; - friend class ::TrackingProtectionServiceTest; + friend class brave_shields::AdBlockServiceTest; + friend class brave_shields::AutoplayWhitelistServiceTest; + friend class brave_shields::ReferrerWhitelistServiceTest; + friend class brave_shields::TrackingProtectionServiceTest; static std::string g_local_data_files_component_id_; static std::string g_local_data_files_component_base64_public_key_; static void SetComponentIdAndBase64PublicKeyForTest( const std::string& component_id, const std::string& component_base64_public_key); - std::vector observers_; - - SEQUENCE_CHECKER(sequence_checker_); bool initialized_; - bool observers_already_called_; - base::WeakPtrFactory weak_factory_; + base::ObserverList::Unchecked observers_; + DISALLOW_COPY_AND_ASSIGN(LocalDataFilesService); }; @@ -79,6 +72,6 @@ class LocalDataFilesService : public BraveComponent { std::unique_ptr LocalDataFilesServiceFactory(BraveComponent::Delegate* delegate); -} // namespace brave_shields +} // namespace brave_component_updater -#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_LOCAL_DATA_FILES_SERVICE_H_ +#endif // BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_LOCAL_DATA_FILES_SERVICE_H_ diff --git a/components/brave_shields/browser/BUILD.gn b/components/brave_shields/browser/BUILD.gn index 2a4dc53a445a..6bea35fda1bc 100644 --- a/components/brave_shields/browser/BUILD.gn +++ b/components/brave_shields/browser/BUILD.gn @@ -25,19 +25,13 @@ source_set("brave_shields") { "autoplay_whitelist_service.h", "base_brave_shields_service.cc", "base_brave_shields_service.h", - "base_local_data_files_observer.cc", - "base_local_data_files_observer.h", "brave_shields_util.cc", "brave_shields_util.h", "brave_shields_web_contents_observer.cc", "brave_shields_web_contents_observer.h", - "brave_resource_dispatcher_host_delegate.cc", - "brave_resource_dispatcher_host_delegate.h", "https_everywhere_recently_used_cache.h", "https_everywhere_service.cc", "https_everywhere_service.h", - "local_data_files_service.cc", - "local_data_files_service.h", "referrer_whitelist_service.cc", "referrer_whitelist_service.h", "tracking_protection_service.cc", @@ -59,6 +53,8 @@ source_set("brave_shields") { "//brave/vendor/autoplay-whitelist/brave:autoplay-whitelist", "//chrome/common", "//components/prefs", + "//content/public/browser", + "//net", "//third_party/leveldatabase", ] diff --git a/components/brave_shields/browser/ad_block_base_service.cc b/components/brave_shields/browser/ad_block_base_service.cc index fb24024fccb7..a331a6345cb3 100644 --- a/components/brave_shields/browser/ad_block_base_service.cc +++ b/components/brave_shields/browser/ad_block_base_service.cc @@ -12,21 +12,23 @@ #include "base/bind.h" #include "base/files/file_path.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/strings/utf_string_conversions.h" -#include "base/threading/thread_restrictions.h" +#include "base/task/post_task.h" #include "brave/browser/net/url_context.h" #include "brave/common/pref_names.h" #include "brave/components/brave_component_updater/browser/dat_file_util.h" #include "brave/components/brave_shields/common/brave_shield_constants.h" #include "brave/vendor/ad-block/ad_block_client.h" #include "components/prefs/pref_service.h" +#include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "url/origin.h" using brave_component_updater::BraveComponent; +using content::BrowserThread; using namespace net::registry_controlled_domains; // NOLINT namespace { @@ -108,7 +110,8 @@ namespace brave_shields { AdBlockBaseService::AdBlockBaseService(BraveComponent::Delegate* delegate) : BaseBraveShieldsService(delegate), ad_block_client_(new AdBlockClient()), - weak_factory_(this) { + weak_factory_(this), + weak_factory_io_thread_(this) { DETACH_FROM_SEQUENCE(sequence_checker_); } @@ -117,13 +120,14 @@ AdBlockBaseService::~AdBlockBaseService() { } void AdBlockBaseService::Cleanup() { - ad_block_client_.reset(); + BrowserThread::DeleteSoon( + BrowserThread::IO, FROM_HERE, ad_block_client_.release()); } bool AdBlockBaseService::ShouldStartRequest(const GURL& url, content::ResourceType resource_type, const std::string& tab_host, bool* did_match_exception, bool* cancel_request_explicitly) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK_CURRENTLY_ON(BrowserThread::IO); FilterOption current_option = ResourceTypeToFilterOption(resource_type); // Determine third-party here so the library doesn't need to figure it out. @@ -163,15 +167,17 @@ bool AdBlockBaseService::ShouldStartRequest(const GURL& url, } void AdBlockBaseService::EnableTag(const std::string& tag, bool enabled) { - GetTaskRunner()->PostTask( - FROM_HERE, - base::BindOnce(&AdBlockBaseService::EnableTagOnFileTaskRunner, - base::Unretained(this), tag, enabled)); + base::PostTaskWithTraits( + FROM_HERE, {BrowserThread::IO}, + base::BindOnce(&AdBlockBaseService::EnableTagOnIOThread, + weak_factory_io_thread_.GetWeakPtr(), + tag, + enabled)); } -void AdBlockBaseService::EnableTagOnFileTaskRunner( - std::string tag, bool enabled) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +void AdBlockBaseService::EnableTagOnIOThread( + const std::string& tag, bool enabled) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); if (enabled) { ad_block_client_->addTag(tag); } else { @@ -180,26 +186,43 @@ void AdBlockBaseService::EnableTagOnFileTaskRunner( } void AdBlockBaseService::GetDATFileData(const base::FilePath& dat_file_path) { - GetTaskRunner()->PostTaskAndReply( + base::PostTaskAndReplyWithResult( + GetTaskRunner().get(), FROM_HERE, - base::Bind(&brave_component_updater::GetDATFileData, dat_file_path, &buffer_), - base::Bind(&AdBlockBaseService::OnDATFileDataReady, - weak_factory_.GetWeakPtr())); + base::BindOnce( + &brave_component_updater::LoadDATFileData, + dat_file_path), + base::BindOnce(&AdBlockBaseService::OnGetDATFileData, + weak_factory_.GetWeakPtr())); } -void AdBlockBaseService::OnDATFileDataReady() { - if (buffer_.empty()) { +void AdBlockBaseService::OnGetDATFileData(GetDATFileDataResult result) { + if (result.second.empty()) { LOG(ERROR) << "Could not obtain ad block data"; return; } - if (!ad_block_client_->deserialize( - reinterpret_cast(&buffer_.front()))) { - ad_block_client_.reset(new AdBlockClient()); + if (!result.first.get()) { LOG(ERROR) << "Failed to deserialize ad block data"; return; } + + base::PostTaskWithTraits( + FROM_HERE, {BrowserThread::IO}, + base::BindOnce(&AdBlockBaseService::UpdateAdBlockClient, + weak_factory_io_thread_.GetWeakPtr(), + std::move(result.first), + std::move(result.second))); } +void AdBlockBaseService::UpdateAdBlockClient( + std::unique_ptr ad_block_client, + brave_component_updater::DATFileDataBuffer buffer) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + ad_block_client_ = std::move(ad_block_client); + buffer_ = std::move(buffer); +} + + bool AdBlockBaseService::Init() { return true; } diff --git a/components/brave_shields/browser/ad_block_base_service.h b/components/brave_shields/browser/ad_block_base_service.h index c147a3f1ce33..df3ce36982d3 100644 --- a/components/brave_shields/browser/ad_block_base_service.h +++ b/components/brave_shields/browser/ad_block_base_service.h @@ -30,6 +30,10 @@ namespace brave_shields { // checking and init. class AdBlockBaseService : public BaseBraveShieldsService { public: + using GetDATFileDataResult = + std::pair, + brave_component_updater::DATFileDataBuffer>; + AdBlockBaseService(BraveComponent::Delegate* delegate); ~AdBlockBaseService() override; @@ -43,19 +47,24 @@ class AdBlockBaseService : public BaseBraveShieldsService { bool Init() override; void Cleanup() override; - void EnableTagOnFileTaskRunner(std::string tag, bool enabled); void GetDATFileData(const base::FilePath& dat_file_path); + AdBlockClient* GetAdBlockClientForTest(); SEQUENCE_CHECKER(sequence_checker_); std::unique_ptr ad_block_client_; - brave_component_updater::DATFileDataBuffer buffer_; private: - void OnDATFileDataReady(); + void UpdateAdBlockClient( + std::unique_ptr ad_block_client, + brave_component_updater::DATFileDataBuffer buffer); + void OnGetDATFileData(GetDATFileDataResult result); + void EnableTagOnIOThread(const std::string& tag, bool enabled); void OnPreferenceChanges(const std::string& pref_name); + brave_component_updater::DATFileDataBuffer buffer_; base::WeakPtrFactory weak_factory_; + base::WeakPtrFactory weak_factory_io_thread_; DISALLOW_COPY_AND_ASSIGN(AdBlockBaseService); }; diff --git a/components/brave_shields/browser/ad_block_regional_service.cc b/components/brave_shields/browser/ad_block_regional_service.cc index 1cacf96ea888..2efb696d7719 100644 --- a/components/brave_shields/browser/ad_block_regional_service.cc +++ b/components/brave_shields/browser/ad_block_regional_service.cc @@ -71,7 +71,7 @@ void AdBlockRegionalService::OnComponentReady( install_dir.AppendASCII(g_ad_block_regional_dat_file_version_) .AppendASCII(uuid_) .AddExtension(FILE_PATH_LITERAL(".dat")); - AdBlockBaseService::GetDATFileData(dat_file_path); + GetDATFileData(dat_file_path); } // static diff --git a/components/brave_shields/browser/ad_block_service.cc b/components/brave_shields/browser/ad_block_service.cc index 6161c31a84ab..6ab950061e34 100644 --- a/components/brave_shields/browser/ad_block_service.cc +++ b/components/brave_shields/browser/ad_block_service.cc @@ -57,7 +57,7 @@ void AdBlockService::OnComponentReady(const std::string& component_id, base::FilePath dat_file_path = install_dir.AppendASCII(g_ad_block_dat_file_version_) .AppendASCII(DAT_FILE); - AdBlockBaseService::GetDATFileData(dat_file_path); + GetDATFileData(dat_file_path); } // static diff --git a/components/brave_shields/browser/autoplay_whitelist_service.cc b/components/brave_shields/browser/autoplay_whitelist_service.cc index 9d37c6390430..8f90c3c0400b 100644 --- a/components/brave_shields/browser/autoplay_whitelist_service.cc +++ b/components/brave_shields/browser/autoplay_whitelist_service.cc @@ -5,32 +5,27 @@ #include "brave/components/brave_shields/browser/autoplay_whitelist_service.h" -#include -#include - -#include "base/base_paths.h" #include "base/bind.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/memory/ptr_util.h" -#include "base/strings/utf_string_conversions.h" -#include "base/threading/thread_restrictions.h" -#include "brave/browser/brave_browser_process_impl.h" -#include "brave/components/brave_shields/browser/ad_block_service.h" -#include "brave/components/brave_shields/browser/local_data_files_service.h" -#include "brave/components/brave_component_updater/browser/dat_file_util.h" +#include "base/task/post_task.h" +#include "base/task_runner_util.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/vendor/autoplay-whitelist/autoplay_whitelist_parser.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" +using brave_component_updater::LocalDataFilesObserver; +using brave_component_updater::LocalDataFilesService; + namespace brave_shields { -AutoplayWhitelistService::AutoplayWhitelistService() - : autoplay_whitelist_client_(new AutoplayWhitelistParser()), +AutoplayWhitelistService::AutoplayWhitelistService( + LocalDataFilesService* local_data_files_service) + : LocalDataFilesObserver(local_data_files_service), + autoplay_whitelist_client_(new AutoplayWhitelistParser()), weak_factory_(this) { - DETACH_FROM_SEQUENCE(sequence_checker_); } AutoplayWhitelistService::~AutoplayWhitelistService() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); autoplay_whitelist_client_.reset(); } @@ -43,53 +38,45 @@ bool AutoplayWhitelistService::ShouldAllowAutoplay(const GURL& url) { return autoplay_whitelist_client_->matchesHost(etld_plus_one.c_str()); } -void AutoplayWhitelistService::OnDATFileDataReady() { - if (buffer_.empty()) { - LOG(ERROR) << "Could not obtain autoplay whitelist data"; - return; - } - autoplay_whitelist_client_.reset(new AutoplayWhitelistParser()); - if (!autoplay_whitelist_client_->deserialize( - reinterpret_cast(&buffer_.front()))) { - autoplay_whitelist_client_.reset(); - LOG(ERROR) << "Failed to deserialize autoplay whitelist data"; - return; - } -} - void AutoplayWhitelistService::OnComponentReady( const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + base::FilePath dat_file_path = install_dir + .AppendASCII(AUTOPLAY_DAT_FILE_VERSION) + .AppendASCII(AUTOPLAY_DAT_FILE); - base::FilePath dat_file_path = install_dir.AppendASCII( - AUTOPLAY_DAT_FILE_VERSION).AppendASCII(AUTOPLAY_DAT_FILE); - - GetTaskRunner()->PostTaskAndReply( + base::PostTaskAndReplyWithResult( + local_data_files_service()->GetTaskRunner().get(), FROM_HERE, - base::Bind(&brave_component_updater::GetDATFileData, - dat_file_path, - &buffer_), - base::Bind(&AutoplayWhitelistService::OnDATFileDataReady, - weak_factory_.GetWeakPtr())); + base::BindOnce( + &brave_component_updater::LoadDATFileData, + dat_file_path), + base::BindOnce(&AutoplayWhitelistService::OnGetDATFileData, + weak_factory_.GetWeakPtr())); } -scoped_refptr - AutoplayWhitelistService::GetTaskRunner() { - // We share the same task runner as ad-block code - return g_brave_browser_process->ad_block_service()->GetTaskRunner(); +void AutoplayWhitelistService::OnGetDATFileData(GetDATFileDataResult result) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + if (result.second.empty()) { + LOG(ERROR) << "Could not obtain autoplay whitelist data"; + return; + } + if (!result.first.get()) { + LOG(ERROR) << "Failed to deserialize autoplay whitelist data"; + return; + } + + autoplay_whitelist_client_ = std::move(result.first); + buffer_ = std::move(result.second); } /////////////////////////////////////////////////////////////////////////////// - -// The autoplay whitelist factory. Using the Brave Shields as a singleton -// is the job of the browser process. -std::unique_ptr AutoplayWhitelistServiceFactory() { - std::unique_ptr service = - std::make_unique(); - g_brave_browser_process->local_data_files_service()->AddObserver( - service.get()); - return service; +// The autoplay whitelist factory +std::unique_ptr AutoplayWhitelistServiceFactory( + LocalDataFilesService* local_data_files_service) { + return std::make_unique(local_data_files_service); } } // namespace brave_shields diff --git a/components/brave_shields/browser/autoplay_whitelist_service.h b/components/brave_shields/browser/autoplay_whitelist_service.h index f254e69ebd73..c3fe8dc1df85 100644 --- a/components/brave_shields/browser/autoplay_whitelist_service.h +++ b/components/brave_shields/browser/autoplay_whitelist_service.h @@ -6,37 +6,38 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_AUTOPLAY_WHITELIST_SERVICE_H_ #define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_AUTOPLAY_WHITELIST_SERVICE_H_ -#include - -#include #include #include -#include #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" -#include "base/sequenced_task_runner.h" -#include "brave/components/brave_shields/browser/base_local_data_files_observer.h" #include "brave/components/brave_component_updater/browser/dat_file_util.h" -#include "content/public/common/resource_type.h" +#include "brave/components/brave_component_updater/browser/local_data_files_observer.h" #include "url/gurl.h" class AutoplayWhitelistParser; class BraveContentSettingsObserverAutoplayTest; +using brave_component_updater::LocalDataFilesObserver; +using brave_component_updater::LocalDataFilesService; + namespace brave_shields { // The brave shields service in charge of autoplay whitelist -class AutoplayWhitelistService : public BaseLocalDataFilesObserver { +class AutoplayWhitelistService : public LocalDataFilesObserver { public: - AutoplayWhitelistService(); + using GetDATFileDataResult = + std::pair, + brave_component_updater::DATFileDataBuffer>; + + explicit AutoplayWhitelistService( + LocalDataFilesService* local_data_files_service); ~AutoplayWhitelistService() override; bool ShouldAllowAutoplay(const GURL& url); - scoped_refptr GetTaskRunner(); - // implementation of BaseLocalDataFilesObserver + // implementation of LocalDataFilesObserver void OnComponentReady(const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) override; @@ -44,19 +45,19 @@ class AutoplayWhitelistService : public BaseLocalDataFilesObserver { private: friend class ::BraveContentSettingsObserverAutoplayTest; - void OnDATFileDataReady(); - - brave_component_updater::DATFileDataBuffer buffer_; + void OnGetDATFileData(GetDATFileDataResult result); std::unique_ptr autoplay_whitelist_client_; - + brave_component_updater::DATFileDataBuffer buffer_; SEQUENCE_CHECKER(sequence_checker_); + base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(AutoplayWhitelistService); }; // Creates the AutoplayWhitelistService -std::unique_ptr AutoplayWhitelistServiceFactory(); +std::unique_ptr AutoplayWhitelistServiceFactory( + LocalDataFilesService* local_data_files_service); } // namespace brave_shields diff --git a/components/brave_shields/browser/base_brave_shields_service.cc b/components/brave_shields/browser/base_brave_shields_service.cc index c4e1fe409228..813a6b8f6263 100644 --- a/components/brave_shields/browser/base_brave_shields_service.cc +++ b/components/brave_shields/browser/base_brave_shields_service.cc @@ -15,8 +15,6 @@ #include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" -#include "base/task_runner_util.h" -#include "base/task/post_task.h" using brave_component_updater::BraveComponent; @@ -25,11 +23,7 @@ namespace brave_shields { BaseBraveShieldsService::BaseBraveShieldsService( BraveComponent::Delegate* delegate) : BraveComponent(delegate), - initialized_(false), - task_runner_( - base::CreateSequencedTaskRunnerWithTraits({base::MayBlock(), - base::TaskPriority::USER_VISIBLE, - base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})) { + initialized_(false) { } BaseBraveShieldsService::~BaseBraveShieldsService() { @@ -73,9 +67,4 @@ bool BaseBraveShieldsService::ShouldStartRequest(const GURL& url, return true; } -scoped_refptr -BaseBraveShieldsService::GetTaskRunner() { - return task_runner_; -} - } // namespace brave_shields diff --git a/components/brave_shields/browser/base_brave_shields_service.h b/components/brave_shields/browser/base_brave_shields_service.h index 92c9288f3f33..92d98e443ec9 100644 --- a/components/brave_shields/browser/base_brave_shields_service.h +++ b/components/brave_shields/browser/base_brave_shields_service.h @@ -25,7 +25,7 @@ namespace brave_shields { // The brave shields service in charge of checking brave shields like ad-block, // tracking protection, etc. -class BaseBraveShieldsService : public brave_component_updater::BraveComponent { +class BaseBraveShieldsService : public BraveComponent { public: BaseBraveShieldsService(BraveComponent::Delegate* delegate); ~BaseBraveShieldsService() override; @@ -37,7 +37,6 @@ class BaseBraveShieldsService : public brave_component_updater::BraveComponent { const std::string& tab_host, bool* did_match_exception, bool* cancel_request_explicitly); - virtual scoped_refptr GetTaskRunner(); protected: virtual bool Init() = 0; diff --git a/components/brave_shields/browser/base_local_data_files_observer.cc b/components/brave_shields/browser/base_local_data_files_observer.cc deleted file mode 100644 index b9a105d4a587..000000000000 --- a/components/brave_shields/browser/base_local_data_files_observer.cc +++ /dev/null @@ -1,13 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/components/brave_shields/browser/base_local_data_files_observer.h" - -namespace brave_shields { - -BaseLocalDataFilesObserver::BaseLocalDataFilesObserver() { } - -BaseLocalDataFilesObserver::~BaseLocalDataFilesObserver() { } - -} // namespace brave_shields diff --git a/components/brave_shields/browser/base_local_data_files_observer.h b/components/brave_shields/browser/base_local_data_files_observer.h deleted file mode 100644 index 9a60b0f95fa2..000000000000 --- a/components/brave_shields/browser/base_local_data_files_observer.h +++ /dev/null @@ -1,29 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_BASE_LOCAL_DATA_FILES_OBSERVER_H_ -#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_BASE_LOCAL_DATA_FILES_OBSERVER_H_ - -#include - -#include "base/files/file_path.h" - -namespace brave_shields { - -// The abstract base class for observers of the local data files service, -// which is the component that arbitrates access to various DAT files -// like tracking protection, video autoplay whitelist, etc. -class BaseLocalDataFilesObserver { - public: - BaseLocalDataFilesObserver(); - virtual ~BaseLocalDataFilesObserver(); - - virtual void OnComponentReady(const std::string& component_id, - const base::FilePath& install_dir, - const std::string& manifest) = 0; -}; - -} // namespace brave_shields - -#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_BASE_LOCAL_DATA_FILES_OBSERVER_H_ diff --git a/components/brave_shields/browser/brave_resource_dispatcher_host_delegate.cc b/components/brave_shields/browser/brave_resource_dispatcher_host_delegate.cc deleted file mode 100644 index c7e0e5ef0ce1..000000000000 --- a/components/brave_shields/browser/brave_resource_dispatcher_host_delegate.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/components/brave_shields/browser/brave_resource_dispatcher_host_delegate.h" - -#include "brave/browser/brave_browser_process_impl.h" -#include "brave/components/brave_shields/browser/ad_block_custom_filters_service.h" -#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h" -#include "brave/components/brave_shields/browser/ad_block_service.h" -#include "brave/components/brave_shields/browser/https_everywhere_service.h" -#include "brave/components/brave_shields/browser/local_data_files_service.h" -#include "extensions/buildflags/buildflags.h" - -using content::ResourceType; - -BraveResourceDispatcherHostDelegate::BraveResourceDispatcherHostDelegate() { - g_brave_browser_process->ad_block_service()->Start(); - g_brave_browser_process->ad_block_custom_filters_service()->Start(); - g_brave_browser_process->ad_block_regional_service_manager()->Start(); - g_brave_browser_process->https_everywhere_service()->Start(); - // Ensure that all services that observe the local data files service - // are created before calling Start(). - g_brave_browser_process->autoplay_whitelist_service(); -#if BUILDFLAG(ENABLE_EXTENSIONS) - g_brave_browser_process->extension_whitelist_service(); -#endif - g_brave_browser_process->referrer_whitelist_service(); - g_brave_browser_process->tracking_protection_service(); - // Now start the local data files service, which calls all observers. - g_brave_browser_process->local_data_files_service()->Start(); -} - -BraveResourceDispatcherHostDelegate::~BraveResourceDispatcherHostDelegate() { -} - -void BraveResourceDispatcherHostDelegate::AppendStandardResourceThrottles( - net::URLRequest* request, - content::ResourceContext* resource_context, - ResourceType resource_type, - std::vector>* throttles) { - ChromeResourceDispatcherHostDelegate::AppendStandardResourceThrottles( - request, resource_context, resource_type, throttles); -} diff --git a/components/brave_shields/browser/brave_resource_dispatcher_host_delegate.h b/components/brave_shields/browser/brave_resource_dispatcher_host_delegate.h deleted file mode 100644 index 4c83e95af4b2..000000000000 --- a/components/brave_shields/browser/brave_resource_dispatcher_host_delegate.h +++ /dev/null @@ -1,31 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_BROWSER_LOADER_BRAVE_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ -#define BRAVE_BROWSER_LOADER_BRAVE_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ - -#include -#include - -#include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" - - -class BraveResourceDispatcherHostDelegate - : public ChromeResourceDispatcherHostDelegate { - public: - BraveResourceDispatcherHostDelegate(); - ~BraveResourceDispatcherHostDelegate() override; - - protected: - void AppendStandardResourceThrottles( - net::URLRequest* request, - content::ResourceContext* resource_context, - content::ResourceType resource_type, - std::vector>* throttles) - override; - - DISALLOW_COPY_AND_ASSIGN(BraveResourceDispatcherHostDelegate); -}; - -#endif // BRAVE_BROWSER_LOADER_BRAVE_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ diff --git a/components/brave_shields/browser/extension_whitelist_service.cc b/components/brave_shields/browser/extension_whitelist_service.cc index 2fa5532b5985..bb91cb486a0c 100644 --- a/components/brave_shields/browser/extension_whitelist_service.cc +++ b/components/brave_shields/browser/extension_whitelist_service.cc @@ -5,32 +5,24 @@ #include "brave/components/brave_shields/browser/extension_whitelist_service.h" -#include #include -#include "base/base_paths.h" #include "base/bind.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/memory/ptr_util.h" -#include "base/strings/utf_string_conversions.h" -#include "base/threading/thread_restrictions.h" -#include "brave/browser/brave_browser_process_impl.h" -#include "brave/components/brave_shields/browser/ad_block_service.h" -#include "brave/components/brave_shields/browser/local_data_files_service.h" -#include "brave/components/brave_component_updater/browser/dat_file_util.h" +#include "base/task_runner_util.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/vendor/extension-whitelist/extension_whitelist_parser.h" -#include "net/base/registry_controlled_domains/registry_controlled_domain.h" namespace brave_shields { -ExtensionWhitelistService::ExtensionWhitelistService() - : extension_whitelist_client_(new ExtensionWhitelistParser()), +ExtensionWhitelistService::ExtensionWhitelistService( + LocalDataFilesService* local_data_files_service) + : LocalDataFilesObserver(local_data_files_service), + extension_whitelist_client_(new ExtensionWhitelistParser()), weak_factory_(this) { - DETACH_FROM_SEQUENCE(sequence_checker_); } ExtensionWhitelistService::~ExtensionWhitelistService() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); extension_whitelist_client_.reset(); } @@ -44,53 +36,45 @@ bool ExtensionWhitelistService::IsBlacklisted(const std::string& extension_id) c return extension_whitelist_client_->isBlacklisted(extension_id.c_str()); } -void ExtensionWhitelistService::OnDATFileDataReady() { - if (buffer_.empty()) { - LOG(ERROR) << "Could not obtain extension whitelist data"; - return; - } - extension_whitelist_client_.reset(new ExtensionWhitelistParser()); - if (!extension_whitelist_client_->deserialize( - reinterpret_cast(&buffer_.front()))) { - extension_whitelist_client_.reset(); - LOG(ERROR) << "Failed to deserialize extension whitelist data"; - return; - } -} - void ExtensionWhitelistService::OnComponentReady( const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + base::FilePath dat_file_path = install_dir + .AppendASCII(EXTENSION_DAT_FILE_VERSION) + .AppendASCII(EXTENSION_DAT_FILE); - base::FilePath dat_file_path = install_dir.AppendASCII( - EXTENSION_DAT_FILE_VERSION).AppendASCII(EXTENSION_DAT_FILE); - - GetTaskRunner()->PostTaskAndReply( + base::PostTaskAndReplyWithResult( + local_data_files_service()->GetTaskRunner().get(), FROM_HERE, - base::Bind(&brave_component_updater::GetDATFileData, - dat_file_path, - &buffer_), - base::Bind(&ExtensionWhitelistService::OnDATFileDataReady, - weak_factory_.GetWeakPtr())); + base::BindOnce( + &brave_component_updater::LoadDATFileData, + dat_file_path), + base::BindOnce(&ExtensionWhitelistService::OnGetDATFileData, + weak_factory_.GetWeakPtr())); } -scoped_refptr - ExtensionWhitelistService::GetTaskRunner() { - // We share the same task runner as ad-block code - return g_brave_browser_process->ad_block_service()->GetTaskRunner(); +void ExtensionWhitelistService::OnGetDATFileData(GetDATFileDataResult result) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + if (result.second.empty()) { + LOG(ERROR) << "Could not obtain extension whitelist data"; + return; + } + if (!result.first.get()) { + LOG(ERROR) << "Failed to deserialize extension whitelist data"; + return; + } + + extension_whitelist_client_ = std::move(result.first); + buffer_ = std::move(result.second); } /////////////////////////////////////////////////////////////////////////////// -// The extension whitelist factory. Using the Brave Shields as a singleton -// is the job of the browser process. -std::unique_ptr ExtensionWhitelistServiceFactory() { - std::unique_ptr service = - std::make_unique(); - g_brave_browser_process->local_data_files_service()->AddObserver( - service.get()); - return service; +std::unique_ptr ExtensionWhitelistServiceFactory( + LocalDataFilesService* local_data_files_service) { + return std::make_unique(local_data_files_service); } } // namespace brave_shields diff --git a/components/brave_shields/browser/extension_whitelist_service.h b/components/brave_shields/browser/extension_whitelist_service.h index 4870ee7abf3c..9ec63a80e817 100644 --- a/components/brave_shields/browser/extension_whitelist_service.h +++ b/components/brave_shields/browser/extension_whitelist_service.h @@ -16,29 +16,33 @@ #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" -#include "base/sequenced_task_runner.h" -#include "brave/components/brave_shields/browser/base_local_data_files_observer.h" #include "brave/components/brave_component_updater/browser/dat_file_util.h" -#include "content/public/common/resource_type.h" -#include "url/gurl.h" +#include "brave/components/brave_component_updater/browser/local_data_files_observer.h" class ExtensionWhitelistParser; class BraveExtensionProviderTest; class BravePDFDownloadTest; +using brave_component_updater::LocalDataFilesObserver; +using brave_component_updater::LocalDataFilesService; + +// TODO(bridiver) - move out of brave shields namespace brave_shields { // The brave shields service in charge of extension whitelist -class ExtensionWhitelistService : public BaseLocalDataFilesObserver { +class ExtensionWhitelistService : public LocalDataFilesObserver { public: - ExtensionWhitelistService(); + using GetDATFileDataResult = + std::pair, + brave_component_updater::DATFileDataBuffer>; + + ExtensionWhitelistService(LocalDataFilesService* local_data_files_service); ~ExtensionWhitelistService() override; bool IsWhitelisted(const std::string& extension_id) const; bool IsBlacklisted(const std::string& extension_id) const; - scoped_refptr GetTaskRunner(); - // implementation of BaseLocalDataFilesObserver + // implementation of LocalDataFilesObserver void OnComponentReady(const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) override; @@ -47,19 +51,19 @@ class ExtensionWhitelistService : public BaseLocalDataFilesObserver { friend class ::BraveExtensionProviderTest; friend class ::BravePDFDownloadTest; - void OnDATFileDataReady(); - - brave_component_updater::DATFileDataBuffer buffer_; + void OnGetDATFileData(GetDATFileDataResult result); std::unique_ptr extension_whitelist_client_; - + brave_component_updater::DATFileDataBuffer buffer_; SEQUENCE_CHECKER(sequence_checker_); base::WeakPtrFactory weak_factory_; + DISALLOW_COPY_AND_ASSIGN(ExtensionWhitelistService); }; // Creates the ExtensionWhitelistService -std::unique_ptr ExtensionWhitelistServiceFactory(); +std::unique_ptr ExtensionWhitelistServiceFactory( + LocalDataFilesService* local_data_files_service); } // namespace brave_shields diff --git a/components/brave_shields/browser/https_everywhere_service.cc b/components/brave_shields/browser/https_everywhere_service.cc index 517b015bbc8f..0448db2636af 100644 --- a/components/brave_shields/browser/https_everywhere_service.cc +++ b/components/brave_shields/browser/https_everywhere_service.cc @@ -101,7 +101,7 @@ void HTTPSEverywhereService::Cleanup() { GetTaskRunner()->PostTask( FROM_HERE, base::Bind(&HTTPSEverywhereService::CloseDatabase, - base::Unretained(this))); + AsWeakPtr())); } bool HTTPSEverywhereService::Init() { @@ -147,7 +147,7 @@ void HTTPSEverywhereService::OnComponentReady( GetTaskRunner()->PostTask( FROM_HERE, base::Bind(&HTTPSEverywhereService::InitDB, - base::Unretained(this), + AsWeakPtr(), install_dir)); } diff --git a/components/brave_shields/browser/https_everywhere_service.h b/components/brave_shields/browser/https_everywhere_service.h index 69a4e04b68ea..33b8f00e8f38 100644 --- a/components/brave_shields/browser/https_everywhere_service.h +++ b/components/brave_shields/browser/https_everywhere_service.h @@ -5,18 +5,16 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYHWERE_SERVICE_H_ #define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYHWERE_SERVICE_H_ -#include - #include #include #include #include #include "base/files/file_path.h" +#include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" #include "brave/components/brave_shields/browser/base_brave_shields_service.h" #include "brave/components/brave_shields/browser/https_everywhere_recently_used_cache.h" -#include "content/public/common/resource_type.h" namespace leveldb { class DB; @@ -42,17 +40,18 @@ const std::string kHTTPSEverywhereComponentBase64PublicKey = struct HTTPSE_REDIRECTS_COUNT_ST { public: - HTTPSE_REDIRECTS_COUNT_ST(uint64_t request_identifier, - unsigned int redirects): - request_identifier_(request_identifier), - redirects_(redirects) { - } - - uint64_t request_identifier_; - unsigned int redirects_; + HTTPSE_REDIRECTS_COUNT_ST(uint64_t request_identifier, + unsigned int redirects): + request_identifier_(request_identifier), + redirects_(redirects) { + } + + uint64_t request_identifier_; + unsigned int redirects_; }; -class HTTPSEverywhereService : public BaseBraveShieldsService { +class HTTPSEverywhereService : public BaseBraveShieldsService, + public base::SupportsWeakPtr { public: HTTPSEverywhereService(BraveComponent::Delegate* delegate); ~HTTPSEverywhereService() override; diff --git a/components/brave_shields/browser/referrer_whitelist_service.cc b/components/brave_shields/browser/referrer_whitelist_service.cc index d04870abb4ef..d84416f9c97f 100644 --- a/components/brave_shields/browser/referrer_whitelist_service.cc +++ b/components/brave_shields/browser/referrer_whitelist_service.cc @@ -5,27 +5,27 @@ #include "brave/components/brave_shields/browser/referrer_whitelist_service.h" -#include -#include - -#include "base/base_paths.h" #include "base/bind.h" #include "base/json/json_reader.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/memory/ptr_util.h" -#include "base/strings/utf_string_conversions.h" -#include "base/threading/thread_restrictions.h" -#include "brave/browser/brave_browser_process_impl.h" -#include "brave/components/brave_shields/browser/ad_block_service.h" -#include "brave/components/brave_shields/browser/local_data_files_service.h" +#include "base/task/post_task.h" +#include "base/task_runner_util.h" +#include "base/values.h" #include "brave/components/brave_component_updater/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" +#include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" + +using brave_component_updater::LocalDataFilesObserver; +using brave_component_updater::LocalDataFilesService; +using content::BrowserThread; namespace brave_shields { -ReferrerWhitelistService::ReferrerWhitelistService() - : weak_factory_(this) { - DETACH_FROM_SEQUENCE(sequence_checker_); +ReferrerWhitelistService::ReferrerWhitelistService( + LocalDataFilesService* local_data_files_service) + : LocalDataFilesObserver(local_data_files_service), + weak_factory_(this), + weak_factory_io_thread_(this) { } ReferrerWhitelistService::~ReferrerWhitelistService() { @@ -37,11 +37,24 @@ ReferrerWhitelistService::ReferrerWhitelist::ReferrerWhitelist( ReferrerWhitelistService::ReferrerWhitelist::~ReferrerWhitelist() = default; bool ReferrerWhitelistService::IsWhitelisted( - const GURL& firstPartyOrigin, const GURL& subresourceUrl) const { - for (auto rw : referrer_whitelist_) { - if (rw.first_party_pattern.MatchesURL(firstPartyOrigin)) { + const GURL& first_party_origin, const GURL& subresource_url) const { + if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { + return IsWhitelisted( + referrer_whitelist_io_thread_, first_party_origin, subresource_url); + } else { + return IsWhitelisted( + referrer_whitelist_, first_party_origin, subresource_url); + } +} + +bool ReferrerWhitelistService::IsWhitelisted( + const std::vector whitelist, + const GURL& first_party_origin, + const GURL& subresource_url) const { + for (auto rw : whitelist) { + if (rw.first_party_pattern.MatchesURL(first_party_origin)) { for (auto subresource_pattern : rw.subresource_pattern_list) { - if (subresource_pattern.MatchesURL(subresourceUrl)) { + if (subresource_pattern.MatchesURL(subresource_url)) { return true; } } @@ -50,15 +63,15 @@ bool ReferrerWhitelistService::IsWhitelisted( return false; } -void ReferrerWhitelistService::OnDATFileDataReady() { +void ReferrerWhitelistService::OnDATFileDataReady(std::string contents) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); referrer_whitelist_.clear(); - if (file_contents_.empty()) { + if (contents.empty()) { LOG(ERROR) << "Could not obtain referrer whitelist data"; return; } - base::Optional root = base::JSONReader::Read(file_contents_); - file_contents_.clear(); + base::Optional root = base::JSONReader::Read(contents); + contents.clear(); if (!root) { LOG(ERROR) << "Failed to parse referrer whitelist data"; return; @@ -83,39 +96,42 @@ void ReferrerWhitelistService::OnDATFileDataReady() { referrer_whitelist_.push_back(rw); } } + + base::PostTaskWithTraits( + FROM_HERE, {BrowserThread::IO}, + base::BindOnce(&ReferrerWhitelistService::OnDATFileDataReadyOnIOThread, + weak_factory_io_thread_.GetWeakPtr(), + referrer_whitelist_)); +} + +void ReferrerWhitelistService::OnDATFileDataReadyOnIOThread( + std::vector whitelist) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + referrer_whitelist_io_thread_ = std::move(whitelist); } void ReferrerWhitelistService::OnComponentReady( const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) { - base::FilePath dat_file_path = install_dir.AppendASCII( - REFERRER_DAT_FILE_VERSION).AppendASCII(REFERRER_DAT_FILE); - GetTaskRunner()->PostTaskAndReply( - FROM_HERE, - base::Bind(&brave_component_updater::GetDATFileAsString, - dat_file_path, - &file_contents_), - base::Bind(&ReferrerWhitelistService::OnDATFileDataReady, - weak_factory_.GetWeakPtr())); -} + base::FilePath dat_file_path = install_dir + .AppendASCII(REFERRER_DAT_FILE_VERSION) + .AppendASCII(REFERRER_DAT_FILE); -scoped_refptr - ReferrerWhitelistService::GetTaskRunner() { - // We share the same task runner as ad-block code - return g_brave_browser_process->ad_block_service()->GetTaskRunner(); + base::PostTaskAndReplyWithResult( + local_data_files_service()->GetTaskRunner().get(), + FROM_HERE, + base::BindOnce(&brave_component_updater::GetDATFileAsString, + dat_file_path), + base::BindOnce(&ReferrerWhitelistService::OnDATFileDataReady, + weak_factory_.GetWeakPtr())); } /////////////////////////////////////////////////////////////////////////////// -// The referrer whitelist factory. Using the Brave Shields as a singleton -// is the job of the browser process. -std::unique_ptr ReferrerWhitelistServiceFactory() { - std::unique_ptr service = - std::make_unique(); - g_brave_browser_process->local_data_files_service()->AddObserver( - service.get()); - return service; +std::unique_ptr ReferrerWhitelistServiceFactory( + LocalDataFilesService* local_data_files_service) { + return std::make_unique(local_data_files_service); } } // namespace brave_shields diff --git a/components/brave_shields/browser/referrer_whitelist_service.h b/components/brave_shields/browser/referrer_whitelist_service.h index fc3eb5b3280e..adf4fd70f232 100644 --- a/components/brave_shields/browser/referrer_whitelist_service.h +++ b/components/brave_shields/browser/referrer_whitelist_service.h @@ -6,9 +6,6 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_REFERRER_WHITELIST_SERVICE_H_ #define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_REFERRER_WHITELIST_SERVICE_H_ -#include - -#include #include #include #include @@ -16,10 +13,7 @@ #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" -#include "base/sequenced_task_runner.h" -#include "base/values.h" -#include "brave/components/brave_shields/browser/base_local_data_files_observer.h" -#include "content/public/common/resource_type.h" +#include "brave/components/brave_component_updater/browser/local_data_files_observer.h" #include "extensions/common/url_pattern.h" #include "url/gurl.h" @@ -28,19 +22,22 @@ class ReferrerWhitelistServiceTest; +using brave_component_updater::LocalDataFilesObserver; +using brave_component_updater::LocalDataFilesService; + namespace brave_shields { // The brave shields service in charge of referrer whitelist -class ReferrerWhitelistService : public BaseLocalDataFilesObserver { +class ReferrerWhitelistService : public LocalDataFilesObserver { public: - ReferrerWhitelistService(); + explicit ReferrerWhitelistService( + LocalDataFilesService* local_data_files_service); ~ReferrerWhitelistService() override; bool IsWhitelisted(const GURL& firstPartyOrigin, const GURL& subresourceUrl) const; - scoped_refptr GetTaskRunner(); - // implementation of BaseLocalDataFilesObserver + // implementation of LocalDataFilesObserver void OnComponentReady(const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) override; @@ -48,10 +45,6 @@ class ReferrerWhitelistService : public BaseLocalDataFilesObserver { private: friend class ::ReferrerWhitelistServiceTest; - void OnDATFileDataReady(); - - typedef std::vector URLPatternList; - struct ReferrerWhitelist { URLPattern first_party_pattern; URLPatternList subresource_pattern_list; @@ -60,16 +53,26 @@ class ReferrerWhitelistService : public BaseLocalDataFilesObserver { ~ReferrerWhitelist(); }; - std::string file_contents_; + bool IsWhitelisted(const std::vector whitelist, + const GURL& first_party_origin, + const GURL& subresource_url) const; + void OnDATFileDataReady(std::string contents); + void OnDATFileDataReadyOnIOThread(std::vector whitelist); + + typedef std::vector URLPatternList; + std::vector referrer_whitelist_; + std::vector referrer_whitelist_io_thread_; SEQUENCE_CHECKER(sequence_checker_); base::WeakPtrFactory weak_factory_; + base::WeakPtrFactory weak_factory_io_thread_; DISALLOW_COPY_AND_ASSIGN(ReferrerWhitelistService); }; // Creates the ReferrerWhitelistService -std::unique_ptr ReferrerWhitelistServiceFactory(); +std::unique_ptr ReferrerWhitelistServiceFactory( + LocalDataFilesService* local_data_files_service); } // namespace brave_shields diff --git a/components/brave_shields/browser/tracking_protection_service.cc b/components/brave_shields/browser/tracking_protection_service.cc index a3525068d299..6cee64b75874 100644 --- a/components/brave_shields/browser/tracking_protection_service.cc +++ b/components/brave_shields/browser/tracking_protection_service.cc @@ -5,23 +5,16 @@ #include "brave/components/brave_shields/browser/tracking_protection_service.h" -#include #include -#include "base/base_paths.h" #include "base/bind.h" -#include "base/command_line.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/memory/ptr_util.h" -#include "base/strings/utf_string_conversions.h" -#include "base/threading/thread_restrictions.h" -#include "brave/browser/brave_browser_process_impl.h" -#include "brave/components/brave_shields/browser/ad_block_service.h" -#include "brave/components/brave_component_updater/browser/dat_file_util.h" -#include "brave/components/brave_shields/browser/local_data_files_service.h" +#include "base/task/post_task.h" +#include "base/task_runner_util.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/components/content_settings/core/browser/brave_cookie_settings.h" #include "brave/vendor/tracking-protection/TPParser.h" +#include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #if BUILDFLAG(BRAVE_STP_ENABLED) #include "base/strings/string_split.h" @@ -29,12 +22,9 @@ #include "brave/components/brave_shields/browser/tracking_protection_helper.h" #include "brave/components/brave_shields/common/brave_shield_constants.h" #include "components/content_settings/core/browser/host_content_settings_map.h" -#include "content/browser/web_contents/web_contents_impl.h" -#include "content/public/browser/browser_thread.h" - -using content::BrowserThread; #endif +using content::BrowserThread; using content_settings::BraveCookieSettings; namespace brave_shields { @@ -48,13 +38,17 @@ const char kStorageTrackersFile[] = "StorageTrackingProtection.dat"; const int kThirdPartyHostsCacheSize = 20; -TrackingProtectionService::TrackingProtectionService() - : tracking_protection_client_(new CTPParser()), weak_factory_(this) { - DETACH_FROM_SEQUENCE(sequence_checker_); +TrackingProtectionService::TrackingProtectionService( + LocalDataFilesService* local_data_files_service) + : LocalDataFilesObserver(local_data_files_service), + tracking_protection_client_(new CTPParser()), + weak_factory_(this), + weak_factory_io_thread_(this) { } TrackingProtectionService::~TrackingProtectionService() { - tracking_protection_client_.reset(); + BrowserThread::DeleteSoon( + BrowserThread::IO, FROM_HERE, tracking_protection_client_.release()); } #if BUILDFLAG(BRAVE_STP_ENABLED) @@ -175,25 +169,35 @@ bool TrackingProtectionService::ShouldStoreState(HostContentSettingsMap* map, first_party_storage_trackers_.end(); } -void TrackingProtectionService::ParseStorageTrackersData() { - if (storage_trackers_buffer_.empty()) { - LOG(ERROR) << "Could not obtain tracking protection data"; +void TrackingProtectionService::OnGetSTPDATFileData(std::string contents) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + if (contents.empty()) { + LOG(ERROR) << "Could not obtain first party trackers data"; return; } - std::string trackers(storage_trackers_buffer_.begin(), - storage_trackers_buffer_.end()); std::vector storage_trackers = - base::SplitString(base::StringPiece(trackers.data(), trackers.size()), + base::SplitString(base::StringPiece(contents.data(), contents.size()), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); if (storage_trackers.empty()) { LOG(ERROR) << "No first party trackers found"; return; } + + base::PostTaskWithTraits( + FROM_HERE, {BrowserThread::IO}, + base::BindOnce(&TrackingProtectionService::UpdateFirstPartyStorageTrackers, + weak_factory_io_thread_.GetWeakPtr(), + std::move(storage_trackers))); +} + +void TrackingProtectionService::UpdateFirstPartyStorageTrackers( + std::vector) { first_party_storage_trackers_ = base::flat_set(std::move(storage_trackers)); } + #endif bool TrackingProtectionService::ShouldStoreState(BraveCookieSettings* settings, @@ -220,13 +224,13 @@ bool TrackingProtectionService::ShouldStartRequest( const std::string& tab_host, bool* matching_exception_filter, bool* cancel_request_explicitly) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); // There are no exceptions in the TP service, but exceptions are // combined with brave/ad-block. if (matching_exception_filter) { *matching_exception_filter = false; } // Intentionally don't set cancel_request_explicitly - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); std::string host = url.host(); if (!tracking_protection_client_->matchesTracker(tab_host.c_str(), host.c_str())) { @@ -251,57 +255,69 @@ bool TrackingProtectionService::ShouldStartRequest( return false; } -void TrackingProtectionService::OnDATFileDataReady() { - if (buffer_.empty()) { +void TrackingProtectionService::OnGetDATFileData(GetDATFileDataResult result) { + if (result.second.empty()) { LOG(ERROR) << "Could not obtain tracking protection data"; return; } - tracking_protection_client_.reset(new CTPParser()); - if (!tracking_protection_client_->deserialize( - reinterpret_cast(&buffer_.front()))) { - tracking_protection_client_.reset(); + if (!result.first.get()) { LOG(ERROR) << "Failed to deserialize tracking protection data"; return; } + + base::PostTaskWithTraits( + FROM_HERE, {BrowserThread::IO}, + base::BindOnce(&TrackingProtectionService::UpdateTrackingProtectionClient, + weak_factory_io_thread_.GetWeakPtr(), + std::move(result.first), + std::move(result.second))); +} + +void TrackingProtectionService::UpdateTrackingProtectionClient( + std::unique_ptr tracking_protection_client, + brave_component_updater::DATFileDataBuffer buffer) { + tracking_protection_client_ = std::move(tracking_protection_client); + buffer_ = std::move(buffer); } void TrackingProtectionService::OnComponentReady( const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) { - base::FilePath navigation_tracking_protection_path = - install_dir.AppendASCII(kDatFileVersion) - .AppendASCII(kNavigationTrackersFile); + base::FilePath navigation_tracking_protection_path = install_dir + .AppendASCII(kDatFileVersion) + .AppendASCII(kNavigationTrackersFile); - GetTaskRunner()->PostTaskAndReply( + base::PostTaskAndReplyWithResult( + local_data_files_service()->GetTaskRunner().get(), FROM_HERE, - base::Bind(&brave_component_updater::GetDATFileData, - navigation_tracking_protection_path, - &buffer_), - base::Bind(&TrackingProtectionService::OnDATFileDataReady, - weak_factory_.GetWeakPtr())); + base::BindOnce(&brave_component_updater::LoadDATFileData, + navigation_tracking_protection_path), + base::BindOnce(&TrackingProtectionService::OnGetDATFileData, + weak_factory_.GetWeakPtr())); #if BUILDFLAG(BRAVE_STP_ENABLED) if (!TrackingProtectionHelper::IsSmartTrackingProtectionEnabled()) { return; } - base::FilePath storage_tracking_protection_path = - install_dir.AppendASCII(kDatFileVersion) - .AppendASCII(kStorageTrackersFile); + base::FilePath storage_tracking_protection_path = install_dir + .AppendASCII(kDatFileVersion) + .AppendASCII(kStorageTrackersFile); - GetTaskRunner()->PostTaskAndReply( + base::PostTaskAndReplyWithResult( + local_data_files_service()->GetTaskRunner().get(), FROM_HERE, - base::Bind(&brave_component_updater::GetDATFileData, - storage_tracking_protection_path, - &storage_trackers_buffer_), - base::Bind(&TrackingProtectionService::ParseStorageTrackersData, - weak_factory_.GetWeakPtr())); + base::BindOnce(&brave_component_updater::GetDATFileAsString, + storage_tracking_protection_path), + base::BindOnce(&TrackingProtectionService::OnGetSTPDATFileData, + weak_factory_.GetWeakPtr())); #endif } // Ported from Android: net/blockers/blockers_worker.cc std::vector TrackingProtectionService::GetThirdPartyHosts( const std::string& base_host) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); { base::AutoLock guard(third_party_hosts_lock_); std::map>::const_iterator iter = @@ -355,21 +371,12 @@ std::vector TrackingProtectionService::GetThirdPartyHosts( return hosts; } -scoped_refptr -TrackingProtectionService::GetTaskRunner() { - // We share the same task runner for all ad-block and TP code - return g_brave_browser_process->ad_block_service()->GetTaskRunner(); -} - /////////////////////////////////////////////////////////////////////////////// -// The tracking protection factory. Using the Brave Shields as a singleton -// is the job of the browser process. -std::unique_ptr TrackingProtectionServiceFactory() { +std::unique_ptr TrackingProtectionServiceFactory( + LocalDataFilesService* local_data_files_service) { std::unique_ptr service = - std::make_unique(); - g_brave_browser_process->local_data_files_service()->AddObserver( - service.get()); + std::make_unique(local_data_files_service); return service; } diff --git a/components/brave_shields/browser/tracking_protection_service.h b/components/brave_shields/browser/tracking_protection_service.h index 1622ba16a4ec..581b631e07fe 100644 --- a/components/brave_shields/browser/tracking_protection_service.h +++ b/components/brave_shields/browser/tracking_protection_service.h @@ -10,20 +10,17 @@ #include #include -// TODO(brave): is an unapproved C++11 header -#include // NOLINT #include #include #include "base/containers/flat_set.h" #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" -#include "base/sequence_checker.h" #include "base/sequenced_task_runner.h" #include "base/synchronization/lock.h" -#include "brave/components/brave_shields/browser/base_local_data_files_observer.h" -#include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP #include "brave/components/brave_component_updater/browser/dat_file_util.h" +#include "brave/components/brave_component_updater/browser/local_data_files_observer.h" +#include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP #include "content/public/common/resource_type.h" #include "url/gurl.h" @@ -35,12 +32,18 @@ namespace content_settings { class BraveCookieSettings; } +using brave_component_updater::LocalDataFilesObserver; +using brave_component_updater::LocalDataFilesService; + namespace brave_shields { // The brave shields service in charge of tracking protection and init. -class TrackingProtectionService : public BaseLocalDataFilesObserver { +class TrackingProtectionService : public LocalDataFilesObserver { public: - TrackingProtectionService(); + using GetDATFileDataResult = + std::pair, + brave_component_updater::DATFileDataBuffer>; + TrackingProtectionService(LocalDataFilesService* local_data_files_service); ~TrackingProtectionService() override; bool ShouldStartRequest(const GURL& spec, @@ -57,9 +60,7 @@ class TrackingProtectionService : public BaseLocalDataFilesObserver { const GURL& first_party_url, const GURL& tab_url) const; - scoped_refptr GetTaskRunner(); - - // implementation of BaseLocalDataFilesObserver + // implementation of LocalDataFilesObserver void OnComponentReady(const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) override; @@ -91,7 +92,8 @@ class TrackingProtectionService : public BaseLocalDataFilesObserver { #if BUILDFLAG(BRAVE_STP_ENABLED) // ParseStorageTrackersData parses the storage trackers list provided by // the offline-crawler - void ParseStorageTrackersData(); + void OnGetSTPDATFileData(std::string contents); + void UpdateFirstPartyStorageTrackers(std::vector); // For Smart Tracking Protection, we need to keep track of the starting site // that initiated the redirects. We use RenderFrameIdKey to determine the @@ -109,29 +111,31 @@ class TrackingProtectionService : public BaseLocalDataFilesObserver { #endif private: - void OnDATFileDataReady(); + void OnGetDATFileData(GetDATFileDataResult result); + void UpdateTrackingProtectionClient( + std::unique_ptr tracking_protection_client, + brave_component_updater::DATFileDataBuffer); std::vector GetThirdPartyHosts(const std::string& base_host); #if BUILDFLAG(BRAVE_STP_ENABLED) base::flat_set first_party_storage_trackers_; std::map render_frame_key_to_starting_site_url; - - brave_component_updater::DATFileDataBuffer storage_trackers_buffer_; #endif - brave_component_updater::DATFileDataBuffer buffer_; std::unique_ptr tracking_protection_client_; std::vector third_party_base_hosts_; std::map> third_party_hosts_cache_; base::Lock third_party_hosts_lock_; + brave_component_updater::DATFileDataBuffer buffer_; - SEQUENCE_CHECKER(sequence_checker_); base::WeakPtrFactory weak_factory_; + base::WeakPtrFactory weak_factory_io_thread_; DISALLOW_COPY_AND_ASSIGN(TrackingProtectionService); }; // Creates the TrackingProtectionService -std::unique_ptr TrackingProtectionServiceFactory(); +std::unique_ptr TrackingProtectionServiceFactory( + LocalDataFilesService* local_data_files_service); } // namespace brave_shields From ecd17cae72aed0e418e6dc56dfbbb559072c194a Mon Sep 17 00:00:00 2001 From: bridiver Date: Thu, 23 May 2019 10:53:27 -0700 Subject: [PATCH 06/13] test fixes --- .../autoplay_permission_context_browsertest.cc | 4 ++-- .../browser/local_data_files_service.h | 18 ++++-------------- .../browser/ad_block_service_browsertest.cc | 10 +++++----- .../referrer_whitelist_service_browsertest.cc | 6 +++--- .../tracking_protection_service_browsertest.cc | 6 +++--- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/browser/autoplay/autoplay_permission_context_browsertest.cc b/browser/autoplay/autoplay_permission_context_browsertest.cc index 91b2bb071b67..2b7d000311fe 100644 --- a/browser/autoplay/autoplay_permission_context_browsertest.cc +++ b/browser/autoplay/autoplay_permission_context_browsertest.cc @@ -198,7 +198,7 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest { } void InitService() { - brave_shields::LocalDataFilesService:: + brave_component_updater::LocalDataFilesService:: SetComponentIdAndBase64PublicKeyForTest( kLocalDataFilesComponentTestId, kLocalDataFilesComponentTestBase64PublicKey); @@ -227,7 +227,7 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest { void WaitForAutoplayWhitelistServiceThread() { scoped_refptr io_helper( new base::ThreadTestHelper( - g_brave_browser_process->autoplay_whitelist_service()->GetTaskRunner())); + g_brave_browser_process->local_data_files_service()->GetTaskRunner())); ASSERT_TRUE(io_helper->Run()); } diff --git a/components/brave_component_updater/browser/local_data_files_service.h b/components/brave_component_updater/browser/local_data_files_service.h index 38e37260083f..45595ce10a6a 100644 --- a/components/brave_component_updater/browser/local_data_files_service.h +++ b/components/brave_component_updater/browser/local_data_files_service.h @@ -13,13 +13,6 @@ #include "base/observer_list.h" #include "brave/components/brave_component_updater/browser/brave_component.h" -namespace brave_shields { -class AdBlockServiceTest; -class AutoplayWhitelistServiceTest; -class ReferrerWhitelistServiceTest; -class TrackingProtectionServiceTest; -} - namespace brave_component_updater { class LocalDataFilesObserver; @@ -46,21 +39,18 @@ class LocalDataFilesService : public BraveComponent { void AddObserver(LocalDataFilesObserver* observer); void RemoveObserver(LocalDataFilesObserver* observer); + static void SetComponentIdAndBase64PublicKeyForTest( + const std::string& component_id, + const std::string& component_base64_public_key); + protected: void OnComponentReady(const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) override; private: - friend class brave_shields::AdBlockServiceTest; - friend class brave_shields::AutoplayWhitelistServiceTest; - friend class brave_shields::ReferrerWhitelistServiceTest; - friend class brave_shields::TrackingProtectionServiceTest; static std::string g_local_data_files_component_id_; static std::string g_local_data_files_component_base64_public_key_; - static void SetComponentIdAndBase64PublicKeyForTest( - const std::string& component_id, - const std::string& component_base64_public_key); bool initialized_; base::ObserverList::Unchecked observers_; diff --git a/components/brave_shields/browser/ad_block_service_browsertest.cc b/components/brave_shields/browser/ad_block_service_browsertest.cc index 8f985925d791..271f454b44ee 100644 --- a/components/brave_shields/browser/ad_block_service_browsertest.cc +++ b/components/brave_shields/browser/ad_block_service_browsertest.cc @@ -12,7 +12,7 @@ #include "brave/components/brave_shields/browser/ad_block_regional_service.h" #include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h" #include "brave/components/brave_shields/browser/ad_block_service.h" -#include "brave/components/brave_shields/browser/local_data_files_service.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/components/brave_shields/browser/tracking_protection_service.h" #include "brave/components/brave_shields/common/brave_shield_constants.h" #include "brave/vendor/ad-block/ad_block_client.h" @@ -125,7 +125,7 @@ class AdBlockServiceTest : public ExtensionBrowserTest { } void InitTrackingProtectionService() { - brave_shields::LocalDataFilesService:: + brave_component_updater::LocalDataFilesService:: SetComponentIdAndBase64PublicKeyForTest( kTrackingProtectionComponentTestId, kTrackingProtectionComponentTestBase64PublicKey); @@ -220,13 +220,13 @@ class AdBlockServiceTest : public ExtensionBrowserTest { void WaitForDefaultAdBlockServiceThread() { scoped_refptr io_helper(new base::ThreadTestHelper( - g_brave_browser_process->ad_block_service()->GetTaskRunner())); + g_brave_browser_process->local_data_files_service()->GetTaskRunner())); ASSERT_TRUE(io_helper->Run()); } void WaitForRegionalAdBlockServiceThread() { scoped_refptr io_helper(new base::ThreadTestHelper( - g_brave_browser_process->ad_block_regional_service_manager() + g_brave_browser_process->local_data_files_service() ->GetTaskRunner())); ASSERT_TRUE(io_helper->Run()); } @@ -234,7 +234,7 @@ class AdBlockServiceTest : public ExtensionBrowserTest { void WaitForTrackingProtectionServiceThread() { scoped_refptr io_helper( new base::ThreadTestHelper( - g_brave_browser_process->tracking_protection_service() + g_brave_browser_process->local_data_files_service() ->GetTaskRunner())); ASSERT_TRUE(io_helper->Run()); } diff --git a/components/brave_shields/browser/referrer_whitelist_service_browsertest.cc b/components/brave_shields/browser/referrer_whitelist_service_browsertest.cc index d122899d7ed6..1e1a48915178 100644 --- a/components/brave_shields/browser/referrer_whitelist_service_browsertest.cc +++ b/components/brave_shields/browser/referrer_whitelist_service_browsertest.cc @@ -9,7 +9,7 @@ #include "base/test/thread_test_helper.h" #include "brave/browser/brave_browser_process_impl.h" #include "brave/common/brave_paths.h" -#include "brave/components/brave_shields/browser/local_data_files_service.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/components/brave_shields/browser/referrer_whitelist_service.h" #include "chrome/browser/extensions/extension_browsertest.h" @@ -45,7 +45,7 @@ class ReferrerWhitelistServiceTest : public ExtensionBrowserTest { } void InitService() { - brave_shields::LocalDataFilesService:: + brave_component_updater::LocalDataFilesService:: SetComponentIdAndBase64PublicKeyForTest( kLocalDataFilesComponentTestId, kLocalDataFilesComponentTestBase64PublicKey); @@ -75,7 +75,7 @@ class ReferrerWhitelistServiceTest : public ExtensionBrowserTest { void WaitForReferrerWhitelistServiceThread() { scoped_refptr io_helper( new base::ThreadTestHelper( - g_brave_browser_process->referrer_whitelist_service()-> + g_brave_browser_process->local_data_files_service()-> GetTaskRunner())); ASSERT_TRUE(io_helper->Run()); base::RunLoop().RunUntilIdle(); diff --git a/components/brave_shields/browser/tracking_protection_service_browsertest.cc b/components/brave_shields/browser/tracking_protection_service_browsertest.cc index d9bee6abff3e..4018346fb406 100644 --- a/components/brave_shields/browser/tracking_protection_service_browsertest.cc +++ b/components/brave_shields/browser/tracking_protection_service_browsertest.cc @@ -11,7 +11,7 @@ #include "brave/common/brave_paths.h" #include "brave/common/pref_names.h" #include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP -#include "brave/components/brave_shields/browser/local_data_files_service.h" +#include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/components/brave_shields/browser/tracking_protection_service.h" #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/net/url_request_mock_util.h" @@ -99,7 +99,7 @@ class TrackingProtectionServiceTest : public ExtensionBrowserTest { } void InitService() { - brave_shields::LocalDataFilesService:: + brave_component_updater::LocalDataFilesService:: SetComponentIdAndBase64PublicKeyForTest( kTrackingProtectionComponentTestId, kTrackingProtectionComponentTestBase64PublicKey); @@ -129,7 +129,7 @@ class TrackingProtectionServiceTest : public ExtensionBrowserTest { void WaitForTrackingProtectionServiceThread() { scoped_refptr io_helper(new base::ThreadTestHelper( - g_brave_browser_process->tracking_protection_service() + g_brave_browser_process->local_data_files_service() ->GetTaskRunner())); ASSERT_TRUE(io_helper->Run()); } From 7c2976511ff3ba13b428d62f9b5544fc7d0cb729 Mon Sep 17 00:00:00 2001 From: bridiver Date: Thu, 23 May 2019 10:53:38 -0700 Subject: [PATCH 07/13] review cleanup --- browser/net/brave_ad_block_tp_network_delegate_helper.cc | 1 - components/brave_shields/browser/referrer_whitelist_service.cc | 2 +- components/brave_shields/browser/referrer_whitelist_service.h | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/browser/net/brave_ad_block_tp_network_delegate_helper.cc b/browser/net/brave_ad_block_tp_network_delegate_helper.cc index fc89a0b9d35b..05345558c0f3 100644 --- a/browser/net/brave_ad_block_tp_network_delegate_helper.cc +++ b/browser/net/brave_ad_block_tp_network_delegate_helper.cc @@ -163,7 +163,6 @@ int OnBeforeURLRequest_AdBlockTPPreWork( return net::OK; } - // TODO(bridiver) - fix this OnBeforeURLRequestAdBlockTP(ctx); return net::OK; diff --git a/components/brave_shields/browser/referrer_whitelist_service.cc b/components/brave_shields/browser/referrer_whitelist_service.cc index d84416f9c97f..7c5afd90c6a7 100644 --- a/components/brave_shields/browser/referrer_whitelist_service.cc +++ b/components/brave_shields/browser/referrer_whitelist_service.cc @@ -48,7 +48,7 @@ bool ReferrerWhitelistService::IsWhitelisted( } bool ReferrerWhitelistService::IsWhitelisted( - const std::vector whitelist, + const std::vector& whitelist, const GURL& first_party_origin, const GURL& subresource_url) const { for (auto rw : whitelist) { diff --git a/components/brave_shields/browser/referrer_whitelist_service.h b/components/brave_shields/browser/referrer_whitelist_service.h index adf4fd70f232..add9fab7e922 100644 --- a/components/brave_shields/browser/referrer_whitelist_service.h +++ b/components/brave_shields/browser/referrer_whitelist_service.h @@ -53,7 +53,7 @@ class ReferrerWhitelistService : public LocalDataFilesObserver { ~ReferrerWhitelist(); }; - bool IsWhitelisted(const std::vector whitelist, + bool IsWhitelisted(const std::vector& whitelist, const GURL& first_party_origin, const GURL& subresource_url) const; void OnDATFileDataReady(std::string contents); From 886dc9114c1d472671054f7c3b7ce510d8fbe062 Mon Sep 17 00:00:00 2001 From: bridiver Date: Thu, 23 May 2019 11:54:31 -0700 Subject: [PATCH 08/13] lint --- ...autoplay_permission_context_browsertest.cc | 255 +++++++++--------- .../brave_component_installer.cc | 12 +- .../brave_component_installer.h | 9 +- .../brave_component_updater_delegate.cc | 8 +- .../brave_component_updater_delegate.h | 3 +- .../extensions/brave_tor_client_updater.cc | 43 ++- browser/extensions/brave_tor_client_updater.h | 49 ++-- .../brave_httpse_network_delegate_helper.cc | 7 +- .../widevine_cdm_component_installer.cc | 5 +- .../browser/brave_component.cc | 2 + .../browser/brave_component.h | 2 +- .../browser/dat_file_util.h | 8 +- .../browser/local_data_files_observer.cc | 3 +- .../browser/local_data_files_observer.h | 3 +- .../browser/local_data_files_service.cc | 11 +- .../browser/ad_block_base_service.h | 3 +- .../browser/ad_block_custom_filters_service.h | 2 +- .../ad_block_regional_service_manager.h | 2 +- .../brave_shields/browser/ad_block_service.h | 7 +- .../browser/autoplay_whitelist_service.cc | 2 + .../browser/autoplay_whitelist_service.h | 1 + .../browser/base_brave_shields_service.h | 2 +- .../browser/extension_whitelist_service.cc | 6 +- .../browser/extension_whitelist_service.h | 6 +- .../browser/https_everywhere_service.cc | 32 ++- .../browser/https_everywhere_service.h | 43 ++- .../browser/referrer_whitelist_service.cc | 2 + .../browser/tracking_protection_service.cc | 7 +- .../browser/tracking_protection_service.h | 6 +- 29 files changed, 301 insertions(+), 240 deletions(-) diff --git a/browser/autoplay/autoplay_permission_context_browsertest.cc b/browser/autoplay/autoplay_permission_context_browsertest.cc index 2b7d000311fe..25d1d485e276 100644 --- a/browser/autoplay/autoplay_permission_context_browsertest.cc +++ b/browser/autoplay/autoplay_permission_context_browsertest.cc @@ -1,4 +1,5 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -36,10 +37,10 @@ const char kVideoPlayingDetect[] = using extensions::ExtensionBrowserTest; -const std::string kLocalDataFilesComponentTestId( - "eclbkhjphkhalklhipiicaldjbnhdfkc"); +const char kLocalDataFilesComponentTestId[] = + "eclbkhjphkhalklhipiicaldjbnhdfkc"; -const std::string kLocalDataFilesComponentTestBase64PublicKey = +const char kLocalDataFilesComponentTestBase64PublicKey[] = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsleoSxQ3DN+6xym2P1uX" "mN6ArIWd9Oru5CSjS0SRE5upM2EnAl/C20TP8JdIlPi/3tk/SN6Y92K3xIhAby5F" "0rbPDSTXEWGy72tv2qb/WySGwDdvYQu9/J5sEDneVcMrSHcC0VWgcZR0eof4BfOy" @@ -49,123 +50,124 @@ const std::string kLocalDataFilesComponentTestBase64PublicKey = "qwIDAQAB"; class AutoplayPermissionContextBrowserTest : public InProcessBrowserTest { - public: - void SetUpOnMainThread() override { - InProcessBrowserTest::SetUpOnMainThread(); - - content_client_.reset(new ChromeContentClient); - content::SetContentClient(content_client_.get()); - browser_content_client_.reset(new BraveContentBrowserClient()); - content::SetBrowserClientForTesting(browser_content_client_.get()); - - host_resolver()->AddRule("*", "127.0.0.1"); - content::SetupCrossSiteRedirector(embedded_test_server()); - - brave::RegisterPathProvider(); - base::FilePath test_data_dir; - base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); - test_data_dir = test_data_dir.AppendASCII("autoplay"); - embedded_test_server()->ServeFilesFromDirectory(test_data_dir); - - ASSERT_TRUE(embedded_test_server()->Start()); - - autoplay_method_url_ = - embedded_test_server()->GetURL("a.com", "/autoplay_by_method.html"); - autoplay_attr_url_ = - embedded_test_server()->GetURL("a.com", "/autoplay_by_attr.html"); - autoplay_method_muted_url_ = - embedded_test_server()->GetURL("a.com", "/autoplay_by_method_muted.html"); - autoplay_attr_muted_url_ = - embedded_test_server()->GetURL("a.com", "/autoplay_by_attr_muted.html"); - file_autoplay_method_url_ = - GURL("file://" + test_data_dir.AsUTF8Unsafe() + - "/autoplay_by_method.html"); - file_autoplay_attr_url_ = - GURL("file://" + test_data_dir.AsUTF8Unsafe() + - "/autoplay_by_attr.html"); - - GURL pattern_url = embedded_test_server()->GetURL("a.com", "/index.html"); - top_level_page_pattern_ = - ContentSettingsPattern::FromString(pattern_url.spec()); - } - - void TearDown() override { - browser_content_client_.reset(); - content_client_.reset(); - } - - const GURL& autoplay_method_url() { return autoplay_method_url_; } - const GURL& autoplay_attr_url() { return autoplay_attr_url_; } - const GURL& autoplay_method_muted_url() { return autoplay_method_muted_url_; } - const GURL& autoplay_attr_muted_url() { return autoplay_attr_muted_url_; } - const GURL& file_autoplay_method_url() { return file_autoplay_method_url_; } - const GURL& file_autoplay_attr_url() { return file_autoplay_attr_url_; } - - const ContentSettingsPattern& top_level_page_pattern() { - return top_level_page_pattern_; - } - - HostContentSettingsMap * content_settings() { - return HostContentSettingsMapFactory::GetForProfile(browser()->profile()); - } - - void AllowAutoplay() { - content_settings()->SetContentSettingCustomScope( - top_level_page_pattern_, - ContentSettingsPattern::Wildcard(), - CONTENT_SETTINGS_TYPE_AUTOPLAY, - std::string(), - CONTENT_SETTING_ALLOW); - } - - void AskAutoplay() { - content_settings()->SetContentSettingCustomScope( - top_level_page_pattern_, - ContentSettingsPattern::Wildcard(), - CONTENT_SETTINGS_TYPE_AUTOPLAY, - std::string(), - CONTENT_SETTING_ASK); - } - - void BlockAutoplay() { - content_settings()->SetContentSettingCustomScope( - top_level_page_pattern_, - ContentSettingsPattern::Wildcard(), - CONTENT_SETTINGS_TYPE_AUTOPLAY, - std::string(), - CONTENT_SETTING_BLOCK); - } - - content::WebContents* contents() { - return browser()->tab_strip_model()->GetActiveWebContents(); - } - - bool NavigateToURLUntilLoadStop(const GURL& url) { - ui_test_utils::NavigateToURL(browser(), url); - return WaitForLoadStop(contents()); - } - - void WaitForPlaying() { - std::string msg_from_renderer; - ASSERT_TRUE(ExecuteScriptAndExtractString(contents(), "notifyWhenPlaying();", - &msg_from_renderer)); - ASSERT_EQ("PLAYING", msg_from_renderer); - } - - private: - GURL autoplay_method_url_; - GURL autoplay_attr_url_; - GURL autoplay_method_muted_url_; - GURL autoplay_attr_muted_url_; - GURL file_autoplay_method_url_; - GURL file_autoplay_attr_url_; - ContentSettingsPattern top_level_page_pattern_; - std::unique_ptr content_client_; - std::unique_ptr browser_content_client_; + public: + void SetUpOnMainThread() override { + InProcessBrowserTest::SetUpOnMainThread(); + + content_client_.reset(new ChromeContentClient); + content::SetContentClient(content_client_.get()); + browser_content_client_.reset(new BraveContentBrowserClient()); + content::SetBrowserClientForTesting(browser_content_client_.get()); + + host_resolver()->AddRule("*", "127.0.0.1"); + content::SetupCrossSiteRedirector(embedded_test_server()); + + brave::RegisterPathProvider(); + base::FilePath test_data_dir; + base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); + test_data_dir = test_data_dir.AppendASCII("autoplay"); + embedded_test_server()->ServeFilesFromDirectory(test_data_dir); + + ASSERT_TRUE(embedded_test_server()->Start()); + + autoplay_method_url_ = + embedded_test_server()->GetURL("a.com", "/autoplay_by_method.html"); + autoplay_attr_url_ = + embedded_test_server()->GetURL("a.com", "/autoplay_by_attr.html"); + autoplay_method_muted_url_ = + embedded_test_server()->GetURL("a.com", "/autoplay_by_method_muted.html"); + autoplay_attr_muted_url_ = + embedded_test_server()->GetURL("a.com", "/autoplay_by_attr_muted.html"); + file_autoplay_method_url_ = + GURL("file://" + test_data_dir.AsUTF8Unsafe() + + "/autoplay_by_method.html"); + file_autoplay_attr_url_ = + GURL("file://" + test_data_dir.AsUTF8Unsafe() + + "/autoplay_by_attr.html"); + + GURL pattern_url = embedded_test_server()->GetURL("a.com", "/index.html"); + top_level_page_pattern_ = + ContentSettingsPattern::FromString(pattern_url.spec()); + } + + void TearDown() override { + browser_content_client_.reset(); + content_client_.reset(); + } + + const GURL& autoplay_method_url() { return autoplay_method_url_; } + const GURL& autoplay_attr_url() { return autoplay_attr_url_; } + const GURL& autoplay_method_muted_url() { return autoplay_method_muted_url_; } + const GURL& autoplay_attr_muted_url() { return autoplay_attr_muted_url_; } + const GURL& file_autoplay_method_url() { return file_autoplay_method_url_; } + const GURL& file_autoplay_attr_url() { return file_autoplay_attr_url_; } + + const ContentSettingsPattern& top_level_page_pattern() { + return top_level_page_pattern_; + } + + HostContentSettingsMap * content_settings() { + return HostContentSettingsMapFactory::GetForProfile(browser()->profile()); + } + + void AllowAutoplay() { + content_settings()->SetContentSettingCustomScope( + top_level_page_pattern_, + ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, + std::string(), + CONTENT_SETTING_ALLOW); + } + + void AskAutoplay() { + content_settings()->SetContentSettingCustomScope( + top_level_page_pattern_, + ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, + std::string(), + CONTENT_SETTING_ASK); + } + + void BlockAutoplay() { + content_settings()->SetContentSettingCustomScope( + top_level_page_pattern_, + ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, + std::string(), + CONTENT_SETTING_BLOCK); + } + + content::WebContents* contents() { + return browser()->tab_strip_model()->GetActiveWebContents(); + } + + bool NavigateToURLUntilLoadStop(const GURL& url) { + ui_test_utils::NavigateToURL(browser(), url); + return WaitForLoadStop(contents()); + } + + void WaitForPlaying() { + std::string msg_from_renderer; + ASSERT_TRUE(ExecuteScriptAndExtractString(contents(), + "notifyWhenPlaying();", + &msg_from_renderer)); + ASSERT_EQ("PLAYING", msg_from_renderer); + } + + private: + GURL autoplay_method_url_; + GURL autoplay_attr_url_; + GURL autoplay_method_muted_url_; + GURL autoplay_attr_muted_url_; + GURL file_autoplay_method_url_; + GURL file_autoplay_attr_url_; + ContentSettingsPattern top_level_page_pattern_; + std::unique_ptr content_client_; + std::unique_ptr browser_content_client_; }; class AutoplayWhitelistServiceTest : public ExtensionBrowserTest { -public: + public: AutoplayWhitelistServiceTest() {} void SetUp() override { @@ -185,7 +187,8 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest { void PreRunTestOnMainThread() override { ExtensionBrowserTest::PreRunTestOnMainThread(); WaitForAutoplayWhitelistServiceThread(); - ASSERT_TRUE(g_brave_browser_process->local_data_files_service()->IsInitialized()); + ASSERT_TRUE( + g_brave_browser_process->local_data_files_service()->IsInitialized()); } void InitEmbeddedTestServer() { @@ -212,8 +215,8 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest { bool InstallAutoplayWhitelistExtension() { base::FilePath test_data_dir; GetTestDataDir(&test_data_dir); - const extensions::Extension* mock_extension = - InstallExtension(test_data_dir.AppendASCII("autoplay-whitelist-data"), 1); + const extensions::Extension* mock_extension = InstallExtension( + test_data_dir.AppendASCII("autoplay-whitelist-data"), 1); if (!mock_extension) return false; @@ -225,9 +228,8 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest { } void WaitForAutoplayWhitelistServiceThread() { - scoped_refptr io_helper( - new base::ThreadTestHelper( - g_brave_browser_process->local_data_files_service()->GetTaskRunner())); + scoped_refptr io_helper(new base::ThreadTestHelper( + g_brave_browser_process->local_data_files_service()->GetTaskRunner())); ASSERT_TRUE(io_helper->Run()); } @@ -242,14 +244,15 @@ class AutoplayWhitelistServiceTest : public ExtensionBrowserTest { void WaitForPlaying() { std::string msg_from_renderer; - ASSERT_TRUE(ExecuteScriptAndExtractString(contents(), "notifyWhenPlaying();", + ASSERT_TRUE(ExecuteScriptAndExtractString(contents(), + "notifyWhenPlaying();", &msg_from_renderer)); ASSERT_EQ("PLAYING", msg_from_renderer); } const GURL& whitelist_autoplay_url() { return whitelist_autoplay_url_; } -private: + private: GURL whitelist_autoplay_url_; }; diff --git a/browser/component_updater/brave_component_installer.cc b/browser/component_updater/brave_component_installer.cc index 2b4be0864ad9..9a9e26e3330a 100644 --- a/browser/component_updater/brave_component_installer.cc +++ b/browser/component_updater/brave_component_installer.cc @@ -1,4 +1,5 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -99,7 +100,8 @@ bool BraveComponentInstallerPolicy::VerifyInstallation( install_dir.Append(FILE_PATH_LITERAL("manifest.json"))); } -bool BraveComponentInstallerPolicy::SupportsGroupPolicyEnabledComponentUpdates() const { +bool BraveComponentInstallerPolicy:: +SupportsGroupPolicyEnabledComponentUpdates() const { return false; } @@ -107,7 +109,8 @@ bool BraveComponentInstallerPolicy::RequiresNetworkEncryption() const { return false; } -update_client::CrxInstaller::Result BraveComponentInstallerPolicy::OnCustomInstall( +update_client::CrxInstaller::Result +BraveComponentInstallerPolicy::OnCustomInstall( const base::DictionaryValue& manifest, const base::FilePath& install_dir) { return Result(InstallError::NONE); @@ -146,7 +149,8 @@ std::vector BraveComponentInstallerPolicy::GetMimeTypes() const { return std::vector(); } -update_client::InstallerAttributes BraveComponentInstallerPolicy::GetInstallerAttributes() const { +update_client::InstallerAttributes +BraveComponentInstallerPolicy::GetInstallerAttributes() const { return update_client::InstallerAttributes(); } diff --git a/browser/component_updater/brave_component_installer.h b/browser/component_updater/brave_component_installer.h index a2cafa316ba1..136a872d628d 100644 --- a/browser/component_updater/brave_component_installer.h +++ b/browser/component_updater/brave_component_installer.h @@ -1,9 +1,10 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_BRAVE_COMPONENT_INSTALLER_H_ -#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_BRAVE_COMPONENT_INSTALLER_H_ +#ifndef BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_INSTALLER_H_ +#define BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_INSTALLER_H_ #include @@ -68,4 +69,4 @@ void RegisterComponent(component_updater::ComponentUpdateService* cus, } // namespace brave -#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_BRAVE_COMPONENT_INSTALLER_H_ +#endif // BRAVE_BROWSER_COMPONENT_UPDATER_BRAVE_COMPONENT_INSTALLER_H_ diff --git a/browser/component_updater/brave_component_updater_delegate.cc b/browser/component_updater/brave_component_updater_delegate.cc index 0da8ccb2250a..80bb130b63f7 100644 --- a/browser/component_updater/brave_component_updater_delegate.cc +++ b/browser/component_updater/brave_component_updater_delegate.cc @@ -1,9 +1,12 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "brave/browser/component_updater/brave_component_updater_delegate.h" +#include + #include "base/sequenced_task_runner.h" #include "base/task/post_task.h" #include "brave/browser/component_updater/brave_component_installer.h" @@ -47,7 +50,8 @@ void BraveComponentUpdaterDelegate::OnDemandUpdate( ComponentsUI::OnDemandUpdate(component_id); } -scoped_refptr BraveComponentUpdaterDelegate::GetTaskRunner() { +scoped_refptr +BraveComponentUpdaterDelegate::GetTaskRunner() { return task_runner_; } diff --git a/browser/component_updater/brave_component_updater_delegate.h b/browser/component_updater/brave_component_updater_delegate.h index 8c278b08f19f..275b2db476ef 100644 --- a/browser/component_updater/brave_component_updater_delegate.h +++ b/browser/component_updater/brave_component_updater_delegate.h @@ -1,4 +1,5 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ diff --git a/browser/extensions/brave_tor_client_updater.cc b/browser/extensions/brave_tor_client_updater.cc index 7e119fe1d389..2258d423e6c1 100644 --- a/browser/extensions/brave_tor_client_updater.cc +++ b/browser/extensions/brave_tor_client_updater.cc @@ -1,9 +1,13 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "brave/browser/extensions/brave_tor_client_updater.h" +#include +#include + #include "base/files/file_enumerator.h" #include "base/files/file_path.h" #include "base/files/file_util.h" @@ -14,6 +18,41 @@ using brave_component_updater::BraveComponent; namespace extensions { +#if defined(OS_WIN) +const char kTorClientComponentName[] = "Brave Tor Client Updater (Windows)"; +const char kTorClientComponentId[] = "cpoalefficncklhjfpglfiplenlpccdb"; +const char kTorClientComponentBase64PublicKey = + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1AYAsmR/VoRwkZCsjRpD" + "58xjrgngW5y17H6BqQ7/CeNSpmXlcMXy6bJs2D/yeS96rhZSrQSHTzS9h/ieo/NZ" + "F5PIwcv07YsG5sRd6zF5a6m92aWCQa1OkbL6jpcpL2Tbc4mCqNxhKMErT7EtIIWL" + "9cW+mtFUjUjvV3rJLQ3Vy9u6fEi77Y8b25kGnTJoVt3uETAIHBnyNpL7ac2f8Iq+" + "4Qa6VFmuoBhup54tTZvMv+ikoKKaQkHzkkjTa4hV5AzdnFDKO8C9qJb3T/Ef0+MO" + "IuZjyySVzGNcOfASeHkhxhlwMQSQuhCN5mdFW5YBnVZ/5QWx8WzbhqBny/ZynS4e" + "rQIDAQAB"; +#elif defined(OS_MACOSX) +const char kTorClientComponentName[] = "Brave Tor Client Updater (Mac)"; +const char kTorClientComponentId[] = "cldoidikboihgcjfkhdeidbpclkineef"; +const char kTorClientComponentBase64PublicKey[] = + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw2QUXSbVuRxYpItYApZ8" + "Ly/fGeUD3A+vb3J7Ot62CF32wTfWweANWyyB+EBGfbtNDAuRlAbNk0QYeCQEttuf" + "jLh3Kd5KR5fSyyNNd2cAzAckQ8p7JdiFYjvqZLGC5vlnHgqq4O8xACX5EPwHLNFD" + "iSpsthNmz3GCUrHrzPHjHVfy+IuucQXygnRv2fwIaAIxJmTbYm4fqsGKpfolWdMe" + "jKVAy1hc9mApZSyt4oGvUu4SJZnxlYMrY4Ze+OWbDesi2JGy+6dA1ddL9IdnwCb3" + "9CBOMNjaHeCVz0MKxdCWGPieQM0R7S1KvDCVqAkss6NAbLB6AVM0JulqxC9b+hr/" + "xwIDAQAB"; +#elif defined(OS_LINUX) +const char kTorClientComponentName[] = "Brave Tor Client Updater (Linux)"; +const char kTorClientComponentId[] = "biahpgbdmdkfgndcmfiipgcebobojjkp"; +const char kTorClientComponentBase64PublicKey[] = + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAseuq8dXKawkZC7RSE7xb" + "lRwh6DD+oPEGEjZWKh596/42IrWNQw60gRIR6s7x0YHh5geFnBRkx9bisEXOrFkq" + "oArVY7eD0gMkjpor9CneD5CnCxc9/2uIPajtXfAmmLAHtN6Wk7yW30SkRf/WvLWX" + "/H+PqskQBN7I5MO7sveYxSrRMSj7prrFHEiFmXTgG/DwjpzrA7KV6vmzz/ReD51o" + "+UuLHE7cxPhnsNd/52uY3Lod3GhxvDoXKYx9kWlzBjxB53A2eLBCDIwwCpqS4/Ib" + "RSJhvF33KQT8YM+7V1MitwB49klP4aEWPXwOlFHmn9Dkmlx2RbO7S0tRcH9UH4LK" + "2QIDAQAB"; +#endif + std::string BraveTorClientUpdater::g_tor_client_component_id_( kTorClientComponentId); std::string BraveTorClientUpdater::g_tor_client_component_base64_public_key_( @@ -74,7 +113,7 @@ void BraveTorClientUpdater::InitExecutablePath( << executable_path.value().c_str(); return; } -#endif // defined(OS_POSIX) +#endif // defined(OS_POSIX) executable_path_ = executable_path; } diff --git a/browser/extensions/brave_tor_client_updater.h b/browser/extensions/brave_tor_client_updater.h index 32a25c725a04..63b853aa88b1 100644 --- a/browser/extensions/brave_tor_client_updater.h +++ b/browser/extensions/brave_tor_client_updater.h @@ -1,10 +1,14 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef BRAVE_BROWSER_EXTENSIONS_BRAVE_TOR_CLIENT_UPDATER_H_ #define BRAVE_BROWSER_EXTENSIONS_BRAVE_TOR_CLIENT_UPDATER_H_ +#include +#include + #include "base/files/file_path.h" #include "base/sequenced_task_runner.h" #include "brave/components/brave_component_updater/browser/brave_component.h" @@ -13,47 +17,26 @@ class BraveTorClientUpdaterTest; using brave_component_updater::BraveComponent; +// TODO(bridiver) - this doesn't belong under extensions namespace extensions { #if defined(OS_WIN) -const std::string kTorClientComponentName("Brave Tor Client Updater (Windows)"); -const std::string kTorClientComponentId("cpoalefficncklhjfpglfiplenlpccdb"); -const std::string kTorClientComponentBase64PublicKey = - "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1AYAsmR/VoRwkZCsjRpD" - "58xjrgngW5y17H6BqQ7/CeNSpmXlcMXy6bJs2D/yeS96rhZSrQSHTzS9h/ieo/NZ" - "F5PIwcv07YsG5sRd6zF5a6m92aWCQa1OkbL6jpcpL2Tbc4mCqNxhKMErT7EtIIWL" - "9cW+mtFUjUjvV3rJLQ3Vy9u6fEi77Y8b25kGnTJoVt3uETAIHBnyNpL7ac2f8Iq+" - "4Qa6VFmuoBhup54tTZvMv+ikoKKaQkHzkkjTa4hV5AzdnFDKO8C9qJb3T/Ef0+MO" - "IuZjyySVzGNcOfASeHkhxhlwMQSQuhCN5mdFW5YBnVZ/5QWx8WzbhqBny/ZynS4e" - "rQIDAQAB"; +extern const char kTorClientComponentName[]; +extern const char kTorClientComponentId[]; #elif defined(OS_MACOSX) -const std::string kTorClientComponentName("Brave Tor Client Updater (Mac)"); -const std::string kTorClientComponentId("cldoidikboihgcjfkhdeidbpclkineef"); -const std::string kTorClientComponentBase64PublicKey = - "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw2QUXSbVuRxYpItYApZ8" - "Ly/fGeUD3A+vb3J7Ot62CF32wTfWweANWyyB+EBGfbtNDAuRlAbNk0QYeCQEttuf" - "jLh3Kd5KR5fSyyNNd2cAzAckQ8p7JdiFYjvqZLGC5vlnHgqq4O8xACX5EPwHLNFD" - "iSpsthNmz3GCUrHrzPHjHVfy+IuucQXygnRv2fwIaAIxJmTbYm4fqsGKpfolWdMe" - "jKVAy1hc9mApZSyt4oGvUu4SJZnxlYMrY4Ze+OWbDesi2JGy+6dA1ddL9IdnwCb3" - "9CBOMNjaHeCVz0MKxdCWGPieQM0R7S1KvDCVqAkss6NAbLB6AVM0JulqxC9b+hr/" - "xwIDAQAB"; +extern const char kTorClientComponentName[]; +extern const char kTorClientComponentId[]; +extern const char kTorClientComponentBase64PublicKey[]; #elif defined(OS_LINUX) -const std::string kTorClientComponentName("Brave Tor Client Updater (Linux)"); -const std::string kTorClientComponentId("biahpgbdmdkfgndcmfiipgcebobojjkp"); -const std::string kTorClientComponentBase64PublicKey = - "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAseuq8dXKawkZC7RSE7xb" - "lRwh6DD+oPEGEjZWKh596/42IrWNQw60gRIR6s7x0YHh5geFnBRkx9bisEXOrFkq" - "oArVY7eD0gMkjpor9CneD5CnCxc9/2uIPajtXfAmmLAHtN6Wk7yW30SkRf/WvLWX" - "/H+PqskQBN7I5MO7sveYxSrRMSj7prrFHEiFmXTgG/DwjpzrA7KV6vmzz/ReD51o" - "+UuLHE7cxPhnsNd/52uY3Lod3GhxvDoXKYx9kWlzBjxB53A2eLBCDIwwCpqS4/Ib" - "RSJhvF33KQT8YM+7V1MitwB49klP4aEWPXwOlFHmn9Dkmlx2RbO7S0tRcH9UH4LK" - "2QIDAQAB"; +extern const char kTorClientComponentName[]; +extern const char kTorClientComponentId[]; +extern const char kTorClientComponentBase64PublicKey[]; #endif class BraveTorClientUpdater : public BraveComponent { public: - BraveTorClientUpdater(BraveComponent::Delegate* delegate); - ~BraveTorClientUpdater() override; + explicit BraveTorClientUpdater(BraveComponent::Delegate* delegate); + ~BraveTorClientUpdater() override; void Register(); base::FilePath GetExecutablePath() const; diff --git a/browser/net/brave_httpse_network_delegate_helper.cc b/browser/net/brave_httpse_network_delegate_helper.cc index 0babeaf48233..7d27b090207b 100644 --- a/browser/net/brave_httpse_network_delegate_helper.cc +++ b/browser/net/brave_httpse_network_delegate_helper.cc @@ -27,7 +27,7 @@ void OnBeforeURLRequest_HttpseFileWork( base::BlockingType::WILL_BLOCK); DCHECK_NE(ctx->request_identifier, 0U); g_brave_browser_process->https_everywhere_service()-> - GetHTTPSURL(&ctx->request_url, ctx->request_identifier, ctx->new_url_spec); + GetHTTPSURL(&ctx->request_url, ctx->request_identifier, &ctx->new_url_spec); } void OnBeforeURLRequest_HttpsePostFileWork( @@ -72,8 +72,9 @@ int OnBeforeURLRequest_HttpsePreFileWork( if (is_valid_url) { if (!g_brave_browser_process->https_everywhere_service()-> - GetHTTPSURLFromCacheOnly(&ctx->request_url, ctx->request_identifier, - ctx->new_url_spec)) { + GetHTTPSURLFromCacheOnly(&ctx->request_url, + ctx->request_identifier, + &ctx->new_url_spec)) { g_brave_browser_process->https_everywhere_service()-> GetTaskRunner()->PostTaskAndReply(FROM_HERE, base::Bind(OnBeforeURLRequest_HttpseFileWork, ctx), diff --git a/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc b/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc index e2ea79a836de..aa66fd39d5b9 100644 --- a/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc +++ b/chromium_src/chrome/browser/component_updater/widevine_cdm_component_installer.cc @@ -1,9 +1,10 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ #define RegisterWidevineCdmComponent RegisterWidevineCdmComponent_ChromiumImpl -#include "../../../../../chrome/browser/component_updater/widevine_cdm_component_installer.cc" +#include "../../../../../chrome/browser/component_updater/widevine_cdm_component_installer.cc" // NOLINT #undef RegisterWidevineCdmComponent #include "brave/browser/brave_browser_process_impl.h" diff --git a/components/brave_component_updater/browser/brave_component.cc b/components/brave_component_updater/browser/brave_component.cc index 75c30402cfbf..558fcc4ee82f 100644 --- a/components/brave_component_updater/browser/brave_component.cc +++ b/components/brave_component_updater/browser/brave_component.cc @@ -5,6 +5,8 @@ #include "brave/components/brave_component_updater/browser/brave_component.h" +#include + #include "base/bind.h" #include "base/sequenced_task_runner.h" diff --git a/components/brave_component_updater/browser/brave_component.h b/components/brave_component_updater/browser/brave_component.h index a2a287577a54..99b593ac58f8 100644 --- a/components/brave_component_updater/browser/brave_component.h +++ b/components/brave_component_updater/browser/brave_component.h @@ -32,7 +32,7 @@ class BraveComponent { virtual scoped_refptr GetTaskRunner() = 0; }; - BraveComponent(Delegate* delegate); + explicit BraveComponent(Delegate* delegate); virtual ~BraveComponent(); void Register(const std::string& component_name, const std::string& component_id, diff --git a/components/brave_component_updater/browser/dat_file_util.h b/components/brave_component_updater/browser/dat_file_util.h index 6d0d03596001..c67ca8a5513b 100644 --- a/components/brave_component_updater/browser/dat_file_util.h +++ b/components/brave_component_updater/browser/dat_file_util.h @@ -3,10 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_DAT_FILE_UTIL_H_ -#define BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_DAT_FILE_UTIL_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_DAT_FILE_UTIL_H_ +#define BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_DAT_FILE_UTIL_H_ +#include #include +#include #include #include "base/files/file_path.h" @@ -36,4 +38,4 @@ std::pair, DATFileDataBuffer> LoadDATFileData( } // namespace brave_component_updater -#endif // BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_DAT_FILE_UTIL_H_ +#endif // BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_DAT_FILE_UTIL_H_ diff --git a/components/brave_component_updater/browser/local_data_files_observer.cc b/components/brave_component_updater/browser/local_data_files_observer.cc index 9a2ba44b3728..1aaeeaaa3f49 100644 --- a/components/brave_component_updater/browser/local_data_files_observer.cc +++ b/components/brave_component_updater/browser/local_data_files_observer.cc @@ -1,4 +1,5 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ diff --git a/components/brave_component_updater/browser/local_data_files_observer.h b/components/brave_component_updater/browser/local_data_files_observer.h index c4ee1bf179d1..d574f0f318a7 100644 --- a/components/brave_component_updater/browser/local_data_files_observer.h +++ b/components/brave_component_updater/browser/local_data_files_observer.h @@ -1,4 +1,5 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ diff --git a/components/brave_component_updater/browser/local_data_files_service.cc b/components/brave_component_updater/browser/local_data_files_service.cc index 2e152f29cb22..d1485828541f 100644 --- a/components/brave_component_updater/browser/local_data_files_service.cc +++ b/components/brave_component_updater/browser/local_data_files_service.cc @@ -1,10 +1,10 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "brave/components/brave_component_updater/browser/local_data_files_service.h" -// #include "base/base_paths.h" #include "brave/components/brave_component_updater/browser/local_data_files_observer.h" using brave_component_updater::BraveComponent; @@ -12,9 +12,10 @@ using brave_component_updater::BraveComponent; namespace brave_component_updater { std::string LocalDataFilesService::g_local_data_files_component_id_( - kLocalDataFilesComponentId); -std::string LocalDataFilesService::g_local_data_files_component_base64_public_key_( - kLocalDataFilesComponentBase64PublicKey); + kLocalDataFilesComponentId); +std::string LocalDataFilesService:: +g_local_data_files_component_base64_public_key_( + kLocalDataFilesComponentBase64PublicKey); LocalDataFilesService::LocalDataFilesService(BraveComponent::Delegate* delegate) : BraveComponent(delegate), diff --git a/components/brave_shields/browser/ad_block_base_service.h b/components/brave_shields/browser/ad_block_base_service.h index df3ce36982d3..8931ab4b6996 100644 --- a/components/brave_shields/browser/ad_block_base_service.h +++ b/components/brave_shields/browser/ad_block_base_service.h @@ -10,6 +10,7 @@ #include #include +#include #include #include "base/files/file_path.h" @@ -34,7 +35,7 @@ class AdBlockBaseService : public BaseBraveShieldsService { std::pair, brave_component_updater::DATFileDataBuffer>; - AdBlockBaseService(BraveComponent::Delegate* delegate); + explicit AdBlockBaseService(BraveComponent::Delegate* delegate); ~AdBlockBaseService() override; bool ShouldStartRequest(const GURL &url, content::ResourceType resource_type, diff --git a/components/brave_shields/browser/ad_block_custom_filters_service.h b/components/brave_shields/browser/ad_block_custom_filters_service.h index e2bd4ac85430..721ddbc04cf9 100644 --- a/components/brave_shields/browser/ad_block_custom_filters_service.h +++ b/components/brave_shields/browser/ad_block_custom_filters_service.h @@ -21,7 +21,7 @@ namespace brave_shields { // checking and init. class AdBlockCustomFiltersService : public AdBlockBaseService { public: - AdBlockCustomFiltersService(BraveComponent::Delegate* delegate); + explicit AdBlockCustomFiltersService(BraveComponent::Delegate* delegate); ~AdBlockCustomFiltersService() override; std::string GetCustomFilters(); diff --git a/components/brave_shields/browser/ad_block_regional_service_manager.h b/components/brave_shields/browser/ad_block_regional_service_manager.h index e4a3820f12c1..7fe3107dc2df 100644 --- a/components/brave_shields/browser/ad_block_regional_service_manager.h +++ b/components/brave_shields/browser/ad_block_regional_service_manager.h @@ -33,7 +33,7 @@ class AdBlockRegionalService; // managing regional AdBlock clients. class AdBlockRegionalServiceManager { public: - AdBlockRegionalServiceManager(BraveComponent::Delegate* delegate); + explicit AdBlockRegionalServiceManager(BraveComponent::Delegate* delegate); ~AdBlockRegionalServiceManager(); static bool IsSupportedLocale(const std::string& locale); diff --git a/components/brave_shields/browser/ad_block_service.h b/components/brave_shields/browser/ad_block_service.h index 6440a5c9ecae..9c8cfaac037b 100644 --- a/components/brave_shields/browser/ad_block_service.h +++ b/components/brave_shields/browser/ad_block_service.h @@ -14,10 +14,11 @@ #include "brave/components/brave_shields/browser/ad_block_base_service.h" #include "components/prefs/pref_registry_simple.h" -#include "content/public/common/resource_type.h" class AdBlockServiceTest; +using brave_component_updater::BraveComponent; + namespace brave_shields { const char kAdBlockComponentName[] = "Brave Ad Block Updater"; @@ -34,7 +35,7 @@ const char kAdBlockComponentBase64PublicKey[] = // The brave shields service in charge of ad-block checking and init. class AdBlockService : public AdBlockBaseService { public: - AdBlockService(brave_component_updater::BraveComponent::Delegate* delegate); + explicit AdBlockService(BraveComponent::Delegate* delegate); ~AdBlockService() override; protected: @@ -58,7 +59,7 @@ class AdBlockService : public AdBlockBaseService { // Creates the AdBlockService std::unique_ptr AdBlockServiceFactory( - brave_component_updater::BraveComponent::Delegate* delegate); + BraveComponent::Delegate* delegate); // Registers the local_state preferences used by Adblock void RegisterPrefsForAdBlockService(PrefRegistrySimple* registry); diff --git a/components/brave_shields/browser/autoplay_whitelist_service.cc b/components/brave_shields/browser/autoplay_whitelist_service.cc index 8f90c3c0400b..2a875fdae53a 100644 --- a/components/brave_shields/browser/autoplay_whitelist_service.cc +++ b/components/brave_shields/browser/autoplay_whitelist_service.cc @@ -5,6 +5,8 @@ #include "brave/components/brave_shields/browser/autoplay_whitelist_service.h" +#include + #include "base/bind.h" #include "base/task/post_task.h" #include "base/task_runner_util.h" diff --git a/components/brave_shields/browser/autoplay_whitelist_service.h b/components/brave_shields/browser/autoplay_whitelist_service.h index c3fe8dc1df85..e07a14ce4a27 100644 --- a/components/brave_shields/browser/autoplay_whitelist_service.h +++ b/components/brave_shields/browser/autoplay_whitelist_service.h @@ -8,6 +8,7 @@ #include #include +#include #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" diff --git a/components/brave_shields/browser/base_brave_shields_service.h b/components/brave_shields/browser/base_brave_shields_service.h index 92d98e443ec9..ad10e0e87a93 100644 --- a/components/brave_shields/browser/base_brave_shields_service.h +++ b/components/brave_shields/browser/base_brave_shields_service.h @@ -27,7 +27,7 @@ namespace brave_shields { // tracking protection, etc. class BaseBraveShieldsService : public BraveComponent { public: - BaseBraveShieldsService(BraveComponent::Delegate* delegate); + explicit BaseBraveShieldsService(BraveComponent::Delegate* delegate); ~BaseBraveShieldsService() override; bool Start(); void Stop(); diff --git a/components/brave_shields/browser/extension_whitelist_service.cc b/components/brave_shields/browser/extension_whitelist_service.cc index bb91cb486a0c..ca1196c2e563 100644 --- a/components/brave_shields/browser/extension_whitelist_service.cc +++ b/components/brave_shields/browser/extension_whitelist_service.cc @@ -26,12 +26,14 @@ ExtensionWhitelistService::~ExtensionWhitelistService() { extension_whitelist_client_.reset(); } -bool ExtensionWhitelistService::IsWhitelisted(const std::string& extension_id) const { +bool ExtensionWhitelistService::IsWhitelisted( + const std::string& extension_id) const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); return extension_whitelist_client_->isWhitelisted(extension_id.c_str()); } -bool ExtensionWhitelistService::IsBlacklisted(const std::string& extension_id) const { +bool ExtensionWhitelistService::IsBlacklisted( + const std::string& extension_id) const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); return extension_whitelist_client_->isBlacklisted(extension_id.c_str()); } diff --git a/components/brave_shields/browser/extension_whitelist_service.h b/components/brave_shields/browser/extension_whitelist_service.h index 9ec63a80e817..cc921b9ffa1f 100644 --- a/components/brave_shields/browser/extension_whitelist_service.h +++ b/components/brave_shields/browser/extension_whitelist_service.h @@ -6,11 +6,10 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_EXTENSION_WHITELIST_SERVICE_H_ #define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_EXTENSION_WHITELIST_SERVICE_H_ -#include - #include #include #include +#include #include #include "base/files/file_path.h" @@ -36,7 +35,8 @@ class ExtensionWhitelistService : public LocalDataFilesObserver { std::pair, brave_component_updater::DATFileDataBuffer>; - ExtensionWhitelistService(LocalDataFilesService* local_data_files_service); + explicit ExtensionWhitelistService( + LocalDataFilesService* local_data_files_service); ~ExtensionWhitelistService() override; bool IsWhitelisted(const std::string& extension_id) const; diff --git a/components/brave_shields/browser/https_everywhere_service.cc b/components/brave_shields/browser/https_everywhere_service.cc index 0448db2636af..975a42b5b723 100644 --- a/components/brave_shields/browser/https_everywhere_service.cc +++ b/components/brave_shields/browser/https_everywhere_service.cc @@ -79,6 +79,17 @@ std::string leveldbGet(leveldb::DB* db, const std::string &key) { namespace brave_shields { +const char kHTTPSEverywhereComponentName[] = "Brave HTTPS Everywhere Updater"; +const char kHTTPSEverywhereComponentId[] = "oofiananboodjbbmdelgdommihjbkfag"; +const char kHTTPSEverywhereComponentBase64PublicKey[] = + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvn9zSMjTmhkQyrZu5UdN" + "350nPqLoSeCYngcC7yDFwaUHjoBQXCZqGeDC69ciCQ2mlRhcV2nxXqlUDkiC6+7m" + "651nI+gi4oVqHagc7EFUyGA0yuIk7qIMvCBdH7wbET27de0rzbRzRht9EKzEjIhC" + "BtoPnmyrO/8qPrH4XR4cPfnFPuJssBBxC1B35H7rh0Br9qePhPDDe9OjyqYxPuio" + "+YcC9obL4g5krVrfrlKLfFNpIewUcJyBpSlCgfxEyEhgDkK9cILTMUi5vC7GxS3P" + "OtZqgfRg8Da4i+NwmjQqrz0JFtPMMSyUnmeMj+mSOL4xZVWr8fU2/GOCXs9gczDp" + "JwIDAQAB"; + bool HTTPSEverywhereService::g_ignore_port_for_test_(false); std::string HTTPSEverywhereService::g_https_everywhere_component_id_( kHTTPSEverywhereComponentId); @@ -152,8 +163,9 @@ void HTTPSEverywhereService::OnComponentReady( } bool HTTPSEverywhereService::GetHTTPSURL( - const GURL* url, const uint64_t& request_identifier, - std::string& new_url) { + const GURL* url, + const uint64_t& request_identifier, + std::string* new_url) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (!url->is_valid()) @@ -166,7 +178,7 @@ bool HTTPSEverywhereService::GetHTTPSURL( return false; } - if (recently_used_cache_.get(url->spec(), &new_url)) { + if (recently_used_cache_.get(url->spec(), new_url)) { AddHTTPSEUrlToRedirectList(request_identifier); return true; } @@ -183,9 +195,9 @@ bool HTTPSEverywhereService::GetHTTPSURL( for (auto domain : domains) { std::string value = leveldbGet(level_db_, domain); if (!value.empty()) { - new_url = ApplyHTTPSRule(candidate_url.spec(), value); - if (0 != new_url.length()) { - recently_used_cache_.add(candidate_url.spec(), new_url); + *new_url = ApplyHTTPSRule(candidate_url.spec(), value); + if (0 != new_url->length()) { + recently_used_cache_.add(candidate_url.spec(), *new_url); AddHTTPSEUrlToRedirectList(request_identifier); return true; } @@ -198,7 +210,7 @@ bool HTTPSEverywhereService::GetHTTPSURL( bool HTTPSEverywhereService::GetHTTPSURLFromCacheOnly( const GURL* url, const uint64_t& request_identifier, - std::string& cached_url) { + std::string* cached_url) { if (!url->is_valid()) return false; @@ -209,7 +221,7 @@ bool HTTPSEverywhereService::GetHTTPSURLFromCacheOnly( return false; } - if (recently_used_cache_.get(url->spec(), &cached_url)) { + if (recently_used_cache_.get(url->spec(), cached_url)) { AddHTTPSEUrlToRedirectList(request_identifier); return true; } @@ -218,7 +230,7 @@ bool HTTPSEverywhereService::GetHTTPSURLFromCacheOnly( bool HTTPSEverywhereService::ShouldHTTPSERedirect( const uint64_t& request_identifier) { - std::lock_guard guard(httpse_get_urls_redirects_count_mutex_); + base::AutoLock auto_lock(httpse_get_urls_redirects_count_mutex_); for (size_t i = 0; i < httpse_urls_redirects_count_.size(); i++) { if (request_identifier == httpse_urls_redirects_count_[i].request_identifier_ && @@ -234,7 +246,7 @@ bool HTTPSEverywhereService::ShouldHTTPSERedirect( void HTTPSEverywhereService::AddHTTPSEUrlToRedirectList( const uint64_t& request_identifier) { // Adding redirects count for the current request - std::lock_guard guard(httpse_get_urls_redirects_count_mutex_); + base::AutoLock auto_lock(httpse_get_urls_redirects_count_mutex_); bool hostFound = false; for (size_t i = 0; i < httpse_urls_redirects_count_.size(); i++) { if (request_identifier == diff --git a/components/brave_shields/browser/https_everywhere_service.h b/components/brave_shields/browser/https_everywhere_service.h index 33b8f00e8f38..aa7024f56989 100644 --- a/components/brave_shields/browser/https_everywhere_service.h +++ b/components/brave_shields/browser/https_everywhere_service.h @@ -1,18 +1,19 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYHWERE_SERVICE_H_ -#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYHWERE_SERVICE_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_SERVICE_H_ +#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_SERVICE_H_ #include #include #include -#include #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" +#include "base/synchronization/lock.h" #include "brave/components/brave_shields/browser/base_brave_shields_service.h" #include "brave/components/brave_shields/browser/https_everywhere_recently_used_cache.h" @@ -26,22 +27,14 @@ using brave_component_updater::BraveComponent; namespace brave_shields { -const std::string kHTTPSEverywhereComponentName("Brave HTTPS Everywhere Updater"); -const std::string kHTTPSEverywhereComponentId("oofiananboodjbbmdelgdommihjbkfag"); - -const std::string kHTTPSEverywhereComponentBase64PublicKey = - "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvn9zSMjTmhkQyrZu5UdN" - "350nPqLoSeCYngcC7yDFwaUHjoBQXCZqGeDC69ciCQ2mlRhcV2nxXqlUDkiC6+7m" - "651nI+gi4oVqHagc7EFUyGA0yuIk7qIMvCBdH7wbET27de0rzbRzRht9EKzEjIhC" - "BtoPnmyrO/8qPrH4XR4cPfnFPuJssBBxC1B35H7rh0Br9qePhPDDe9OjyqYxPuio" - "+YcC9obL4g5krVrfrlKLfFNpIewUcJyBpSlCgfxEyEhgDkK9cILTMUi5vC7GxS3P" - "OtZqgfRg8Da4i+NwmjQqrz0JFtPMMSyUnmeMj+mSOL4xZVWr8fU2/GOCXs9gczDp" - "JwIDAQAB"; +extern const char kHTTPSEverywhereComponentName[]; +extern const char kHTTPSEverywhereComponentId[]; +extern const char kHTTPSEverywhereComponentBase64PublicKey[]; struct HTTPSE_REDIRECTS_COUNT_ST { -public: + public: HTTPSE_REDIRECTS_COUNT_ST(uint64_t request_identifier, - unsigned int redirects): + unsigned int redirects): request_identifier_(request_identifier), redirects_(redirects) { } @@ -53,12 +46,14 @@ struct HTTPSE_REDIRECTS_COUNT_ST { class HTTPSEverywhereService : public BaseBraveShieldsService, public base::SupportsWeakPtr { public: - HTTPSEverywhereService(BraveComponent::Delegate* delegate); - ~HTTPSEverywhereService() override; - bool GetHTTPSURL(const GURL* url, const uint64_t& request_id, - std::string& new_url); + explicit HTTPSEverywhereService(BraveComponent::Delegate* delegate); + ~HTTPSEverywhereService() override; + bool GetHTTPSURL(const GURL* url, + const uint64_t& request_id, + std::string* new_url); bool GetHTTPSURLFromCacheOnly(const GURL* url, - const uint64_t& request_id, std::string& cached_url); + const uint64_t& request_id, + std::string* cached_url); protected: bool Init() override; @@ -87,7 +82,7 @@ class HTTPSEverywhereService : public BaseBraveShieldsService, void InitDB(const base::FilePath& install_dir); - std::mutex httpse_get_urls_redirects_count_mutex_; + base::Lock httpse_get_urls_redirects_count_mutex_; std::vector httpse_urls_redirects_count_; HTTPSERecentlyUsedCache recently_used_cache_; leveldb::DB* level_db_; @@ -102,4 +97,4 @@ std::unique_ptr HTTPSEverywhereServiceFactory( } // namespace brave_shields -#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYHWERE_SERVICE_H_ +#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_SERVICE_H_ diff --git a/components/brave_shields/browser/referrer_whitelist_service.cc b/components/brave_shields/browser/referrer_whitelist_service.cc index 7c5afd90c6a7..78b52a8ac8c7 100644 --- a/components/brave_shields/browser/referrer_whitelist_service.cc +++ b/components/brave_shields/browser/referrer_whitelist_service.cc @@ -5,6 +5,8 @@ #include "brave/components/brave_shields/browser/referrer_whitelist_service.h" +#include + #include "base/bind.h" #include "base/json/json_reader.h" #include "base/task/post_task.h" diff --git a/components/brave_shields/browser/tracking_protection_service.cc b/components/brave_shields/browser/tracking_protection_service.cc index 6cee64b75874..36f4c4b8fa22 100644 --- a/components/brave_shields/browser/tracking_protection_service.cc +++ b/components/brave_shields/browser/tracking_protection_service.cc @@ -187,9 +187,10 @@ void TrackingProtectionService::OnGetSTPDATFileData(std::string contents) { base::PostTaskWithTraits( FROM_HERE, {BrowserThread::IO}, - base::BindOnce(&TrackingProtectionService::UpdateFirstPartyStorageTrackers, - weak_factory_io_thread_.GetWeakPtr(), - std::move(storage_trackers))); + base::BindOnce( + &TrackingProtectionService::UpdateFirstPartyStorageTrackers, + weak_factory_io_thread_.GetWeakPtr(), + std::move(storage_trackers))); } void TrackingProtectionService::UpdateFirstPartyStorageTrackers( diff --git a/components/brave_shields/browser/tracking_protection_service.h b/components/brave_shields/browser/tracking_protection_service.h index 581b631e07fe..86490263ef2a 100644 --- a/components/brave_shields/browser/tracking_protection_service.h +++ b/components/brave_shields/browser/tracking_protection_service.h @@ -6,11 +6,10 @@ #ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_TRACKING_PROTECTION_SERVICE_H_ #define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_TRACKING_PROTECTION_SERVICE_H_ -#include - #include #include #include +#include #include #include "base/containers/flat_set.h" @@ -43,7 +42,8 @@ class TrackingProtectionService : public LocalDataFilesObserver { using GetDATFileDataResult = std::pair, brave_component_updater::DATFileDataBuffer>; - TrackingProtectionService(LocalDataFilesService* local_data_files_service); + explicit TrackingProtectionService( + LocalDataFilesService* local_data_files_service); ~TrackingProtectionService() override; bool ShouldStartRequest(const GURL& spec, From c93ddc7e5e8a6ec039132e0f92d3f54b052043f0 Mon Sep 17 00:00:00 2001 From: bridiver Date: Thu, 23 May 2019 15:47:36 -0700 Subject: [PATCH 09/13] fixes for STP enabled build --- .../brave_shields/browser/tracking_protection_service.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/brave_shields/browser/tracking_protection_service.cc b/components/brave_shields/browser/tracking_protection_service.cc index 36f4c4b8fa22..1fef5ab1f09b 100644 --- a/components/brave_shields/browser/tracking_protection_service.cc +++ b/components/brave_shields/browser/tracking_protection_service.cc @@ -170,7 +170,6 @@ bool TrackingProtectionService::ShouldStoreState(HostContentSettingsMap* map, } void TrackingProtectionService::OnGetSTPDATFileData(std::string contents) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); if (contents.empty()) { LOG(ERROR) << "Could not obtain first party trackers data"; return; @@ -194,7 +193,7 @@ void TrackingProtectionService::OnGetSTPDATFileData(std::string contents) { } void TrackingProtectionService::UpdateFirstPartyStorageTrackers( - std::vector) { + std::vector storage_trackers) { first_party_storage_trackers_ = base::flat_set(std::move(storage_trackers)); } From ed258449c8c40ccb042372f587782ff434ef5254 Mon Sep 17 00:00:00 2001 From: bridiver Date: Thu, 23 May 2019 20:17:59 -0700 Subject: [PATCH 10/13] standardize callbacks --- browser/component_updater/brave_component_installer.cc | 6 ++++-- browser/component_updater/brave_component_installer.h | 10 +++++----- .../brave_component_updater/browser/dat_file_util.h | 9 +++++++-- .../brave_shields/browser/ad_block_base_service.h | 3 +-- .../brave_shields/browser/autoplay_whitelist_service.h | 3 +-- .../browser/extension_whitelist_service.h | 3 +-- .../browser/tracking_protection_service.h | 4 ++-- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/browser/component_updater/brave_component_installer.cc b/browser/component_updater/brave_component_installer.cc index 9a9e26e3330a..0adf37b960b1 100644 --- a/browser/component_updater/brave_component_installer.cc +++ b/browser/component_updater/brave_component_installer.cc @@ -23,6 +23,8 @@ #include "components/update_client/utils.h" #include "crypto/sha2.h" +using brave_component_updater::BraveComponent; + namespace { using Result = update_client::CrxInstaller::Result; using InstallError = update_client::InstallError; @@ -78,7 +80,7 @@ namespace brave { BraveComponentInstallerPolicy::BraveComponentInstallerPolicy( const std::string& name, const std::string& base64_public_key, - ReadyCallback ready_callback) + BraveComponent::ReadyCallback ready_callback) : name_(name), base64_public_key_(base64_public_key), ready_callback_(std::move(ready_callback)) { @@ -159,7 +161,7 @@ void RegisterComponent( const std::string& name, const std::string& base64_public_key, base::OnceClosure registered_callback, - ReadyCallback ready_callback) { + BraveComponent::ReadyCallback ready_callback) { auto installer = base::MakeRefCounted( std::make_unique( name, base64_public_key, std::move(ready_callback))); diff --git a/browser/component_updater/brave_component_installer.h b/browser/component_updater/brave_component_installer.h index 136a872d628d..fa277d11f5d5 100644 --- a/browser/component_updater/brave_component_installer.h +++ b/browser/component_updater/brave_component_installer.h @@ -16,11 +16,11 @@ #include "base/callback.h" #include "base/files/file_path.h" #include "base/macros.h" +#include "brave/components/brave_component_updater/browser/brave_component.h" #include "components/component_updater/component_installer.h" #include "components/update_client/update_client.h" -using ReadyCallback = base::OnceCallback; +using brave_component_updater::BraveComponent; namespace brave { @@ -29,7 +29,7 @@ class BraveComponentInstallerPolicy : public: explicit BraveComponentInstallerPolicy(const std::string& name, const std::string& base64_public_key, - ReadyCallback ready_callback); + BraveComponent::ReadyCallback ready_callback); ~BraveComponentInstallerPolicy() override; @@ -56,7 +56,7 @@ class BraveComponentInstallerPolicy : std::string name_; std::string base64_public_key_; std::string public_key_; - ReadyCallback ready_callback_; + BraveComponent::ReadyCallback ready_callback_; DISALLOW_COPY_AND_ASSIGN(BraveComponentInstallerPolicy); }; @@ -65,7 +65,7 @@ void RegisterComponent(component_updater::ComponentUpdateService* cus, const std::string& name, const std::string& base64_public_key, base::OnceClosure registered_callback, - ReadyCallback ready_callback); + BraveComponent::ReadyCallback ready_callback); } // namespace brave diff --git a/components/brave_component_updater/browser/dat_file_util.h b/components/brave_component_updater/browser/dat_file_util.h index c67ca8a5513b..2163516d4422 100644 --- a/components/brave_component_updater/browser/dat_file_util.h +++ b/components/brave_component_updater/browser/dat_file_util.h @@ -22,7 +22,11 @@ void GetDATFileData(const base::FilePath& file_path, std::string GetDATFileAsString(const base::FilePath& file_path); template -std::pair, DATFileDataBuffer> LoadDATFileData( +using LoadDATFileDataResult = + std::pair, brave_component_updater::DATFileDataBuffer>; + +template +LoadDATFileDataResult LoadDATFileData( const base::FilePath& dat_file_path) { DATFileDataBuffer buffer; GetDATFileData(dat_file_path, &buffer); @@ -32,10 +36,11 @@ std::pair, DATFileDataBuffer> LoadDATFileData( !client->deserialize(reinterpret_cast(&buffer.front()))) client.reset(); - return std::pair, DATFileDataBuffer>( + return LoadDATFileDataResult( std::move(client), std::move(buffer)); } + } // namespace brave_component_updater #endif // BRAVE_COMPONENTS_BRAVE_COMPONENT_UPDATER_BROWSER_DAT_FILE_UTIL_H_ diff --git a/components/brave_shields/browser/ad_block_base_service.h b/components/brave_shields/browser/ad_block_base_service.h index 8931ab4b6996..f12b71ff8f8d 100644 --- a/components/brave_shields/browser/ad_block_base_service.h +++ b/components/brave_shields/browser/ad_block_base_service.h @@ -32,8 +32,7 @@ namespace brave_shields { class AdBlockBaseService : public BaseBraveShieldsService { public: using GetDATFileDataResult = - std::pair, - brave_component_updater::DATFileDataBuffer>; + brave_component_updater::LoadDATFileDataResult; explicit AdBlockBaseService(BraveComponent::Delegate* delegate); ~AdBlockBaseService() override; diff --git a/components/brave_shields/browser/autoplay_whitelist_service.h b/components/brave_shields/browser/autoplay_whitelist_service.h index e07a14ce4a27..13019ff7a34f 100644 --- a/components/brave_shields/browser/autoplay_whitelist_service.h +++ b/components/brave_shields/browser/autoplay_whitelist_service.h @@ -29,8 +29,7 @@ namespace brave_shields { class AutoplayWhitelistService : public LocalDataFilesObserver { public: using GetDATFileDataResult = - std::pair, - brave_component_updater::DATFileDataBuffer>; + brave_component_updater::LoadDATFileDataResult; explicit AutoplayWhitelistService( LocalDataFilesService* local_data_files_service); diff --git a/components/brave_shields/browser/extension_whitelist_service.h b/components/brave_shields/browser/extension_whitelist_service.h index cc921b9ffa1f..79fd9dafe443 100644 --- a/components/brave_shields/browser/extension_whitelist_service.h +++ b/components/brave_shields/browser/extension_whitelist_service.h @@ -32,8 +32,7 @@ namespace brave_shields { class ExtensionWhitelistService : public LocalDataFilesObserver { public: using GetDATFileDataResult = - std::pair, - brave_component_updater::DATFileDataBuffer>; + brave_component_updater::LoadDATFileDataResult; explicit ExtensionWhitelistService( LocalDataFilesService* local_data_files_service); diff --git a/components/brave_shields/browser/tracking_protection_service.h b/components/brave_shields/browser/tracking_protection_service.h index 86490263ef2a..7a3038bb0213 100644 --- a/components/brave_shields/browser/tracking_protection_service.h +++ b/components/brave_shields/browser/tracking_protection_service.h @@ -40,8 +40,8 @@ namespace brave_shields { class TrackingProtectionService : public LocalDataFilesObserver { public: using GetDATFileDataResult = - std::pair, - brave_component_updater::DATFileDataBuffer>; + brave_component_updater::LoadDATFileDataResult; + explicit TrackingProtectionService( LocalDataFilesService* local_data_files_service); ~TrackingProtectionService() override; From 568251407ac722809644465d3c3b8338a741ca2b Mon Sep 17 00:00:00 2001 From: bridiver Date: Thu, 23 May 2019 20:18:17 -0700 Subject: [PATCH 11/13] check for io thread --- components/brave_shields/browser/tracking_protection_service.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/components/brave_shields/browser/tracking_protection_service.cc b/components/brave_shields/browser/tracking_protection_service.cc index 1fef5ab1f09b..d3f52669f0cc 100644 --- a/components/brave_shields/browser/tracking_protection_service.cc +++ b/components/brave_shields/browser/tracking_protection_service.cc @@ -276,6 +276,7 @@ void TrackingProtectionService::OnGetDATFileData(GetDATFileDataResult result) { void TrackingProtectionService::UpdateTrackingProtectionClient( std::unique_ptr tracking_protection_client, brave_component_updater::DATFileDataBuffer buffer) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); tracking_protection_client_ = std::move(tracking_protection_client); buffer_ = std::move(buffer); } From 5bd42fb090757483d4ff68035851a1c1e7efdc5b Mon Sep 17 00:00:00 2001 From: bridiver Date: Thu, 23 May 2019 20:18:28 -0700 Subject: [PATCH 12/13] fix tests to wait for IO thread tasks --- .../browser/ad_block_service_browsertest.cc | 54 ++++++++----------- .../referrer_whitelist_service_browsertest.cc | 13 +++-- ...tracking_protection_service_browsertest.cc | 11 ++-- 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/components/brave_shields/browser/ad_block_service_browsertest.cc b/components/brave_shields/browser/ad_block_service_browsertest.cc index 271f454b44ee..a6ee092da570 100644 --- a/components/brave_shields/browser/ad_block_service_browsertest.cc +++ b/components/brave_shields/browser/ad_block_service_browsertest.cc @@ -4,6 +4,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "base/path_service.h" +#include "base/task/post_task.h" #include "base/test/thread_test_helper.h" #include "brave/browser/brave_browser_process_impl.h" #include "brave/common/brave_paths.h" @@ -20,9 +21,12 @@ #include "chrome/browser/ui/browser.h" #include "chrome/test/base/ui_test_utils.h" #include "components/prefs/pref_service.h" +#include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "content/public/test/browser_test_utils.h" #include "net/dns/mock_host_resolver.h" +using content::BrowserThread; using extensions::ExtensionBrowserTest; const char kAdBlockTestPage[] = "/blocking.html"; @@ -78,7 +82,7 @@ class AdBlockServiceTest : public ExtensionBrowserTest { void PreRunTestOnMainThread() override { ExtensionBrowserTest::PreRunTestOnMainThread(); - WaitForDefaultAdBlockServiceThread(); + WaitForAdBlockServiceThreads(); ASSERT_TRUE(g_brave_browser_process->ad_block_service()->IsInitialized()); } @@ -156,7 +160,7 @@ class AdBlockServiceTest : public ExtensionBrowserTest { g_brave_browser_process->ad_block_service()->OnComponentReady( ad_block_extension->id(), ad_block_extension->path(), ""); - WaitForDefaultAdBlockServiceThread(); + WaitForAdBlockServiceThreads(); return true; } @@ -183,7 +187,7 @@ class AdBlockServiceTest : public ExtensionBrowserTest { ->regional_services_.find(uuid); regional_service->second->OnComponentReady(ad_block_extension->id(), ad_block_extension->path(), ""); - WaitForRegionalAdBlockServiceThread(); + WaitForAdBlockServiceThreads(); return true; } @@ -200,7 +204,7 @@ class AdBlockServiceTest : public ExtensionBrowserTest { g_brave_browser_process->tracking_protection_service()->OnComponentReady( tracking_protection_extension->id(), tracking_protection_extension->path(), ""); - WaitForTrackingProtectionServiceThread(); + WaitForAdBlockServiceThreads(); return true; } @@ -213,29 +217,13 @@ class AdBlockServiceTest : public ExtensionBrowserTest { return true; } - void WaitForAllAdBlockServiceThreads() { - WaitForDefaultAdBlockServiceThread(); - WaitForRegionalAdBlockServiceThread(); - } - - void WaitForDefaultAdBlockServiceThread() { - scoped_refptr io_helper(new base::ThreadTestHelper( + void WaitForAdBlockServiceThreads() { + scoped_refptr tr_helper(new base::ThreadTestHelper( g_brave_browser_process->local_data_files_service()->GetTaskRunner())); - ASSERT_TRUE(io_helper->Run()); - } - - void WaitForRegionalAdBlockServiceThread() { + ASSERT_TRUE(tr_helper->Run()); scoped_refptr io_helper(new base::ThreadTestHelper( - g_brave_browser_process->local_data_files_service() - ->GetTaskRunner())); - ASSERT_TRUE(io_helper->Run()); - } - - void WaitForTrackingProtectionServiceThread() { - scoped_refptr io_helper( - new base::ThreadTestHelper( - g_brave_browser_process->local_data_files_service() - ->GetTaskRunner())); + base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}) + .get())); ASSERT_TRUE(io_helper->Run()); } }; @@ -698,7 +686,7 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, SocialButttonAdBLockTagTest) { kAdBlockTestPage); g_brave_browser_process->ad_block_service()->EnableTag( brave_shields::kFacebookEmbeds, true); - WaitForDefaultAdBlockServiceThread(); + WaitForAdBlockServiceThreads(); GURL resource_url = embedded_test_server()->GetURL("example.com", "/logo.png"); ui_test_utils::NavigateToURL(browser(), tab_url); @@ -723,7 +711,7 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, SocialButttonAdBlockDiffTagTest) { kAdBlockTestPage); g_brave_browser_process->ad_block_service()->EnableTag( brave_shields::kFacebookEmbeds, true); - WaitForDefaultAdBlockServiceThread(); + WaitForAdBlockServiceThreads(); GURL resource_url = embedded_test_server()->GetURL("example.com", "/logo.png"); ui_test_utils::NavigateToURL(browser(), tab_url); @@ -751,38 +739,38 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, TagPrefsControlTags) { // Toggling prefs once is reflected in the adblock client. prefs->SetBoolean(kLinkedInEmbedControlType, true); - WaitForAllAdBlockServiceThreads(); + WaitForAdBlockServiceThreads(); AssertTagExists(brave_shields::kFacebookEmbeds, true); AssertTagExists(brave_shields::kTwitterEmbeds, true); AssertTagExists(brave_shields::kLinkedInEmbeds, true); prefs->SetBoolean(kFBEmbedControlType, false); - WaitForAllAdBlockServiceThreads(); + WaitForAdBlockServiceThreads(); AssertTagExists(brave_shields::kFacebookEmbeds, false); AssertTagExists(brave_shields::kTwitterEmbeds, true); AssertTagExists(brave_shields::kLinkedInEmbeds, true); prefs->SetBoolean(kTwitterEmbedControlType, false); - WaitForAllAdBlockServiceThreads(); + WaitForAdBlockServiceThreads(); AssertTagExists(brave_shields::kFacebookEmbeds, false); AssertTagExists(brave_shields::kTwitterEmbeds, false); AssertTagExists(brave_shields::kLinkedInEmbeds, true); // Toggling prefs back is reflected in the adblock client. prefs->SetBoolean(kLinkedInEmbedControlType, false); - WaitForAllAdBlockServiceThreads(); + WaitForAdBlockServiceThreads(); AssertTagExists(brave_shields::kFacebookEmbeds, false); AssertTagExists(brave_shields::kTwitterEmbeds, false); AssertTagExists(brave_shields::kLinkedInEmbeds, false); prefs->SetBoolean(kFBEmbedControlType, true); - WaitForAllAdBlockServiceThreads(); + WaitForAdBlockServiceThreads(); AssertTagExists(brave_shields::kFacebookEmbeds, true); AssertTagExists(brave_shields::kTwitterEmbeds, false); AssertTagExists(brave_shields::kLinkedInEmbeds, false); prefs->SetBoolean(kTwitterEmbedControlType, true); - WaitForAllAdBlockServiceThreads(); + WaitForAdBlockServiceThreads(); AssertTagExists(brave_shields::kFacebookEmbeds, true); AssertTagExists(brave_shields::kTwitterEmbeds, true); AssertTagExists(brave_shields::kLinkedInEmbeds, false); diff --git a/components/brave_shields/browser/referrer_whitelist_service_browsertest.cc b/components/brave_shields/browser/referrer_whitelist_service_browsertest.cc index 1e1a48915178..3b63ef9ac57b 100644 --- a/components/brave_shields/browser/referrer_whitelist_service_browsertest.cc +++ b/components/brave_shields/browser/referrer_whitelist_service_browsertest.cc @@ -12,7 +12,10 @@ #include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/components/brave_shields/browser/referrer_whitelist_service.h" #include "chrome/browser/extensions/extension_browsertest.h" +#include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" +using content::BrowserThread; using extensions::ExtensionBrowserTest; const char kLocalDataFilesComponentTestId[] = @@ -73,10 +76,12 @@ class ReferrerWhitelistServiceTest : public ExtensionBrowserTest { } void WaitForReferrerWhitelistServiceThread() { - scoped_refptr io_helper( - new base::ThreadTestHelper( - g_brave_browser_process->local_data_files_service()-> - GetTaskRunner())); + scoped_refptr tr_helper(new base::ThreadTestHelper( + g_brave_browser_process->local_data_files_service()->GetTaskRunner())); + ASSERT_TRUE(tr_helper->Run()); + scoped_refptr io_helper(new base::ThreadTestHelper( + base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}) + .get())); ASSERT_TRUE(io_helper->Run()); base::RunLoop().RunUntilIdle(); } diff --git a/components/brave_shields/browser/tracking_protection_service_browsertest.cc b/components/brave_shields/browser/tracking_protection_service_browsertest.cc index 4018346fb406..0d347b5b3c0a 100644 --- a/components/brave_shields/browser/tracking_protection_service_browsertest.cc +++ b/components/brave_shields/browser/tracking_protection_service_browsertest.cc @@ -19,6 +19,7 @@ #include "chrome/test/base/ui_test_utils.h" #include "components/prefs/pref_service.h" #include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "content/public/test/browser_test_utils.h" #include "net/dns/mock_host_resolver.h" @@ -33,6 +34,7 @@ const char kRedirectPage[] = "/client-redirect?"; const char kStoragePage[] = "/storage.html"; #endif +using content::BrowserThread; using extensions::ExtensionBrowserTest; const char kTrackingPage[] = "/tracking.html"; @@ -77,7 +79,7 @@ class TrackingProtectionServiceTest : public ExtensionBrowserTest { void SetUpOnMainThread() override { ExtensionBrowserTest::SetUpOnMainThread(); base::PostTaskWithTraits( - FROM_HERE, {content::BrowserThread::IO}, + FROM_HERE, {BrowserThread::IO}, base::BindOnce(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); host_resolver()->AddRule("*", "127.0.0.1"); } @@ -128,9 +130,12 @@ class TrackingProtectionServiceTest : public ExtensionBrowserTest { } void WaitForTrackingProtectionServiceThread() { + scoped_refptr tr_helper(new base::ThreadTestHelper( + g_brave_browser_process->local_data_files_service()->GetTaskRunner())); + ASSERT_TRUE(tr_helper->Run()); scoped_refptr io_helper(new base::ThreadTestHelper( - g_brave_browser_process->local_data_files_service() - ->GetTaskRunner())); + base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}) + .get())); ASSERT_TRUE(io_helper->Run()); } }; From 662850bf64ea425abc2877234c69f0d6ebbeef0a Mon Sep 17 00:00:00 2001 From: bridiver Date: Fri, 24 May 2019 10:31:16 -0700 Subject: [PATCH 13/13] missing `[]` for OS_WIN --- browser/extensions/brave_tor_client_updater.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/extensions/brave_tor_client_updater.cc b/browser/extensions/brave_tor_client_updater.cc index 2258d423e6c1..43892218e6aa 100644 --- a/browser/extensions/brave_tor_client_updater.cc +++ b/browser/extensions/brave_tor_client_updater.cc @@ -21,7 +21,7 @@ namespace extensions { #if defined(OS_WIN) const char kTorClientComponentName[] = "Brave Tor Client Updater (Windows)"; const char kTorClientComponentId[] = "cpoalefficncklhjfpglfiplenlpccdb"; -const char kTorClientComponentBase64PublicKey = +const char kTorClientComponentBase64PublicKey[] = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1AYAsmR/VoRwkZCsjRpD" "58xjrgngW5y17H6BqQ7/CeNSpmXlcMXy6bJs2D/yeS96rhZSrQSHTzS9h/ieo/NZ" "F5PIwcv07YsG5sRd6zF5a6m92aWCQa1OkbL6jpcpL2Tbc4mCqNxhKMErT7EtIIWL"