Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Launch tor when tor browser context created and terminated it during
Browse files Browse the repository at this point in the history
context destruction
  • Loading branch information
darkdh committed Feb 16, 2018
1 parent 75c8277 commit f2df25a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions brave/browser/brave_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/path_service.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/process/launch.h"
#include "base/trace_event/trace_event.h"
#include "brave/browser/brave_permission_manager.h"
#include "brave/browser/net/proxy/proxy_config_service_tor.h"
Expand Down Expand Up @@ -179,6 +180,11 @@ BraveBrowserContext::BraveBrowserContext(
std::string tor_proxy;
if (options.GetString("tor_proxy", &tor_proxy)) {
tor_proxy_ = GURL(tor_proxy);
if (!tor_process_.IsValid()) {
base::FilePath tor("/usr/local/bin/tor");
base::CommandLine cmdline(tor);
tor_process_ = base::LaunchProcess(cmdline, base::LaunchOptions());
}
}

if (in_memory) {
Expand All @@ -204,6 +210,10 @@ BraveBrowserContext::BraveBrowserContext(
BraveBrowserContext::~BraveBrowserContext() {
MaybeSendDestroyedNotification();

if (tor_process_.IsValid()) {
base::EnsureProcessTerminated(std::move(tor_process_));
}

if (track_zoom_subscription_.get())
track_zoom_subscription_.reset(nullptr);

Expand Down
1 change: 1 addition & 0 deletions brave/browser/brave_browser_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class BraveBrowserContext : public Profile {
bool isolated_storage_;
GURL tor_proxy_;
bool in_memory_;
base::Process tor_process_;

URLRequestContextGetterMap url_request_context_getter_map_;

Expand Down
6 changes: 5 additions & 1 deletion chromium_src/chrome/browser/profiles/profile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h"
#include "brave/browser/brave_browser_context.h"
#include "build/build_config.h"
#include "atom/browser/atom_browser_context.h"
#include "chrome/browser/browser_process.h"
Expand Down Expand Up @@ -82,7 +83,10 @@ void ProfileManager::OnProfileCreated(Profile* profile,
bool success,
bool is_new_profile) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!profile->IsOffTheRecord() &&
auto brave_browser_context =
brave::BraveBrowserContext::FromBrowserContext(profile);
if ((!profile->IsOffTheRecord() ||
brave_browser_context->IsIsolatedStorage())&&
!GetProfileByPath(profile->GetPath())) {
AddProfile(profile);
}
Expand Down

0 comments on commit f2df25a

Please sign in to comment.