Remove unused pieces of URLRequestJobFactory API.

This is mostly the Interceptor logic which is now unused.
Also switch DebugDevToolsInterceptor (the last remaining
Interceptor) to a ProtocolHandler.

BUG=146602,161529

Review URL: https://chromiumcodereview.appspot.com/12217095

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182016 0039d316-1c4b-4281-b951-d872f2087c98
parent d9e19bf4
...@@ -63,28 +63,4 @@ bool AwURLRequestJobFactory::SetProtocolHandler( ...@@ -63,28 +63,4 @@ bool AwURLRequestJobFactory::SetProtocolHandler(
return next_factory_->SetProtocolHandler(scheme, protocol_handler); return next_factory_->SetProtocolHandler(scheme, protocol_handler);
} }
void AwURLRequestJobFactory::AddInterceptor(Interceptor* interceptor) {
next_factory_->AddInterceptor(interceptor);
}
URLRequestJob* AwURLRequestJobFactory::MaybeCreateJobWithInterceptor(
URLRequest* request, NetworkDelegate* network_delegate) const {
return next_factory_->MaybeCreateJobWithInterceptor(
request, network_delegate);
}
URLRequestJob* AwURLRequestJobFactory::MaybeInterceptRedirect(
const GURL& location,
URLRequest* request,
NetworkDelegate* network_delegate) const {
return next_factory_->MaybeInterceptRedirect(
location, request, network_delegate);
}
URLRequestJob* AwURLRequestJobFactory::MaybeInterceptResponse(
URLRequest* request,
NetworkDelegate* network_delegate) const {
return next_factory_->MaybeInterceptResponse(request, network_delegate);
}
} // namespace android_webview } // namespace android_webview
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "net/url_request/url_request_job_factory.h" #include "net/url_request/url_request_job_factory.h"
namespace net {
class URLRequestJobFactoryImpl;
} // namespace net
namespace android_webview { namespace android_webview {
// android_webview uses a custom URLRequestJobFactoryImpl to support // android_webview uses a custom URLRequestJobFactoryImpl to support
...@@ -21,30 +25,21 @@ class AwURLRequestJobFactory : public net::URLRequestJobFactory { ...@@ -21,30 +25,21 @@ class AwURLRequestJobFactory : public net::URLRequestJobFactory {
AwURLRequestJobFactory(); AwURLRequestJobFactory();
virtual ~AwURLRequestJobFactory(); virtual ~AwURLRequestJobFactory();
virtual bool SetProtocolHandler(const std::string& scheme, bool SetProtocolHandler(const std::string& scheme,
ProtocolHandler* protocol_handler) OVERRIDE; ProtocolHandler* protocol_handler);
virtual void AddInterceptor(Interceptor* interceptor) OVERRIDE;
virtual net::URLRequestJob* MaybeCreateJobWithInterceptor( // net::URLRequestJobFactory implementation.
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
const std::string& scheme, const std::string& scheme,
net::URLRequest* request, net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE; net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual net::URLRequestJob* MaybeInterceptRedirect(
const GURL& location,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual net::URLRequestJob* MaybeInterceptResponse(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE; virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE;
virtual bool IsHandledURL(const GURL& url) const OVERRIDE; virtual bool IsHandledURL(const GURL& url) const OVERRIDE;
private: private:
// By default calls are forwarded to this factory, to avoid having to // By default calls are forwarded to this factory, to avoid having to
// subclass an existing implementation class. // subclass an existing implementation class.
scoped_ptr<URLRequestJobFactory> next_factory_; scoped_ptr<net::URLRequestJobFactoryImpl> next_factory_;
DISALLOW_COPY_AND_ASSIGN(AwURLRequestJobFactory); DISALLOW_COPY_AND_ASSIGN(AwURLRequestJobFactory);
}; };
......
...@@ -175,22 +175,6 @@ void ProtocolHandlerRegistry::JobInterceptorFactory::Chain( ...@@ -175,22 +175,6 @@ void ProtocolHandlerRegistry::JobInterceptorFactory::Chain(
job_factory_ = job_factory.Pass(); job_factory_ = job_factory.Pass();
} }
bool ProtocolHandlerRegistry::JobInterceptorFactory::SetProtocolHandler(
const std::string& scheme, ProtocolHandler* protocol_handler) {
return job_factory_->SetProtocolHandler(scheme, protocol_handler);
}
void ProtocolHandlerRegistry::JobInterceptorFactory::AddInterceptor(
Interceptor* interceptor) {
return job_factory_->AddInterceptor(interceptor);
}
net::URLRequestJob*
ProtocolHandlerRegistry::JobInterceptorFactory::MaybeCreateJobWithInterceptor(
net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
return job_factory_->MaybeCreateJobWithInterceptor(request, network_delegate);
}
net::URLRequestJob* net::URLRequestJob*
ProtocolHandlerRegistry::JobInterceptorFactory:: ProtocolHandlerRegistry::JobInterceptorFactory::
MaybeCreateJobWithProtocolHandler( MaybeCreateJobWithProtocolHandler(
...@@ -206,21 +190,6 @@ MaybeCreateJobWithProtocolHandler( ...@@ -206,21 +190,6 @@ MaybeCreateJobWithProtocolHandler(
scheme, request, network_delegate); scheme, request, network_delegate);
} }
net::URLRequestJob*
ProtocolHandlerRegistry::JobInterceptorFactory::MaybeInterceptRedirect(
const GURL& location,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const {
return job_factory_->MaybeInterceptRedirect(
location, request, network_delegate);
}
net::URLRequestJob*
ProtocolHandlerRegistry::JobInterceptorFactory::MaybeInterceptResponse(
net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
return job_factory_->MaybeInterceptResponse(request, network_delegate);
}
bool ProtocolHandlerRegistry::JobInterceptorFactory::IsHandledProtocol( bool ProtocolHandlerRegistry::JobInterceptorFactory::IsHandledProtocol(
const std::string& scheme) const { const std::string& scheme) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
......
...@@ -106,23 +106,10 @@ class ProtocolHandlerRegistry : public ProfileKeyedService { ...@@ -106,23 +106,10 @@ class ProtocolHandlerRegistry : public ProfileKeyedService {
void Chain(scoped_ptr<net::URLRequestJobFactory> job_factory); void Chain(scoped_ptr<net::URLRequestJobFactory> job_factory);
// URLRequestJobFactory implementation. // URLRequestJobFactory implementation.
virtual bool SetProtocolHandler(const std::string& scheme,
ProtocolHandler* protocol_handler) OVERRIDE;
virtual void AddInterceptor(Interceptor* interceptor) OVERRIDE;
virtual net::URLRequestJob* MaybeCreateJobWithInterceptor(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
const std::string& scheme, const std::string& scheme,
net::URLRequest* request, net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE; net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual net::URLRequestJob* MaybeInterceptRedirect(
const GURL& location,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual net::URLRequestJob* MaybeInterceptResponse(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE;
virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE; virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE;
virtual bool IsHandledURL(const GURL& url) const OVERRIDE; virtual bool IsHandledURL(const GURL& url) const OVERRIDE;
......
...@@ -60,34 +60,12 @@ void AssertIntercepted( ...@@ -60,34 +60,12 @@ void AssertIntercepted(
// ProtocolHandlerRegistry properly handled a job creation request. // ProtocolHandlerRegistry properly handled a job creation request.
class FakeURLRequestJobFactory : public net::URLRequestJobFactory { class FakeURLRequestJobFactory : public net::URLRequestJobFactory {
// net::URLRequestJobFactory implementation: // net::URLRequestJobFactory implementation:
virtual bool SetProtocolHandler(const std::string& scheme,
ProtocolHandler* protocol_handler) OVERRIDE {
return false;
}
virtual void AddInterceptor(Interceptor* interceptor) OVERRIDE {
}
virtual net::URLRequestJob* MaybeCreateJobWithInterceptor(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
return NULL;
}
virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler( virtual net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
const std::string& scheme, const std::string& scheme,
net::URLRequest* request, net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE { net::NetworkDelegate* network_delegate) const OVERRIDE {
return NULL; return NULL;
} }
virtual net::URLRequestJob* MaybeInterceptRedirect(
const GURL& location,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
return NULL;
}
virtual net::URLRequestJob* MaybeInterceptResponse(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
return NULL;
}
virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE { virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE {
return false; return false;
} }
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
#include "net/url_request/data_protocol_handler.h" #include "net/url_request/data_protocol_handler.h"
#include "net/url_request/file_protocol_handler.h" #include "net/url_request/file_protocol_handler.h"
#include "net/url_request/ftp_protocol_handler.h" #include "net/url_request/ftp_protocol_handler.h"
#include "net/url_request/protocol_intercept_job_factory.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#include "net/url_request/url_request_file_job.h" #include "net/url_request/url_request_file_job.h"
#include "net/url_request/url_request_job_factory_impl.h" #include "net/url_request/url_request_job_factory_impl.h"
...@@ -189,12 +190,13 @@ bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) { ...@@ -189,12 +190,13 @@ bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) {
return true; return true;
} }
class DebugDevToolsInterceptor : public net::URLRequestJobFactory::Interceptor { class DebugDevToolsInterceptor
: public net::URLRequestJobFactory::ProtocolHandler {
public: public:
DebugDevToolsInterceptor() {} DebugDevToolsInterceptor() {}
virtual ~DebugDevToolsInterceptor() {} virtual ~DebugDevToolsInterceptor() {}
virtual net::URLRequestJob* MaybeIntercept( virtual net::URLRequestJob* MaybeCreateJob(
net::URLRequest* request, net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE { net::NetworkDelegate* network_delegate) const OVERRIDE {
base::FilePath path; base::FilePath path;
...@@ -203,23 +205,6 @@ class DebugDevToolsInterceptor : public net::URLRequestJobFactory::Interceptor { ...@@ -203,23 +205,6 @@ class DebugDevToolsInterceptor : public net::URLRequestJobFactory::Interceptor {
return NULL; return NULL;
} }
virtual net::URLRequestJob* MaybeInterceptRedirect(
const GURL& location,
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
return NULL;
}
virtual net::URLRequestJob* MaybeInterceptResponse(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
return NULL;
}
virtual bool WillHandleProtocol(const std::string& protocol) const {
return protocol == chrome::kChromeDevToolsScheme;
}
}; };
#endif // defined(DEBUG_DEVTOOLS) #endif // defined(DEBUG_DEVTOOLS)
...@@ -766,16 +751,20 @@ scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults( ...@@ -766,16 +751,20 @@ scoped_ptr<net::URLRequestJobFactory> ProfileIOData::SetUpJobFactoryDefaults(
ftp_auth_cache)); ftp_auth_cache));
#endif // !defined(DISABLE_FTP_SUPPORT) #endif // !defined(DISABLE_FTP_SUPPORT)
scoped_ptr<net::URLRequestJobFactory> top_job_factory =
job_factory.PassAs<net::URLRequestJobFactory>();
#if defined(DEBUG_DEVTOOLS) #if defined(DEBUG_DEVTOOLS)
job_factory->AddInterceptor(new DebugDevToolsInterceptor()); top_job_factory.reset(new net::ProtocolInterceptJobFactory(
top_job_factory.Pass(),
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(
new DebugDevToolsInterceptor)));
#endif #endif
if (protocol_handler_interceptor) { if (protocol_handler_interceptor) {
protocol_handler_interceptor->Chain( protocol_handler_interceptor->Chain(top_job_factory.Pass());
job_factory.PassAs<net::URLRequestJobFactory>());
return protocol_handler_interceptor.PassAs<net::URLRequestJobFactory>(); return protocol_handler_interceptor.PassAs<net::URLRequestJobFactory>();
} else { } else {
return job_factory.PassAs<net::URLRequestJobFactory>(); return top_job_factory.Pass();
} }
} }
......
...@@ -4,12 +4,7 @@ ...@@ -4,12 +4,7 @@
#include "net/url_request/protocol_intercept_job_factory.h" #include "net/url_request/protocol_intercept_job_factory.h"
#include "base/stl_util.h" #include "base/logging.h"
#include "googleurl/src/gurl.h"
#include "net/base/load_flags.h"
#include "net/url_request/url_request_job_manager.h"
class GURL;
namespace net { namespace net {
...@@ -22,20 +17,6 @@ ProtocolInterceptJobFactory::ProtocolInterceptJobFactory( ...@@ -22,20 +17,6 @@ ProtocolInterceptJobFactory::ProtocolInterceptJobFactory(
ProtocolInterceptJobFactory::~ProtocolInterceptJobFactory() {} ProtocolInterceptJobFactory::~ProtocolInterceptJobFactory() {}
bool ProtocolInterceptJobFactory::SetProtocolHandler(
const std::string& scheme, ProtocolHandler* protocol_handler) {
return job_factory_->SetProtocolHandler(scheme, protocol_handler);
}
void ProtocolInterceptJobFactory::AddInterceptor(Interceptor* interceptor) {
return job_factory_->AddInterceptor(interceptor);
}
URLRequestJob* ProtocolInterceptJobFactory::MaybeCreateJobWithInterceptor(
URLRequest* request, NetworkDelegate* network_delegate) const {
return job_factory_->MaybeCreateJobWithInterceptor(request, network_delegate);
}
URLRequestJob* ProtocolInterceptJobFactory::MaybeCreateJobWithProtocolHandler( URLRequestJob* ProtocolInterceptJobFactory::MaybeCreateJobWithProtocolHandler(
const std::string& scheme, const std::string& scheme,
URLRequest* request, URLRequest* request,
...@@ -49,19 +30,6 @@ URLRequestJob* ProtocolInterceptJobFactory::MaybeCreateJobWithProtocolHandler( ...@@ -49,19 +30,6 @@ URLRequestJob* ProtocolInterceptJobFactory::MaybeCreateJobWithProtocolHandler(
scheme, request, network_delegate); scheme, request, network_delegate);
} }
URLRequestJob* ProtocolInterceptJobFactory::MaybeInterceptRedirect(
const GURL& location,
URLRequest* request,
NetworkDelegate* network_delegate) const {
return job_factory_->MaybeInterceptRedirect(
location, request, network_delegate);
}
URLRequestJob* ProtocolInterceptJobFactory::MaybeInterceptResponse(
URLRequest* request, NetworkDelegate* network_delegate) const {
return job_factory_->MaybeInterceptResponse(request, network_delegate);
}
bool ProtocolInterceptJobFactory::IsHandledProtocol( bool ProtocolInterceptJobFactory::IsHandledProtocol(
const std::string& scheme) const { const std::string& scheme) const {
return job_factory_->IsHandledProtocol(scheme); return job_factory_->IsHandledProtocol(scheme);
......
...@@ -29,21 +29,10 @@ class NET_EXPORT ProtocolInterceptJobFactory : public URLRequestJobFactory { ...@@ -29,21 +29,10 @@ class NET_EXPORT ProtocolInterceptJobFactory : public URLRequestJobFactory {
virtual ~ProtocolInterceptJobFactory(); virtual ~ProtocolInterceptJobFactory();
// URLRequestJobFactory implementation // URLRequestJobFactory implementation
virtual bool SetProtocolHandler(const std::string& scheme,
ProtocolHandler* protocol_handler) OVERRIDE;
virtual void AddInterceptor(Interceptor* interceptor) OVERRIDE;
virtual URLRequestJob* MaybeCreateJobWithInterceptor(
URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE;
virtual URLRequestJob* MaybeCreateJobWithProtocolHandler( virtual URLRequestJob* MaybeCreateJobWithProtocolHandler(
const std::string& scheme, const std::string& scheme,
URLRequest* request, URLRequest* request,
NetworkDelegate* network_delegate) const OVERRIDE; NetworkDelegate* network_delegate) const OVERRIDE;
virtual URLRequestJob* MaybeInterceptRedirect(
const GURL& location,
URLRequest* request,
NetworkDelegate* network_delegate) const OVERRIDE;
virtual URLRequestJob* MaybeInterceptResponse(
URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE;
virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE; virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE;
virtual bool IsHandledURL(const GURL& url) const OVERRIDE; virtual bool IsHandledURL(const GURL& url) const OVERRIDE;
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
// Temporary layering violation to allow existing users of a deprecated // Temporary layering violation to allow existing users of a deprecated
// interface. // interface.
class ChildProcessSecurityPolicyTest; class ChildProcessSecurityPolicyTest;
class ComponentUpdateInterceptor;
class TestAutomationProvider; class TestAutomationProvider;
class URLRequestAutomationJob; class URLRequestAutomationJob;
...@@ -57,13 +56,6 @@ namespace content { ...@@ -57,13 +56,6 @@ namespace content {
class ResourceDispatcherHostTest; class ResourceDispatcherHostTest;
} }
// Temporary layering violation to allow existing users of a deprecated
// interface.
namespace extensions {
class AutoUpdateInterceptor;
class UserScriptListenerTest;
}
// Temporary layering violation to allow existing users of a deprecated // Temporary layering violation to allow existing users of a deprecated
// interface. // interface.
namespace fileapi { namespace fileapi {
...@@ -72,12 +64,6 @@ class FileSystemURLRequestJobTest; ...@@ -72,12 +64,6 @@ class FileSystemURLRequestJobTest;
class FileWriterDelegateTest; class FileWriterDelegateTest;
} }
// Temporary layering violation to allow existing users of a deprecated
// interface.
namespace policy {
class CannedResponseInterceptor;
}
// Temporary layering violation to allow existing users of a deprecated // Temporary layering violation to allow existing users of a deprecated
// interface. // interface.
namespace webkit_blob { namespace webkit_blob {
...@@ -206,7 +192,8 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), ...@@ -206,7 +192,8 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme, static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme,
ProtocolFactory* factory); ProtocolFactory* factory);
// Use URLRequestJobFactory::Interceptor instead. // TODO(pauljensen): Remove this when AppCacheInterceptor is a
// ProtocolHandler, see crbug.com/161547.
static void RegisterRequestInterceptor(Interceptor* interceptor); static void RegisterRequestInterceptor(Interceptor* interceptor);
static void UnregisterRequestInterceptor(Interceptor* interceptor); static void UnregisterRequestInterceptor(Interceptor* interceptor);
......
...@@ -8,13 +8,6 @@ namespace net { ...@@ -8,13 +8,6 @@ namespace net {
URLRequestJobFactory::ProtocolHandler::~ProtocolHandler() {} URLRequestJobFactory::ProtocolHandler::~ProtocolHandler() {}
URLRequestJobFactory::Interceptor::~Interceptor() {}
bool URLRequestJobFactory::Interceptor::WillHandleProtocol(
const std::string& protocol) const {
return false;
}
URLRequestJobFactory::URLRequestJobFactory() {} URLRequestJobFactory::URLRequestJobFactory() {}
URLRequestJobFactory::~URLRequestJobFactory() {} URLRequestJobFactory::~URLRequestJobFactory() {}
......
...@@ -32,78 +32,14 @@ class NET_EXPORT URLRequestJobFactory ...@@ -32,78 +32,14 @@ class NET_EXPORT URLRequestJobFactory
URLRequest* request, NetworkDelegate* network_delegate) const = 0; URLRequest* request, NetworkDelegate* network_delegate) const = 0;
}; };
// TODO(shalev): Move this to URLRequestJobFactoryImpl.
class NET_EXPORT Interceptor {
public:
virtual ~Interceptor();
// Called for every request made. Should return a new job to handle the
// request if it should be intercepted, or NULL to allow the request to
// be handled in the normal manner.
virtual URLRequestJob* MaybeIntercept(
URLRequest* request, NetworkDelegate* network_delegate) const = 0;
// Called after having received a redirect response, but prior to the
// the request delegate being informed of the redirect. Can return a new
// job to replace the existing job if it should be intercepted, or NULL
// to allow the normal handling to continue. If a new job is provided,
// the delegate never sees the original redirect response, instead the
// response produced by the intercept job will be returned.
virtual URLRequestJob* MaybeInterceptRedirect(
const GURL& location,
URLRequest* request,
NetworkDelegate* network_delegate) const = 0;
// Called after having received a final response, but prior to the
// the request delegate being informed of the response. This is also
// called when there is no server response at all to allow interception
// on DNS or network errors. Can return a new job to replace the existing
// job if it should be intercepted, or NULL to allow the normal handling to
// continue. If a new job is provided, the delegate never sees the original
// response, instead the response produced by the intercept job will be
// returned.
virtual URLRequestJob* MaybeInterceptResponse(
URLRequest* request, NetworkDelegate* network_delegate) const = 0;
// Returns true if this interceptor handles requests for URLs with the
// given protocol. Returning false does not imply that this interceptor
// can't or won't handle requests with the given protocol.
virtual bool WillHandleProtocol(const std::string& protocol) const;
};
URLRequestJobFactory(); URLRequestJobFactory();
virtual ~URLRequestJobFactory(); virtual ~URLRequestJobFactory();
// TODO(shalev): Remove this from the interface.
// Sets the ProtocolHandler for a scheme. Returns true on success, false on
// failure (a ProtocolHandler already exists for |scheme|). On success,
// URLRequestJobFactory takes ownership of |protocol_handler|.
virtual bool SetProtocolHandler(const std::string& scheme,
ProtocolHandler* protocol_handler) = 0;
// TODO(shalev): Remove this from the interface.
// Takes ownership of |interceptor|. Adds it to the end of the Interceptor
// list.
virtual void AddInterceptor(Interceptor* interceptor) = 0;
// TODO(shalev): Consolidate MaybeCreateJobWithInterceptor and
// MaybeCreateJobWithProtocolHandler into a single method.
virtual URLRequestJob* MaybeCreateJobWithInterceptor(
URLRequest* request, NetworkDelegate* network_delegate) const = 0;
virtual URLRequestJob* MaybeCreateJobWithProtocolHandler( virtual URLRequestJob* MaybeCreateJobWithProtocolHandler(
const std::string& scheme, const std::string& scheme,
URLRequest* request, URLRequest* request,
NetworkDelegate* network_delegate) const = 0; NetworkDelegate* network_delegate) const = 0;
virtual URLRequestJob* MaybeInterceptRedirect(
const GURL& location,
URLRequest* request,
NetworkDelegate* network_delegate) const = 0;
virtual URLRequestJob* MaybeInterceptResponse(
URLRequest* request, NetworkDelegate* network_delegate) const = 0;
virtual bool IsHandledProtocol(const std::string& scheme) const = 0; virtual bool IsHandledProtocol(const std::string& scheme) const = 0;
virtual bool IsHandledURL(const GURL& url) const = 0; virtual bool IsHandledURL(const GURL& url) const = 0;
......
...@@ -15,7 +15,6 @@ URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {} ...@@ -15,7 +15,6 @@ URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {}
URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() { URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {
STLDeleteValues(&protocol_handler_map_); STLDeleteValues(&protocol_handler_map_);
STLDeleteElements(&interceptors_);
} }
bool URLRequestJobFactoryImpl::SetProtocolHandler( bool URLRequestJobFactoryImpl::SetProtocolHandler(
...@@ -39,29 +38,6 @@ bool URLRequestJobFactoryImpl::SetProtocolHandler( ...@@ -39,29 +38,6 @@ bool URLRequestJobFactoryImpl::SetProtocolHandler(
return true; return true;
} }
void URLRequestJobFactoryImpl::AddInterceptor(Interceptor* interceptor) {
DCHECK(CalledOnValidThread());
CHECK(interceptor);
interceptors_.push_back(interceptor);
}
URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithInterceptor(
URLRequest* request, NetworkDelegate* network_delegate) const {
DCHECK(CalledOnValidThread());
URLRequestJob* job = NULL;
if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
InterceptorList::const_iterator i;
for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
job = (*i)->MaybeIntercept(request, network_delegate);
if (job)
return job;
}
}
return NULL;
}
URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler( URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler(
const std::string& scheme, const std::string& scheme,
URLRequest* request, URLRequest* request,
...@@ -73,48 +49,9 @@ URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler( ...@@ -73,48 +49,9 @@ URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler(
return it->second->MaybeCreateJob(request, network_delegate); return it->second->MaybeCreateJob(request, network_delegate);
} }
URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptRedirect(
const GURL& location,
URLRequest* request,
NetworkDelegate* network_delegate) const {
DCHECK(CalledOnValidThread());
URLRequestJob* job = NULL;
if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
InterceptorList::const_iterator i;
for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
job = (*i)->MaybeInterceptRedirect(location, request, network_delegate);
if (job)
return job;
}
}
return NULL;
}
URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptResponse(
URLRequest* request, NetworkDelegate* network_delegate) const {
DCHECK(CalledOnValidThread());
URLRequestJob* job = NULL;
if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
InterceptorList::const_iterator i;
for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
job = (*i)->MaybeInterceptResponse(request, network_delegate);
if (job)
return job;
}
}
return NULL;
}
bool URLRequestJobFactoryImpl::IsHandledProtocol( bool URLRequestJobFactoryImpl::IsHandledProtocol(
const std::string& scheme) const { const std::string& scheme) const {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
InterceptorList::const_iterator i;
for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
if ((*i)->WillHandleProtocol(scheme))
return true;
}
return ContainsKey(protocol_handler_map_, scheme) || return ContainsKey(protocol_handler_map_, scheme) ||
URLRequestJobManager::GetInstance()->SupportsScheme(scheme); URLRequestJobManager::GetInstance()->SupportsScheme(scheme);
} }
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
#include "net/url_request/url_request_job_factory.h" #include "net/url_request/url_request_job_factory.h"
...@@ -18,31 +20,24 @@ class NET_EXPORT URLRequestJobFactoryImpl : public URLRequestJobFactory { ...@@ -18,31 +20,24 @@ class NET_EXPORT URLRequestJobFactoryImpl : public URLRequestJobFactory {
URLRequestJobFactoryImpl(); URLRequestJobFactoryImpl();
virtual ~URLRequestJobFactoryImpl(); virtual ~URLRequestJobFactoryImpl();
// Sets the ProtocolHandler for a scheme. Returns true on success, false on
// failure (a ProtocolHandler already exists for |scheme|). On success,
// URLRequestJobFactory takes ownership of |protocol_handler|.
bool SetProtocolHandler(const std::string& scheme,
ProtocolHandler* protocol_handler);
// URLRequestJobFactory implementation // URLRequestJobFactory implementation
virtual bool SetProtocolHandler(const std::string& scheme,
ProtocolHandler* protocol_handler) OVERRIDE;
virtual void AddInterceptor(Interceptor* interceptor) OVERRIDE;
virtual URLRequestJob* MaybeCreateJobWithInterceptor(
URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE;
virtual URLRequestJob* MaybeCreateJobWithProtocolHandler( virtual URLRequestJob* MaybeCreateJobWithProtocolHandler(
const std::string& scheme, const std::string& scheme,
URLRequest* request, URLRequest* request,
NetworkDelegate* network_delegate) const OVERRIDE; NetworkDelegate* network_delegate) const OVERRIDE;
virtual URLRequestJob* MaybeInterceptRedirect(
const GURL& location,
URLRequest* request,
NetworkDelegate* network_delegate) const OVERRIDE;
virtual URLRequestJob* MaybeInterceptResponse(
URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE;
virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE; virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE;
virtual bool IsHandledURL(const GURL& url) const OVERRIDE; virtual bool IsHandledURL(const GURL& url) const OVERRIDE;
private: private:
typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap; typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap;
typedef std::vector<Interceptor*> InterceptorList;
ProtocolHandlerMap protocol_handler_map_; ProtocolHandlerMap protocol_handler_map_;
InterceptorList interceptors_;
DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactoryImpl); DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactoryImpl);
}; };
......
...@@ -57,44 +57,6 @@ class DummyProtocolHandler : public URLRequestJobFactory::ProtocolHandler { ...@@ -57,44 +57,6 @@ class DummyProtocolHandler : public URLRequestJobFactory::ProtocolHandler {
} }
}; };
class DummyInterceptor : public URLRequestJobFactory::Interceptor {
public:
DummyInterceptor()
: did_intercept_(false),
handle_all_protocols_(false) {
}
virtual URLRequestJob* MaybeIntercept(
URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE {
did_intercept_ = true;
return new MockURLRequestJob(
request,
network_delegate,
URLRequestStatus(URLRequestStatus::FAILED, ERR_FAILED));
}
virtual URLRequestJob* MaybeInterceptRedirect(
const GURL& /* location */,
URLRequest* /* request */,
NetworkDelegate* network_delegate /* network delegate */) const OVERRIDE {
return NULL;
}
virtual URLRequestJob* MaybeInterceptResponse(
URLRequest* /* request */,
NetworkDelegate* network_delegate /* network delegate */) const OVERRIDE {
return NULL;
}
virtual bool WillHandleProtocol(
const std::string& /* protocol */) const OVERRIDE {
return handle_all_protocols_;
}
mutable bool did_intercept_;
mutable bool handle_all_protocols_;
};
TEST(URLRequestJobFactoryTest, NoProtocolHandler) { TEST(URLRequestJobFactoryTest, NoProtocolHandler) {
TestDelegate delegate; TestDelegate delegate;
TestURLRequestContext request_context; TestURLRequestContext request_context;
...@@ -128,91 +90,6 @@ TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) { ...@@ -128,91 +90,6 @@ TEST(URLRequestJobFactoryTest, DeleteProtocolHandler) {
job_factory.SetProtocolHandler("foo", NULL); job_factory.SetProtocolHandler("foo", NULL);
} }
TEST(URLRequestJobFactoryTest, BasicInterceptor) {
TestDelegate delegate;
URLRequestJobFactoryImpl job_factory;
TestURLRequestContext request_context;
request_context.set_job_factory(&job_factory);
job_factory.AddInterceptor(new DummyInterceptor);
TestURLRequest request(GURL("http://bar"), &delegate, &request_context);
request.Start();
MessageLoop::current()->Run();
EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
EXPECT_EQ(ERR_FAILED, request.status().error());
}
TEST(URLRequestJobFactoryTest, InterceptorNeedsValidSchemeStill) {
TestDelegate delegate;
URLRequestJobFactoryImpl job_factory;
TestURLRequestContext request_context;
request_context.set_job_factory(&job_factory);
job_factory.AddInterceptor(new DummyInterceptor);
TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
request.Start();
MessageLoop::current()->Run();
EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, request.status().error());
}
TEST(URLRequestJobFactoryTest, InterceptorOverridesProtocolHandler) {
TestDelegate delegate;
URLRequestJobFactoryImpl job_factory;
TestURLRequestContext request_context;
request_context.set_job_factory(&job_factory);
job_factory.SetProtocolHandler("foo", new DummyProtocolHandler);
job_factory.AddInterceptor(new DummyInterceptor);
TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
request.Start();
MessageLoop::current()->Run();
EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
EXPECT_EQ(ERR_FAILED, request.status().error());
}
TEST(URLRequestJobFactoryTest, InterceptorDoesntInterceptUnknownProtocols) {
TestDelegate delegate;
URLRequestJobFactoryImpl job_factory;
TestURLRequestContext request_context;
request_context.set_job_factory(&job_factory);
DummyInterceptor* interceptor = new DummyInterceptor;
job_factory.AddInterceptor(interceptor);
TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
request.Start();
MessageLoop::current()->Run();
EXPECT_FALSE(interceptor->did_intercept_);
}
TEST(URLRequestJobFactoryTest, InterceptorInterceptsHandledUnknownProtocols) {
TestDelegate delegate;
URLRequestJobFactoryImpl job_factory;
TestURLRequestContext request_context;
request_context.set_job_factory(&job_factory);
DummyInterceptor* interceptor = new DummyInterceptor;
interceptor->handle_all_protocols_ = true;
job_factory.AddInterceptor(interceptor);
TestURLRequest request(GURL("foo://bar"), &delegate, &request_context);
request.Start();
MessageLoop::current()->Run();
EXPECT_TRUE(interceptor->did_intercept_);
EXPECT_EQ(URLRequestStatus::FAILED, request.status().status());
EXPECT_EQ(ERR_FAILED, request.status().error());
}
TEST(URLRequestJobFactoryTest, InterceptorAffectsIsHandledProtocol) {
DummyInterceptor* interceptor = new DummyInterceptor;
URLRequestJobFactoryImpl job_factory;
job_factory.AddInterceptor(interceptor);
EXPECT_FALSE(interceptor->WillHandleProtocol("anything"));
EXPECT_FALSE(job_factory.IsHandledProtocol("anything"));
interceptor->handle_all_protocols_ = true;
EXPECT_TRUE(interceptor->WillHandleProtocol("anything"));
EXPECT_TRUE(job_factory.IsHandledProtocol("anything"));
}
} // namespace } // namespace
} // namespace net } // namespace net
...@@ -79,14 +79,8 @@ URLRequestJob* URLRequestJobManager::CreateJob( ...@@ -79,14 +79,8 @@ URLRequestJob* URLRequestJobManager::CreateJob(
// See if the request should be intercepted. // See if the request should be intercepted.
// //
if (job_factory) { // TODO(pauljensen): Remove this when AppCacheInterceptor is a
URLRequestJob* job = job_factory->MaybeCreateJobWithInterceptor( // ProtocolHandler, see crbug.com/161547.
request, network_delegate);
if (job)
return job;
}
// TODO(willchan): Remove this in favor of URLRequestJobFactory::Interceptor.
if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
InterceptorList::const_iterator i; InterceptorList::const_iterator i;
for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
...@@ -155,16 +149,11 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( ...@@ -155,16 +149,11 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect(
return NULL; return NULL;
} }
URLRequestJob* job = NULL;
if (job_factory)
job = job_factory->MaybeInterceptRedirect(
location, request, network_delegate);
if (job)
return job;
InterceptorList::const_iterator i; InterceptorList::const_iterator i;
for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
job = (*i)->MaybeInterceptRedirect(request, network_delegate, location); URLRequestJob* job = (*i)->MaybeInterceptRedirect(request,
network_delegate,
location);
if (job) if (job)
return job; return job;
} }
...@@ -192,15 +181,10 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptResponse( ...@@ -192,15 +181,10 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptResponse(
return NULL; return NULL;
} }
URLRequestJob* job = NULL;
if (job_factory)
job = job_factory->MaybeInterceptResponse(request, network_delegate);
if (job)
return job;
InterceptorList::const_iterator i; InterceptorList::const_iterator i;
for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
job = (*i)->MaybeInterceptResponse(request, network_delegate); URLRequestJob* job = (*i)->MaybeInterceptResponse(request,
network_delegate);
if (job) if (job)
return job; return job;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment