Chromium Code Reviews| Index: chrome/browser/custom_handlers/protocol_handler_registry.cc |
| diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.cc b/chrome/browser/custom_handlers/protocol_handler_registry.cc |
| index bab8c445560eba9b7b4e95bf914fa86c8dd9299c..cab49edf7f5a992d2ff9d3c55e901d6949fd3e96 100644 |
| --- a/chrome/browser/custom_handlers/protocol_handler_registry.cc |
| +++ b/chrome/browser/custom_handlers/protocol_handler_registry.cc |
| @@ -155,62 +155,79 @@ net::URLRequestJob* ProtocolHandlerRegistry::Core::MaybeCreateJob( |
| net::URLRequestRedirectJob::REDIRECT_302_FOUND); |
| } |
| -// URLInterceptor ------------------------------------------------------------ |
| +// JobFactory ----------------------------------------------------------------- |
| -// Instances of this class are produced for ownership by the IO |
| +// Instances of JobFactory are produced for ownership by the IO |
| // thread where it handler URL requests. We should never hold |
| // any pointers on this class, only produce them in response to |
| // requests via |ProtocolHandlerRegistry::CreateURLInterceptor|. |
|
erikwright (departed)
2013/01/02 16:29:36
Update name of CreateURLInterceptor
|
| -class ProtocolHandlerRegistry::URLInterceptor |
| - : public net::URLRequestJobFactory::Interceptor { |
| - public: |
| - explicit URLInterceptor(Core* core); |
| - virtual ~URLInterceptor(); |
| +ProtocolHandlerRegistry::JobFactory::JobFactory(Core* core) |
| + : core_(core) { |
| + DCHECK(core_); |
| + DetachFromThread(); |
| +} |
| - virtual net::URLRequestJob* MaybeIntercept( |
| - net::URLRequest* request, |
| - net::NetworkDelegate* network_delegate) const OVERRIDE; |
| +ProtocolHandlerRegistry::JobFactory::~JobFactory() { |
| +} |
| - virtual bool WillHandleProtocol(const std::string& protocol) const OVERRIDE; |
| +void ProtocolHandlerRegistry::JobFactory::Chain( |
| + scoped_ptr<net::URLRequestJobFactory> job_factory) { |
| + job_factory_ = job_factory.Pass(); |
| +} |
| - virtual net::URLRequestJob* MaybeInterceptRedirect( |
| - const GURL& url, |
| - net::URLRequest* request, |
| - net::NetworkDelegate* network_delegate) const OVERRIDE { |
| - return NULL; |
| - } |
| +bool ProtocolHandlerRegistry::JobFactory::SetProtocolHandler( |
| + const std::string& scheme, ProtocolHandler* protocol_handler) { |
| + return job_factory_->SetProtocolHandler(scheme, protocol_handler); |
| +} |
| - virtual net::URLRequestJob* MaybeInterceptResponse( |
| - net::URLRequest* request, |
| - net::NetworkDelegate* network_delegate) const OVERRIDE { |
| - return NULL; |
| - } |
| +void ProtocolHandlerRegistry::JobFactory::AddInterceptor( |
| + Interceptor* interceptor) { |
| + return job_factory_->AddInterceptor(interceptor); |
| +} |
| - private: |
| - scoped_refptr<Core> core_; |
| - DISALLOW_COPY_AND_ASSIGN(URLInterceptor); |
| -}; |
| +net::URLRequestJob* |
| +ProtocolHandlerRegistry::JobFactory::MaybeCreateJobWithInterceptor( |
| + net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| + return job_factory_->MaybeCreateJobWithInterceptor(request, network_delegate); |
| +} |
| -ProtocolHandlerRegistry::URLInterceptor::URLInterceptor(Core* core) |
| - : core_(core) { |
| - DCHECK(core_); |
| +net::URLRequestJob* |
| +ProtocolHandlerRegistry::JobFactory::MaybeCreateJobWithProtocolHandler( |
| + const std::string& scheme, |
| + net::URLRequest* request, |
| + net::NetworkDelegate* network_delegate) const { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + net::URLRequestJob* job = core_->MaybeCreateJob(request, network_delegate); |
| + if (job) |
| + return job; |
| + return job_factory_->MaybeCreateJobWithProtocolHandler( |
| + scheme, request, network_delegate); |
| } |
| -ProtocolHandlerRegistry::URLInterceptor::~URLInterceptor() { |
| +net::URLRequestJob* ProtocolHandlerRegistry::JobFactory::MaybeInterceptRedirect( |
| + const GURL& location, |
| + net::URLRequest* request, |
| + net::NetworkDelegate* network_delegate) const { |
| + return job_factory_->MaybeInterceptRedirect( |
| + location, request, network_delegate); |
| } |
| -net::URLRequestJob* ProtocolHandlerRegistry::URLInterceptor::MaybeIntercept( |
| +net::URLRequestJob* ProtocolHandlerRegistry::JobFactory::MaybeInterceptResponse( |
| net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - |
| - return core_->MaybeCreateJob(request, network_delegate); |
| + return job_factory_->MaybeInterceptResponse(request, network_delegate); |
| } |
| -bool ProtocolHandlerRegistry::URLInterceptor::WillHandleProtocol( |
| - const std::string& protocol) const { |
| +bool ProtocolHandlerRegistry::JobFactory::IsHandledProtocol( |
| + const std::string& scheme) const { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + return core_->IsHandledProtocol(scheme) || |
| + job_factory_->IsHandledProtocol(scheme); |
| +} |
| - return core_->IsHandledProtocol(protocol); |
| +bool ProtocolHandlerRegistry::JobFactory::IsHandledURL(const GURL& url) const { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + return (url.is_valid() && core_->IsHandledProtocol(url.scheme())) || |
| + job_factory_->IsHandledURL(url); |
| } |
| // DefaultClientObserver ------------------------------------------------------ |
| @@ -875,11 +892,11 @@ void ProtocolHandlerRegistry::AddPredefinedHandler( |
| SetDefault(handler); |
| } |
| -net::URLRequestJobFactory::Interceptor* |
| - ProtocolHandlerRegistry::CreateURLInterceptor() { |
| +scoped_ptr<ProtocolHandlerRegistry::JobFactory> |
| +ProtocolHandlerRegistry::CreateURLRequestJobFactory() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| // this is always created on the UI thread (in profile_io's |
| // InitializeOnUIThread. Any method calls must be done |
| // on the IO thread (this is checked). |
| - return new URLInterceptor(core_); |
| + return scoped_ptr<JobFactory>(new JobFactory(core_)); |
| } |