forked from breach/thrust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stanislas Polu
committed
Dec 1, 2014
1 parent
8f5bedb
commit c21cade
Showing
9 changed files
with
228 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/browser/session/thrust_session_proxy_config_service.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Copyright (c) 2014 Stanislas Polu. | ||
// See the LICENSE file. | ||
|
||
#include "src/browser/session/thrust_session_proxy_config_service.h" | ||
|
||
#include "net/proxy/proxy_service.h" | ||
#include "net/proxy/proxy_config_service_fixed.h" | ||
#include "content/public/browser/browser_thread.h" | ||
|
||
#include "src/browser/session/thrust_session.h" | ||
|
||
using namespace content; | ||
|
||
namespace thrust_shell { | ||
|
||
ThrustSessionProxyConfigService::ThrustSessionProxyConfigService( | ||
ThrustSession* parent) | ||
: parent_(parent) | ||
{ | ||
LOG(INFO) << "ThrustSesionProxyConfigService Constructor: " << this; | ||
|
||
system_service_.reset( | ||
net::ProxyService::CreateSystemProxyConfigService( | ||
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) | ||
->message_loop_proxy().get(), | ||
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE))); | ||
fixed_service_.reset(); | ||
} | ||
|
||
ThrustSessionProxyConfigService::~ThrustSessionProxyConfigService() | ||
{ | ||
/* We nullify the proxy service in parent to prevent erroneous access */ | ||
/* after it gets reclaimed. */ | ||
parent_->proxy_config_service_ = NULL; | ||
|
||
LOG(INFO) << "ThrustSesionProxyConfigService Destructor: " << this; | ||
} | ||
|
||
/******************************************************************************/ | ||
/* PUBLIC API */ | ||
/******************************************************************************/ | ||
void | ||
ThrustSessionProxyConfigService::SetProxyRules( | ||
std::string& proxy_string) | ||
{ | ||
net::ProxyConfig proxy_config; | ||
proxy_config.proxy_rules().ParseFromString(proxy_string); | ||
fixed_service_.reset(new net::ProxyConfigServiceFixed(proxy_config)); | ||
|
||
LOG(INFO) << "ThrustSesionProxyConfigService SetProxyRules: " << proxy_string; | ||
|
||
if(observers_.might_have_observers()) { | ||
ObserverList<Observer>::Iterator it(observers_); | ||
Observer* obs; | ||
while((obs = it.GetNext()) != NULL) { | ||
fixed_service_->AddObserver(obs); | ||
} | ||
} | ||
FOR_EACH_OBSERVER(Observer, observers_, | ||
OnProxyConfigChanged(proxy_config, CONFIG_VALID)); | ||
} | ||
|
||
void | ||
ThrustSessionProxyConfigService::ClearProxyRules() | ||
{ | ||
fixed_service_.reset(); | ||
|
||
net::ProxyConfig proxy_config; | ||
net::ProxyConfigService::ConfigAvailability avail = | ||
this->GetLatestProxyConfig(&proxy_config); | ||
|
||
FOR_EACH_OBSERVER(Observer, observers_, | ||
OnProxyConfigChanged(proxy_config, avail)); | ||
} | ||
|
||
/******************************************************************************/ | ||
/* PROXY CONFIG SERVICE IMPLEMENTATION */ | ||
/******************************************************************************/ | ||
void | ||
ThrustSessionProxyConfigService::AddObserver( | ||
Observer* observer) | ||
{ | ||
observers_.AddObserver(observer); | ||
if(fixed_service_.get()) { | ||
fixed_service_->AddObserver(observer); | ||
} | ||
system_service_->AddObserver(observer); | ||
} | ||
|
||
void | ||
ThrustSessionProxyConfigService::RemoveObserver( | ||
Observer* observer) | ||
{ | ||
observers_.RemoveObserver(observer); | ||
if(fixed_service_.get()) { | ||
fixed_service_->RemoveObserver(observer); | ||
} | ||
system_service_->RemoveObserver(observer); | ||
} | ||
|
||
net::ProxyConfigService::ConfigAvailability | ||
ThrustSessionProxyConfigService::GetLatestProxyConfig( | ||
net::ProxyConfig* config) | ||
{ | ||
if(fixed_service_.get()) { | ||
return fixed_service_->GetLatestProxyConfig(config); | ||
} | ||
return system_service_->GetLatestProxyConfig(config); | ||
} | ||
|
||
void | ||
ThrustSessionProxyConfigService::OnLazyPoll() | ||
{ | ||
if(fixed_service_.get()) { | ||
fixed_service_->OnLazyPoll(); | ||
} | ||
system_service_->OnLazyPoll(); | ||
} | ||
|
||
} // namespace thrust_shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2014 Stanislas Polu. | ||
// See the LICENSE file. | ||
|
||
#ifndef THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_PROXY_CONFIG_SERVICE_H_ | ||
#define THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_PROXY_CONFIG_SERVICE_H_ | ||
|
||
#include "base/memory/scoped_ptr.h" | ||
#include "base/observer_list.h" | ||
#include "net/proxy/proxy_config_service.h" | ||
|
||
namespace thrust_shell { | ||
|
||
class ThrustSession; | ||
|
||
// ### ThrustSessionProxyConfigService | ||
// | ||
// The ThrustSessionProxyConfigService is the glue between the system proxy | ||
// service and custom proxy rules set by the user for a given thrust_session. | ||
// This proxy service is passed as argument to the | ||
// ThrustShellURLRequestContextGetter to manage all proxy information. | ||
// | ||
// The ProxyConfigService expose two simple methods SetProxyString and | ||
// ClearProxyString to set or clear (return to system settings) the proxy rules | ||
// for all requests made for this session | ||
class ThrustSessionProxyConfigService : public net::ProxyConfigService { | ||
public: | ||
// ### THrustSessionProxyConfigService | ||
ThrustSessionProxyConfigService(ThrustSession* parent); | ||
~ThrustSessionProxyConfigService(); | ||
|
||
/****************************************************************************/ | ||
/* PUBLIC API */ | ||
/****************************************************************************/ | ||
void SetProxyRules(std::string& rules); | ||
void ClearProxyRules(); | ||
|
||
/****************************************************************************/ | ||
/* PROXY CONFIG SERVICE IMPLEMENTATION */ | ||
/****************************************************************************/ | ||
virtual void AddObserver(Observer* observer) OVERRIDE; | ||
virtual void RemoveObserver(Observer* observer) OVERRIDE; | ||
|
||
virtual ConfigAvailability GetLatestProxyConfig( | ||
net::ProxyConfig* config) OVERRIDE; | ||
virtual void OnLazyPoll() OVERRIDE; | ||
|
||
private: | ||
ThrustSession* parent_; | ||
|
||
ObserverList<Observer> observers_; | ||
scoped_ptr<net::ProxyConfigService> system_service_; | ||
scoped_ptr<net::ProxyConfigService> fixed_service_; | ||
|
||
friend class ThrustSession; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ThrustSessionProxyConfigService); | ||
}; | ||
|
||
} // namespace thrust_shell | ||
|
||
#endif // THRUST_SHELL_BROWSER_SESSION_THRUST_SESSION_PROXY_CONFIG_SERVICE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.