| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ |
| 6 #define NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 14 | 14 |
| 15 class GURL; | 15 class GURL; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 class NetworkDelegate; |
| 19 class URLRequest; | 20 class URLRequest; |
| 20 class URLRequestJob; | 21 class URLRequestJob; |
| 21 | 22 |
| 22 class NET_EXPORT URLRequestJobFactory | 23 class NET_EXPORT URLRequestJobFactory |
| 23 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | 24 : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 24 public: | 25 public: |
| 25 class NET_EXPORT ProtocolHandler { | 26 class NET_EXPORT ProtocolHandler { |
| 26 public: | 27 public: |
| 27 virtual ~ProtocolHandler(); | 28 virtual ~ProtocolHandler(); |
| 28 | 29 |
| 29 virtual URLRequestJob* MaybeCreateJob(URLRequest* request) const = 0; | 30 virtual URLRequestJob* MaybeCreateJob( |
| 31 URLRequest* request, NetworkDelegate* network_delegate) const = 0; |
| 30 }; | 32 }; |
| 31 | 33 |
| 32 class NET_EXPORT Interceptor { | 34 class NET_EXPORT Interceptor { |
| 33 public: | 35 public: |
| 34 virtual ~Interceptor(); | 36 virtual ~Interceptor(); |
| 35 | 37 |
| 36 // Called for every request made. Should return a new job to handle the | 38 // Called for every request made. Should return a new job to handle the |
| 37 // request if it should be intercepted, or NULL to allow the request to | 39 // request if it should be intercepted, or NULL to allow the request to |
| 38 // be handled in the normal manner. | 40 // be handled in the normal manner. |
| 39 virtual URLRequestJob* MaybeIntercept(URLRequest* request) const = 0; | 41 virtual URLRequestJob* MaybeIntercept( |
| 42 URLRequest* request, NetworkDelegate* network_delegate) const = 0; |
| 40 | 43 |
| 41 // Called after having received a redirect response, but prior to the | 44 // Called after having received a redirect response, but prior to the |
| 42 // the request delegate being informed of the redirect. Can return a new | 45 // the request delegate being informed of the redirect. Can return a new |
| 43 // job to replace the existing job if it should be intercepted, or NULL | 46 // job to replace the existing job if it should be intercepted, or NULL |
| 44 // to allow the normal handling to continue. If a new job is provided, | 47 // to allow the normal handling to continue. If a new job is provided, |
| 45 // the delegate never sees the original redirect response, instead the | 48 // the delegate never sees the original redirect response, instead the |
| 46 // response produced by the intercept job will be returned. | 49 // response produced by the intercept job will be returned. |
| 47 virtual URLRequestJob* MaybeInterceptRedirect( | 50 virtual URLRequestJob* MaybeInterceptRedirect( |
| 48 const GURL& location, | 51 const GURL& location, |
| 49 URLRequest* request) const = 0; | 52 URLRequest* request, |
| 53 NetworkDelegate* network_delegate) const = 0; |
| 50 | 54 |
| 51 // Called after having received a final response, but prior to the | 55 // Called after having received a final response, but prior to the |
| 52 // the request delegate being informed of the response. This is also | 56 // the request delegate being informed of the response. This is also |
| 53 // called when there is no server response at all to allow interception | 57 // called when there is no server response at all to allow interception |
| 54 // on DNS or network errors. Can return a new job to replace the existing | 58 // on DNS or network errors. Can return a new job to replace the existing |
| 55 // job if it should be intercepted, or NULL to allow the normal handling to | 59 // job if it should be intercepted, or NULL to allow the normal handling to |
| 56 // continue. If a new job is provided, the delegate never sees the original | 60 // continue. If a new job is provided, the delegate never sees the original |
| 57 // response, instead the response produced by the intercept job will be | 61 // response, instead the response produced by the intercept job will be |
| 58 // returned. | 62 // returned. |
| 59 virtual URLRequestJob* MaybeInterceptResponse( | 63 virtual URLRequestJob* MaybeInterceptResponse( |
| 60 URLRequest* request) const = 0; | 64 URLRequest* request, NetworkDelegate* network_delegate) const = 0; |
| 61 | 65 |
| 62 // Returns true if this interceptor handles requests for URLs with the | 66 // Returns true if this interceptor handles requests for URLs with the |
| 63 // given protocol. Returning false does not imply that this interceptor | 67 // given protocol. Returning false does not imply that this interceptor |
| 64 // can't or won't handle requests with the given protocol. | 68 // can't or won't handle requests with the given protocol. |
| 65 virtual bool WillHandleProtocol(const std::string& protocol) const; | 69 virtual bool WillHandleProtocol(const std::string& protocol) const; |
| 66 }; | 70 }; |
| 67 | 71 |
| 68 URLRequestJobFactory(); | 72 URLRequestJobFactory(); |
| 69 ~URLRequestJobFactory(); | 73 ~URLRequestJobFactory(); |
| 70 | 74 |
| 71 // Sets the ProtocolHandler for a scheme. Returns true on success, false on | 75 // Sets the ProtocolHandler for a scheme. Returns true on success, false on |
| 72 // failure (a ProtocolHandler already exists for |scheme|). On success, | 76 // failure (a ProtocolHandler already exists for |scheme|). On success, |
| 73 // URLRequestJobFactory takes ownership of |protocol_handler|. | 77 // URLRequestJobFactory takes ownership of |protocol_handler|. |
| 74 bool SetProtocolHandler(const std::string& scheme, | 78 bool SetProtocolHandler(const std::string& scheme, |
| 75 ProtocolHandler* protocol_handler); | 79 ProtocolHandler* protocol_handler); |
| 76 | 80 |
| 77 // Takes ownership of |interceptor|. Adds it to the end of the Interceptor | 81 // Takes ownership of |interceptor|. Adds it to the end of the Interceptor |
| 78 // list. | 82 // list. |
| 79 void AddInterceptor(Interceptor* interceptor); | 83 void AddInterceptor(Interceptor* interceptor); |
| 80 | 84 |
| 81 URLRequestJob* MaybeCreateJobWithInterceptor(URLRequest* request) const; | 85 URLRequestJob* MaybeCreateJobWithInterceptor( |
| 86 URLRequest* request, NetworkDelegate* network_delegate) const; |
| 82 | 87 |
| 83 URLRequestJob* MaybeCreateJobWithProtocolHandler(const std::string& scheme, | 88 URLRequestJob* MaybeCreateJobWithProtocolHandler( |
| 84 URLRequest* request) const; | 89 const std::string& scheme, |
| 90 URLRequest* request, |
| 91 NetworkDelegate* network_delegate) const; |
| 85 | 92 |
| 86 URLRequestJob* MaybeInterceptRedirect(const GURL& location, | 93 URLRequestJob* MaybeInterceptRedirect( |
| 87 URLRequest* request) const; | 94 const GURL& location, |
| 95 URLRequest* request, |
| 96 NetworkDelegate* network_delegate) const; |
| 88 | 97 |
| 89 URLRequestJob* MaybeInterceptResponse(URLRequest* request) const; | 98 URLRequestJob* MaybeInterceptResponse( |
| 99 URLRequest* request, NetworkDelegate* network_delegate) const; |
| 90 | 100 |
| 91 bool IsHandledProtocol(const std::string& scheme) const; | 101 bool IsHandledProtocol(const std::string& scheme) const; |
| 92 | 102 |
| 93 bool IsHandledURL(const GURL& url) const; | 103 bool IsHandledURL(const GURL& url) const; |
| 94 | 104 |
| 95 private: | 105 private: |
| 96 typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap; | 106 typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap; |
| 97 typedef std::vector<Interceptor*> InterceptorList; | 107 typedef std::vector<Interceptor*> InterceptorList; |
| 98 | 108 |
| 99 ProtocolHandlerMap protocol_handler_map_; | 109 ProtocolHandlerMap protocol_handler_map_; |
| 100 InterceptorList interceptors_; | 110 InterceptorList interceptors_; |
| 101 | 111 |
| 102 DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactory); | 112 DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactory); |
| 103 }; | 113 }; |
| 104 | 114 |
| 105 } // namespace net | 115 } // namespace net |
| 106 | 116 |
| 107 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ | 117 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ |
| OLD | NEW |