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) const = 0; |
(...skipping 21 matching lines...) Expand all Loading... |
71 // Sets the ProtocolHandler for a scheme. Returns true on success, false on | 74 // Sets the ProtocolHandler for a scheme. Returns true on success, false on |
72 // failure (a ProtocolHandler already exists for |scheme|). On success, | 75 // failure (a ProtocolHandler already exists for |scheme|). On success, |
73 // URLRequestJobFactory takes ownership of |protocol_handler|. | 76 // URLRequestJobFactory takes ownership of |protocol_handler|. |
74 bool SetProtocolHandler(const std::string& scheme, | 77 bool SetProtocolHandler(const std::string& scheme, |
75 ProtocolHandler* protocol_handler); | 78 ProtocolHandler* protocol_handler); |
76 | 79 |
77 // Takes ownership of |interceptor|. Adds it to the end of the Interceptor | 80 // Takes ownership of |interceptor|. Adds it to the end of the Interceptor |
78 // list. | 81 // list. |
79 void AddInterceptor(Interceptor* interceptor); | 82 void AddInterceptor(Interceptor* interceptor); |
80 | 83 |
81 URLRequestJob* MaybeCreateJobWithInterceptor(URLRequest* request) const; | 84 URLRequestJob* MaybeCreateJobWithInterceptor( |
| 85 URLRequest* request, NetworkDelegate* network_delegate) const; |
82 | 86 |
83 URLRequestJob* MaybeCreateJobWithProtocolHandler(const std::string& scheme, | 87 URLRequestJob* MaybeCreateJobWithProtocolHandler( |
84 URLRequest* request) const; | 88 const std::string& scheme, |
| 89 URLRequest* request, |
| 90 NetworkDelegate* network_delegate) const; |
85 | 91 |
86 URLRequestJob* MaybeInterceptRedirect(const GURL& location, | 92 URLRequestJob* MaybeInterceptRedirect(const GURL& location, |
87 URLRequest* request) const; | 93 URLRequest* request) const; |
88 | 94 |
89 URLRequestJob* MaybeInterceptResponse(URLRequest* request) const; | 95 URLRequestJob* MaybeInterceptResponse(URLRequest* request) const; |
90 | 96 |
91 bool IsHandledProtocol(const std::string& scheme) const; | 97 bool IsHandledProtocol(const std::string& scheme) const; |
92 | 98 |
93 bool IsHandledURL(const GURL& url) const; | 99 bool IsHandledURL(const GURL& url) const; |
94 | 100 |
95 private: | 101 private: |
96 typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap; | 102 typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap; |
97 typedef std::vector<Interceptor*> InterceptorList; | 103 typedef std::vector<Interceptor*> InterceptorList; |
98 | 104 |
99 ProtocolHandlerMap protocol_handler_map_; | 105 ProtocolHandlerMap protocol_handler_map_; |
100 InterceptorList interceptors_; | 106 InterceptorList interceptors_; |
101 | 107 |
102 DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactory); | 108 DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactory); |
103 }; | 109 }; |
104 | 110 |
105 } // namespace net | 111 } // namespace net |
106 | 112 |
107 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ | 113 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_FACTORY_H_ |
OLD | NEW |