Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor tor to brave/components #6881

Merged
merged 10 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,6 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_PROFILES_TOR_PROFILE_NAME" desc="Name of the Tor profile.">
Tor
</message>
<message name="IDS_UTILITY_PROCESS_TOR_LAUNCHER_NAME" desc="The utility process which launch Tor">
Tor Launcher
</message>
<message name="IDS_SERVICE_BAT_ADS" desc="The bat ads utility process">
Bat Ads Service
</message>
Expand Down
15 changes: 3 additions & 12 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/build/config.gni")
import("//brave/components/binance/browser/buildflags/buildflags.gni")
import("//brave/components/brave_ads/browser/buildflags/buildflags.gni")
Expand All @@ -16,6 +15,7 @@ import("//brave/components/greaselion/browser/buildflags/buildflags.gni")
import("//brave/components/ipfs/buildflags/buildflags.gni")
import("//brave/components/moonpay/browser/buildflags/buildflags.gni")
import("//brave/components/speedreader/buildflags.gni")
import("//brave/components/tor/buildflags/buildflags.gni")
import("//build/buildflag_header.gni")
import("//build/config/features.gni")
import("//chrome/common/features.gni")
Expand Down Expand Up @@ -130,7 +130,6 @@ source_set("browser_process") {
"//base",
"//brave/browser/net",
"//brave/browser/notifications",
"//brave/browser/tor:buildflags",
"//brave/browser/translate/buildflags",
"//brave/chromium_src:browser",
"//brave/chromium_src:browser",
Expand Down Expand Up @@ -160,6 +159,7 @@ source_set("browser_process") {
"//brave/components/p3a",
"//brave/components/resources",
"//brave/components/speedreader:buildflags",
"//brave/components/tor/buildflags",
"//brave/components/weekly_storage",
"//brave/services/network/public/cpp",
"//chrome/common",
Expand Down Expand Up @@ -197,15 +197,6 @@ source_set("browser_process") {
"//ui/base",
]

if (enable_tor) {
sources += [
# TODO(bridiver) - change the directory for these
"extensions/brave_tor_client_updater.cc",
"extensions/brave_tor_client_updater.h",
]
deps += [ "//third_party/re2" ]
}

if (brave_wallet_enabled) {
deps += [
"//brave/components/brave_wallet",
Expand Down Expand Up @@ -330,7 +321,7 @@ source_set("browser_process") {
if (enable_tor) {
deps += [
"//brave/browser/tor",
"//brave/common/tor:pref_names",
"//brave/components/tor",
]
}

Expand Down
4 changes: 2 additions & 2 deletions browser/brave_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include "base/command_line.h"
#include "brave/browser/browsing_data/brave_clear_browsing_data.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_sync/buildflags/buildflags.h"
#include "brave/components/brave_sync/features.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "chrome/common/chrome_features.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_driver_switches.h"
Expand All @@ -20,7 +20,7 @@
#if BUILDFLAG(ENABLE_TOR)
#include <string>
#include "base/files/file_util.h"
#include "brave/common/tor/tor_constants.h"
#include "brave/components/tor/tor_constants.h"
#include "chrome/browser/browser_process_impl.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
Expand Down
14 changes: 8 additions & 6 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "brave/browser/net/brave_system_request_handler.h"
#include "brave/browser/profiles/brave_profile_manager.h"
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/browser/ui/brave_browser_command_controller.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h"
Expand Down Expand Up @@ -70,8 +69,8 @@
#endif

#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/extensions/brave_tor_client_updater.h"
#include "brave/common/tor/pref_names.h"
#include "brave/components/tor/brave_tor_client_updater.h"
#include "brave/components/tor/pref_names.h"
#endif

#if BUILDFLAG(IPFS_ENABLED)
Expand Down Expand Up @@ -309,13 +308,16 @@ void BraveBrowserProcessImpl::OnBraveDarkModeChanged() {
}

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

tor_client_updater_ = extensions::BraveTorClientUpdaterFactory(
brave_component_updater_delegate());
base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);

tor_client_updater_.reset(new tor::BraveTorClientUpdater(
brave_component_updater_delegate(), local_state(), user_data_dir));
return tor_client_updater_.get();
}

Expand Down
8 changes: 4 additions & 4 deletions browser/brave_browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include <memory>

#include "base/memory/ref_counted.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/components/brave_ads/browser/buildflags/buildflags.h"
#include "brave/components/brave_component_updater/browser/brave_component.h"
#include "brave/components/brave_referrals/buildflags/buildflags.h"
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/speedreader/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "chrome/browser/browser_process_impl.h"
#include "extensions/buildflags/buildflags.h"
#include "third_party/widevine/cdm/buildflags.h"
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace ntp_background_images {
class NTPBackgroundImagesService;
} // namespace ntp_background_images

namespace extensions {
namespace tor {
class BraveTorClientUpdater;
}

Expand Down Expand Up @@ -100,7 +100,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
brave_shields::HTTPSEverywhereService* https_everywhere_service();
brave_component_updater::LocalDataFilesService* local_data_files_service();
#if BUILDFLAG(ENABLE_TOR)
extensions::BraveTorClientUpdater* tor_client_updater();
tor::BraveTorClientUpdater* tor_client_updater();
#endif
#if BUILDFLAG(IPFS_ENABLED)
ipfs::BraveIpfsClientUpdater* ipfs_client_updater();
Expand Down Expand Up @@ -160,7 +160,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
std::unique_ptr<brave::BraveReferralsService> brave_referrals_service_;
#endif
#if BUILDFLAG(ENABLE_TOR)
std::unique_ptr<extensions::BraveTorClientUpdater> tor_client_updater_;
std::unique_ptr<tor::BraveTorClientUpdater> tor_client_updater_;
#endif
#if BUILDFLAG(IPFS_ENABLED)
std::unique_ptr<ipfs::BraveIpfsClientUpdater> ipfs_client_updater_;
Expand Down
28 changes: 20 additions & 8 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
#include "base/task/post_task.h"
#include "brave/browser/brave_browser_main_extra_parts.h"
#include "brave/browser/brave_browser_process_impl.h"
#include "brave/browser/extensions/brave_tor_client_updater.h"
#include "brave/browser/net/brave_proxying_url_loader_factory.h"
#include "brave/browser/net/brave_proxying_web_socket.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/common/webui_url_constants.h"
#include "brave/components/binance/browser/buildflags/buildflags.h"
Expand All @@ -35,6 +33,7 @@
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/ipfs/features.h"
#include "brave/components/speedreader/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -85,8 +84,10 @@ using extensions::ChromeContentBrowserClientExtensionsPart;
#endif

#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/tor/onion_location_navigation_throttle.h"
#include "brave/browser/tor/tor_navigation_throttle.h"
#include "brave/browser/tor/onion_location_navigation_throttle_delegate.h"
#include "brave/browser/tor/tor_profile_service_factory.h"
#include "brave/components/tor/onion_location_navigation_throttle.h"
#include "brave/components/tor/tor_navigation_throttle.h"
#endif

#if BUILDFLAG(ENABLE_SPEEDREADER)
Expand Down Expand Up @@ -459,21 +460,32 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
std::make_unique<extensions::BraveWebTorrentNavigationThrottle>(handle));
#endif

#if BUILDFLAG(ENABLE_TOR) ||BUILDFLAG(IPFS_ENABLED)
content::BrowserContext* context =
handle->GetWebContents()->GetBrowserContext();
#endif

#if BUILDFLAG(ENABLE_TOR)
std::unique_ptr<content::NavigationThrottle> tor_navigation_throttle =
tor::TorNavigationThrottle::MaybeCreateThrottleFor(handle);
tor::TorNavigationThrottle::MaybeCreateThrottleFor(handle,
TorProfileServiceFactory::GetForContext(context),
brave::IsTorProfile(context));
if (tor_navigation_throttle)
throttles.push_back(std::move(tor_navigation_throttle));
std::unique_ptr<tor::OnionLocationNavigationThrottleDelegate>
onion_location_navigation_throttle_delegate =
std::make_unique<tor::OnionLocationNavigationThrottleDelegate>();
std::unique_ptr<content::NavigationThrottle>
onion_location_navigation_throttle =
tor::OnionLocationNavigationThrottle::MaybeCreateThrottleFor(handle);
tor::OnionLocationNavigationThrottle::MaybeCreateThrottleFor(
handle, TorProfileServiceFactory::IsTorDisabled(),
std::move(onion_location_navigation_throttle_delegate),
brave::IsTorProfile(context));
if (onion_location_navigation_throttle)
throttles.push_back(std::move(onion_location_navigation_throttle));
#endif

#if BUILDFLAG(IPFS_ENABLED)
content::BrowserContext* context =
handle->GetWebContents()->GetBrowserContext();
std::unique_ptr<content::NavigationThrottle> ipfs_navigation_throttle =
ipfs::IpfsNavigationThrottle::MaybeCreateThrottleFor(handle,
ipfs::IpfsServiceFactory::GetForContext(context),
Expand Down
4 changes: 2 additions & 2 deletions browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include "brave/browser/brave_stats/brave_stats_updater.h"
#include "brave/browser/metrics/metrics_reporting_util.h"
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_referrals/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_service.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/metrics_pref_names.h"
Expand All @@ -28,7 +28,7 @@
#endif

#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/tor/tor_profile_service.h"
#include "brave/components/tor/tor_profile_service.h"
#endif

#if !defined(OS_ANDROID)
Expand Down
4 changes: 2 additions & 2 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "brave/browser/search/ntp_utils.h"
#include "brave/browser/themes/brave_dark_mode_utils.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/browser/ui/omnibox/brave_omnibox_client_impl.h"
#include "brave/common/pref_names.h"
#include "brave/components/binance/browser/buildflags/buildflags.h"
Expand All @@ -24,6 +23,7 @@
#include "brave/components/crypto_dot_com/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/speedreader/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/common/pref_names.h"
Expand Down Expand Up @@ -89,7 +89,7 @@
#endif

#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/tor/tor_profile_service.h"
#include "brave/components/tor/tor_profile_service.h"
#endif

#if defined(OS_ANDROID)
Expand Down
10 changes: 6 additions & 4 deletions browser/brave_tab_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "base/feature_list.h"
#include "brave/browser/brave_stats/brave_stats_tab_helper.h"
#include "brave/browser/farbling/farbling_tab_helper.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/ui/bookmark/brave_bookmark_tab_helper.h"
#include "brave/components/brave_ads/browser/ads_tab_helper.h"
#include "brave/components/brave_perf_predictor/browser/buildflags.h"
Expand All @@ -20,6 +20,7 @@
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/speedreader/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "content/public/browser/web_contents.h"
#include "third_party/widevine/cdm/buildflags.h"

Expand Down Expand Up @@ -59,8 +60,8 @@
#endif

#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/tor/tor_tab_helper.h"
#include "brave/browser/tor/onion_location_tab_helper.h"
#include "brave/components/tor/onion_location_tab_helper.h"
#include "brave/components/tor/tor_tab_helper.h"
#endif

#if BUILDFLAG(IPFS_ENABLED)
Expand Down Expand Up @@ -118,7 +119,8 @@ void AttachTabHelpers(content::WebContents* web_contents) {
#endif

#if BUILDFLAG(ENABLE_TOR)
tor::TorTabHelper::MaybeCreateForWebContents(web_contents);
tor::TorTabHelper::MaybeCreateForWebContents(
web_contents, brave::IsTorProfile(web_contents->GetBrowserContext()));
tor::OnionLocationTabHelper::CreateForWebContents(web_contents);
#endif

Expand Down
16 changes: 11 additions & 5 deletions browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

#include "brave/browser/browser_context_keyed_service_factories.h"

#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/browser/brave_shields/ad_block_pref_service_factory.h"
#include "brave/browser/brave_shields/cookie_pref_service_factory.h"
#include "brave/browser/ntp_background_images/view_counter_service_factory.h"
#include "brave/browser/search_engines/search_engine_provider_service_factory.h"
#include "brave/browser/search_engines/search_engine_tracker.h"
#include "brave/browser/tor/tor_profile_service_factory.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/browser/ntp_background_images/view_counter_service_factory.h"
#include "brave/components/brave_wallet/buildflags/buildflags.h"
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"

#if BUILDFLAG(ENABLE_GREASELION)
#include "brave/browser/greaselion/greaselion_service_factory.h"
Expand All @@ -35,6 +35,10 @@
#include "brave/browser/ipfs/ipfs_service_factory.h"
#endif

#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/tor/tor_profile_service_factory.h"
#endif

namespace brave {

void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
Expand All @@ -45,7 +49,9 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
#if BUILDFLAG(ENABLE_GREASELION)
greaselion::GreaselionServiceFactory::GetInstance();
#endif
#if BUILDFLAG(ENABLE_TOR)
TorProfileServiceFactory::GetInstance();
#endif
SearchEngineProviderServiceFactory::GetInstance();
SearchEngineTrackerFactory::GetInstance();
ntp_background_images::ViewCounterServiceFactory::GetInstance();
Expand Down
4 changes: 2 additions & 2 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/components/binance/browser/buildflags/buildflags.gni")
import("//brave/components/gemini/browser/buildflags/buildflags.gni")
import("//brave/components/crypto_dot_com/browser/buildflags/buildflags.gni")
Expand All @@ -9,6 +8,7 @@ import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni")
import("//brave/components/brave_together/buildflags/buildflags.gni")
import("//brave/components/ipfs/buildflags/buildflags.gni")
import("//brave/components/moonpay/browser/buildflags/buildflags.gni")
import("//brave/components/tor/buildflags/buildflags.gni")
import("//build/config/features.gni")
import("//components/gcm_driver/config.gni")

Expand Down Expand Up @@ -55,7 +55,6 @@ source_set("extensions") {
"//base",
"//brave/app:brave_generated_resources_grit",
"//brave/browser/profiles",
"//brave/browser/tor:buildflags",
"//brave/browser/webcompat_reporter",
"//brave/common",
"//brave/common:pref_names",
Expand All @@ -66,6 +65,7 @@ source_set("extensions") {
"//brave/components/brave_shields/common",
"//brave/components/brave_wayback_machine:buildflags",
"//brave/components/ipfs/buildflags",
"//brave/components/tor/buildflags",
"//chrome/browser/extensions",
"//chrome/common",
"//components/gcm_driver:gcm_driver",
Expand Down
Loading