Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_IMPL_H_ |
| 6 | #define NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_IMPL_H_ |
| 7 | |
| 8 | #include <map> |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 9 | #include <string> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 10 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 11 | #include "base/basictypes.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | #include "net/base/net_export.h" |
| 14 | #include "net/url_request/url_request_job_factory.h" |
| 15 | |
| 16 | namespace net { |
| 17 | |
Torne (Richard Coles) | f8ee788 | 2014-06-20 14:52:04 +0100 | [diff] [blame] | 18 | class URLRequestInterceptor; |
| 19 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 20 | class NET_EXPORT URLRequestJobFactoryImpl : public URLRequestJobFactory { |
| 21 | public: |
| 22 | URLRequestJobFactoryImpl(); |
| 23 | virtual ~URLRequestJobFactoryImpl(); |
| 24 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 25 | // Sets the ProtocolHandler for a scheme. Returns true on success, false on |
| 26 | // failure (a ProtocolHandler already exists for |scheme|). On success, |
| 27 | // URLRequestJobFactory takes ownership of |protocol_handler|. |
| 28 | bool SetProtocolHandler(const std::string& scheme, |
| 29 | ProtocolHandler* protocol_handler); |
| 30 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 31 | // URLRequestJobFactory implementation |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 32 | virtual URLRequestJob* MaybeCreateJobWithProtocolHandler( |
| 33 | const std::string& scheme, |
| 34 | URLRequest* request, |
| 35 | NetworkDelegate* network_delegate) const OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 36 | virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE; |
| 37 | virtual bool IsHandledURL(const GURL& url) const OVERRIDE; |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 38 | virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 39 | |
| 40 | private: |
Torne (Richard Coles) | f8ee788 | 2014-06-20 14:52:04 +0100 | [diff] [blame] | 41 | // For testing only. |
| 42 | friend class URLRequestFilter; |
| 43 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 44 | typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 45 | |
Torne (Richard Coles) | f8ee788 | 2014-06-20 14:52:04 +0100 | [diff] [blame] | 46 | // Sets a global URLRequestInterceptor for testing purposes. The interceptor |
| 47 | // is given the chance to intercept any request before the corresponding |
| 48 | // ProtocolHandler, but after any other URLRequestJobFactories layered on top |
| 49 | // of the URLRequestJobFactoryImpl. |
| 50 | // If an interceptor is set, the old interceptor must be cleared before |
| 51 | // setting a new one. |
| 52 | static void SetInterceptorForTesting(URLRequestInterceptor* interceptor); |
| 53 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 54 | ProtocolHandlerMap protocol_handler_map_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 55 | |
| 56 | DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactoryImpl); |
| 57 | }; |
| 58 | |
| 59 | } // namespace net |
| 60 | |
| 61 | #endif // NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_IMPL_H_ |