diff --git a/components/tor/tor_launcher_factory.cc b/components/tor/tor_launcher_factory.cc index 0c0a53544c99..8811cf17efa4 100644 --- a/components/tor/tor_launcher_factory.cc +++ b/components/tor/tor_launcher_factory.cc @@ -218,6 +218,7 @@ void TorLauncherFactory::GotSOCKSListeners( tor_proxy_uri.erase( std::remove(tor_proxy_uri.begin(), tor_proxy_uri.end(), '\"'), tor_proxy_uri.end()); + tor_proxy_uri_ = tor_proxy_uri; for (auto& observer : observers_) observer.NotifyTorNewProxyURI(tor_proxy_uri); } diff --git a/components/tor/tor_launcher_factory.h b/components/tor/tor_launcher_factory.h index a77295237e44..d664e2ca2ebe 100644 --- a/components/tor/tor_launcher_factory.h +++ b/components/tor/tor_launcher_factory.h @@ -31,6 +31,7 @@ class TorLauncherFactory : public tor::TorControl::Delegate { void KillTorProcess(); int64_t GetTorPid() const { return tor_pid_; } bool IsTorConnected() const { return is_connected_; } + std::string GetTorProxyURI() const { return tor_proxy_uri_; } void AddObserver(tor::TorProfileServiceImpl* serice); void RemoveObserver(tor::TorProfileServiceImpl* service); @@ -72,6 +73,8 @@ class TorLauncherFactory : public tor::TorControl::Delegate { mojo::Remote tor_launcher_; + std::string tor_proxy_uri_; + int64_t tor_pid_; tor::mojom::TorConfig config_; diff --git a/components/tor/tor_profile_service_impl.cc b/components/tor/tor_profile_service_impl.cc index 62a52312fcc3..c75f35bad712 100644 --- a/components/tor/tor_profile_service_impl.cc +++ b/components/tor/tor_profile_service_impl.cc @@ -251,7 +251,17 @@ void TorProfileServiceImpl::NotifyTorInitializing( std::unique_ptr TorProfileServiceImpl::CreateProxyConfigService() { - proxy_config_service_ = new net::ProxyConfigServiceTor(); + // First tor profile will have empty proxy uri but it will receive update from + // NotifyTorNewProxyURI. And subsequent tor profile might not have + // NotifyTorNewProxyURI because it is called once when tor control is ready. + const std::string tor_proxy_uri = tor_launcher_factory_->GetTorProxyURI(); + if (tor_proxy_uri.empty()) { + proxy_config_service_ = + new net::ProxyConfigServiceTor(); + } else { + proxy_config_service_ = + new net::ProxyConfigServiceTor(tor_proxy_uri); + } return std::unique_ptr(proxy_config_service_); }