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..c3431b2ac763ecb95bf167ef67c4dd924bf22053 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|. |
-class ProtocolHandlerRegistry::URLInterceptor |
- : public net::URLRequestJobFactory::Interceptor { |
- public: |
- explicit URLInterceptor(Core* core); |
- virtual ~URLInterceptor(); |
+// requests via |ProtocolHandlerRegistry::CreateURLRequestJobFactory|. |
+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( |
mmenke
2013/01/03 15:45:11
Hmm...Wonder if this capability should be added to
pauljensen
2013/01/03 18:43:51
ProtocolHandlerRegistry::Interceptor and Developer
mmenke
2013/01/03 18:49:37
SGTM
|
+ 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_)); |
} |