OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_MANAGER_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
14 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
15 | 15 |
16 template <typename T> struct DefaultSingletonTraits; | 16 template <typename T> |
| 17 struct DefaultSingletonTraits; |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 | 20 |
20 // This class is responsible for managing the set of protocol factories and | 21 // This class is responsible for managing the set of protocol factories and |
21 // request interceptors that determine how an URLRequestJob gets created to | 22 // request interceptors that determine how an URLRequestJob gets created to |
22 // handle an URLRequest. | 23 // handle an URLRequest. |
23 // | 24 // |
24 // MULTI-THREADING NOTICE: | 25 // MULTI-THREADING NOTICE: |
25 // URLRequest is designed to have all consumers on a single thread, and | 26 // URLRequest is designed to have all consumers on a single thread, and |
26 // so no attempt is made to support ProtocolFactory or Interceptor instances | 27 // so no attempt is made to support ProtocolFactory or Interceptor instances |
(...skipping 16 matching lines...) Expand all Loading... |
43 // of a redirect. Returns NULL if no interceptor intervenes. | 44 // of a redirect. Returns NULL if no interceptor intervenes. |
44 URLRequestJob* MaybeInterceptRedirect(URLRequest* request, | 45 URLRequestJob* MaybeInterceptRedirect(URLRequest* request, |
45 NetworkDelegate* network_delegate, | 46 NetworkDelegate* network_delegate, |
46 const GURL& location) const; | 47 const GURL& location) const; |
47 | 48 |
48 // Allows interceptors to hijack the request after examining the response | 49 // Allows interceptors to hijack the request after examining the response |
49 // status and headers. This is also called when there is no server response | 50 // status and headers. This is also called when there is no server response |
50 // at all to allow interception of failed requests due to network errors. | 51 // at all to allow interception of failed requests due to network errors. |
51 // Returns NULL if no interceptor intervenes. | 52 // Returns NULL if no interceptor intervenes. |
52 URLRequestJob* MaybeInterceptResponse( | 53 URLRequestJob* MaybeInterceptResponse( |
53 URLRequest* request, NetworkDelegate* network_delegate) const; | 54 URLRequest* request, |
| 55 NetworkDelegate* network_delegate) const; |
54 | 56 |
55 // Returns true if there is a protocol factory registered for the given | 57 // Returns true if there is a protocol factory registered for the given |
56 // scheme. Note: also returns true if there is a built-in handler for the | 58 // scheme. Note: also returns true if there is a built-in handler for the |
57 // given scheme. | 59 // given scheme. |
58 bool SupportsScheme(const std::string& scheme) const; | 60 bool SupportsScheme(const std::string& scheme) const; |
59 | 61 |
60 // Register a protocol factory associated with the given scheme. The factory | 62 // Register a protocol factory associated with the given scheme. The factory |
61 // parameter may be null to clear any existing association. Returns the | 63 // parameter may be null to clear any existing association. Returns the |
62 // previously registered protocol factory if any. | 64 // previously registered protocol factory if any. |
63 URLRequest::ProtocolFactory* RegisterProtocolFactory( | 65 URLRequest::ProtocolFactory* RegisterProtocolFactory( |
64 const std::string& scheme, URLRequest::ProtocolFactory* factory); | 66 const std::string& scheme, |
| 67 URLRequest::ProtocolFactory* factory); |
65 | 68 |
66 // Register/unregister a request interceptor. | 69 // Register/unregister a request interceptor. |
67 void RegisterRequestInterceptor(URLRequest::Interceptor* interceptor); | 70 void RegisterRequestInterceptor(URLRequest::Interceptor* interceptor); |
68 void UnregisterRequestInterceptor(URLRequest::Interceptor* interceptor); | 71 void UnregisterRequestInterceptor(URLRequest::Interceptor* interceptor); |
69 | 72 |
70 private: | 73 private: |
71 typedef std::map<std::string, URLRequest::ProtocolFactory*> FactoryMap; | 74 typedef std::map<std::string, URLRequest::ProtocolFactory*> FactoryMap; |
72 typedef std::vector<URLRequest::Interceptor*> InterceptorList; | 75 typedef std::vector<URLRequest::Interceptor*> InterceptorList; |
73 friend struct DefaultSingletonTraits<URLRequestJobManager>; | 76 friend struct DefaultSingletonTraits<URLRequestJobManager>; |
74 | 77 |
(...skipping 22 matching lines...) Expand all Loading... |
97 // check back on. | 100 // check back on. |
98 return true; | 101 return true; |
99 } | 102 } |
100 | 103 |
101 // We use this to assert that CreateJob and the registration functions all | 104 // We use this to assert that CreateJob and the registration functions all |
102 // run on the same thread. | 105 // run on the same thread. |
103 mutable base::PlatformThreadId allowed_thread_; | 106 mutable base::PlatformThreadId allowed_thread_; |
104 mutable bool allowed_thread_initialized_; | 107 mutable bool allowed_thread_initialized_; |
105 #endif | 108 #endif |
106 | 109 |
107 mutable base::Lock lock_; | 110 mutable base::Lock lock_; |
108 FactoryMap factories_; | 111 FactoryMap factories_; |
109 InterceptorList interceptors_; | 112 InterceptorList interceptors_; |
110 | 113 |
111 DISALLOW_COPY_AND_ASSIGN(URLRequestJobManager); | 114 DISALLOW_COPY_AND_ASSIGN(URLRequestJobManager); |
112 }; | 115 }; |
113 | 116 |
114 } // namespace net | 117 } // namespace net |
115 | 118 |
116 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_ | 119 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_ |
OLD | NEW |