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_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/debug/leak_tracker.h" | 13 #include "base/debug/leak_tracker.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/string16.h" | 17 #include "base/string16.h" |
18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
20 #include "net/base/completion_callback.h" | 20 #include "net/base/completion_callback.h" |
21 #include "net/base/load_states.h" | 21 #include "net/base/load_states.h" |
22 #include "net/base/net_api.h" | 22 #include "net/base/net_export.h" |
23 #include "net/base/net_log.h" | 23 #include "net/base/net_log.h" |
24 #include "net/base/request_priority.h" | 24 #include "net/base/request_priority.h" |
25 #include "net/http/http_request_headers.h" | 25 #include "net/http/http_request_headers.h" |
26 #include "net/http/http_response_info.h" | 26 #include "net/http/http_response_info.h" |
27 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
28 | 28 |
29 class FilePath; | 29 class FilePath; |
30 // Temporary layering violation to allow existing users of a deprecated | 30 // Temporary layering violation to allow existing users of a deprecated |
31 // interface. | 31 // interface. |
32 class AutoUpdateInterceptor; | 32 class AutoUpdateInterceptor; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // A class representing the asynchronous load of a data stream from an URL. | 97 // A class representing the asynchronous load of a data stream from an URL. |
98 // | 98 // |
99 // The lifetime of an instance of this class is completely controlled by the | 99 // The lifetime of an instance of this class is completely controlled by the |
100 // consumer, and the instance is not required to live on the heap or be | 100 // consumer, and the instance is not required to live on the heap or be |
101 // allocated in any special way. It is also valid to delete an URLRequest | 101 // allocated in any special way. It is also valid to delete an URLRequest |
102 // object during the handling of a callback to its delegate. Of course, once | 102 // object during the handling of a callback to its delegate. Of course, once |
103 // the URLRequest is deleted, no further callbacks to its delegate will occur. | 103 // the URLRequest is deleted, no further callbacks to its delegate will occur. |
104 // | 104 // |
105 // NOTE: All usage of all instances of this class should be on the same thread. | 105 // NOTE: All usage of all instances of this class should be on the same thread. |
106 // | 106 // |
107 class NET_API URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe) { | 107 class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
108 public: | 108 public: |
109 // Callback function implemented by protocol handlers to create new jobs. | 109 // Callback function implemented by protocol handlers to create new jobs. |
110 // The factory may return NULL to indicate an error, which will cause other | 110 // The factory may return NULL to indicate an error, which will cause other |
111 // factories to be queried. If no factory handles the request, then the | 111 // factories to be queried. If no factory handles the request, then the |
112 // default job will be used. | 112 // default job will be used. |
113 typedef URLRequestJob* (ProtocolFactory)(URLRequest* request, | 113 typedef URLRequestJob* (ProtocolFactory)(URLRequest* request, |
114 const std::string& scheme); | 114 const std::string& scheme); |
115 | 115 |
116 // HTTP request/response header IDs (via some preprocessor fun) for use with | 116 // HTTP request/response header IDs (via some preprocessor fun) for use with |
117 // SetRequestHeaderById and GetResponseHeaderById. | 117 // SetRequestHeaderById and GetResponseHeaderById. |
118 enum { | 118 enum { |
119 #define HTTP_ATOM(x) HTTP_ ## x, | 119 #define HTTP_ATOM(x) HTTP_ ## x, |
120 #include "net/http/http_atom_list.h" | 120 #include "net/http/http_atom_list.h" |
121 #undef HTTP_ATOM | 121 #undef HTTP_ATOM |
122 }; | 122 }; |
123 | 123 |
124 // Derive from this class and add your own data members to associate extra | 124 // Derive from this class and add your own data members to associate extra |
125 // information with a URLRequest. Use GetUserData(key) and SetUserData() | 125 // information with a URLRequest. Use GetUserData(key) and SetUserData() |
126 class UserData { | 126 class UserData { |
127 public: | 127 public: |
128 UserData() {} | 128 UserData() {} |
129 virtual ~UserData() {} | 129 virtual ~UserData() {} |
130 }; | 130 }; |
131 | 131 |
132 // This class handles network interception. Use with | 132 // This class handles network interception. Use with |
133 // (Un)RegisterRequestInterceptor. | 133 // (Un)RegisterRequestInterceptor. |
134 class NET_API Interceptor { | 134 class NET_EXPORT Interceptor { |
135 public: | 135 public: |
136 virtual ~Interceptor() {} | 136 virtual ~Interceptor() {} |
137 | 137 |
138 // Called for every request made. Should return a new job to handle the | 138 // Called for every request made. Should return a new job to handle the |
139 // request if it should be intercepted, or NULL to allow the request to | 139 // request if it should be intercepted, or NULL to allow the request to |
140 // be handled in the normal manner. | 140 // be handled in the normal manner. |
141 virtual URLRequestJob* MaybeIntercept(URLRequest* request) = 0; | 141 virtual URLRequestJob* MaybeIntercept(URLRequest* request) = 0; |
142 | 142 |
143 // Called after having received a redirect response, but prior to the | 143 // Called after having received a redirect response, but prior to the |
144 // the request delegate being informed of the redirect. Can return a new | 144 // the request delegate being informed of the redirect. Can return a new |
(...skipping 11 matching lines...) Expand all Loading... |
156 // job if it should be intercepted, or NULL to allow the normal handling to | 156 // job if it should be intercepted, or NULL to allow the normal handling to |
157 // continue. If a new job is provided, the delegate never sees the original | 157 // continue. If a new job is provided, the delegate never sees the original |
158 // response, instead the response produced by the intercept job will be | 158 // response, instead the response produced by the intercept job will be |
159 // returned. | 159 // returned. |
160 virtual URLRequestJob* MaybeInterceptResponse(URLRequest* request); | 160 virtual URLRequestJob* MaybeInterceptResponse(URLRequest* request); |
161 }; | 161 }; |
162 | 162 |
163 // Deprecated interfaces in net::URLRequest. They have been moved to | 163 // Deprecated interfaces in net::URLRequest. They have been moved to |
164 // URLRequest's private section to prevent new uses. Existing uses are | 164 // URLRequest's private section to prevent new uses. Existing uses are |
165 // explicitly friended here and should be removed over time. | 165 // explicitly friended here and should be removed over time. |
166 class NET_API Deprecated { | 166 class NET_EXPORT Deprecated { |
167 private: | 167 private: |
168 // TODO(willchan): Kill off these friend declarations. | 168 // TODO(willchan): Kill off these friend declarations. |
169 friend class ::AutoUpdateInterceptor; | 169 friend class ::AutoUpdateInterceptor; |
170 friend class ::ChildProcessSecurityPolicyTest; | 170 friend class ::ChildProcessSecurityPolicyTest; |
171 friend class ::ComponentUpdateInterceptor; | 171 friend class ::ComponentUpdateInterceptor; |
172 friend class ::ResourceDispatcherHostTest; | 172 friend class ::ResourceDispatcherHostTest; |
173 friend class ::TestAutomationProvider; | 173 friend class ::TestAutomationProvider; |
174 friend class ::UserScriptListenerTest; | 174 friend class ::UserScriptListenerTest; |
175 friend class ::URLRequestAutomationJob; | 175 friend class ::URLRequestAutomationJob; |
176 friend class TestInterceptor; | 176 friend class TestInterceptor; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 // - OnResponseStarted | 213 // - OnResponseStarted |
214 // Read() initiated by delegate | 214 // Read() initiated by delegate |
215 // - OnReadCompleted* (zero or more calls until all data is read) | 215 // - OnReadCompleted* (zero or more calls until all data is read) |
216 // | 216 // |
217 // Read() must be called at least once. Read() returns true when it completed | 217 // Read() must be called at least once. Read() returns true when it completed |
218 // immediately, and false if an IO is pending or if there is an error. When | 218 // immediately, and false if an IO is pending or if there is an error. When |
219 // Read() returns false, the caller can check the Request's status() to see | 219 // Read() returns false, the caller can check the Request's status() to see |
220 // if an error occurred, or if the IO is just pending. When Read() returns | 220 // if an error occurred, or if the IO is just pending. When Read() returns |
221 // true with zero bytes read, it indicates the end of the response. | 221 // true with zero bytes read, it indicates the end of the response. |
222 // | 222 // |
223 class NET_API Delegate { | 223 class NET_EXPORT Delegate { |
224 public: | 224 public: |
225 virtual ~Delegate() {} | 225 virtual ~Delegate() {} |
226 | 226 |
227 // Called upon a server-initiated redirect. The delegate may call the | 227 // Called upon a server-initiated redirect. The delegate may call the |
228 // request's Cancel method to prevent the redirect from being followed. | 228 // request's Cancel method to prevent the redirect from being followed. |
229 // Since there may be multiple chained redirects, there may also be more | 229 // Since there may be multiple chained redirects, there may also be more |
230 // than one redirect call. | 230 // than one redirect call. |
231 // | 231 // |
232 // When this function is called, the request will still contain the | 232 // When this function is called, the request will still contain the |
233 // original URL, the destination of the redirect is provided in 'new_url'. | 233 // original URL, the destination of the redirect is provided in 'new_url'. |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 // messages to network delegate. | 785 // messages to network delegate. |
786 // TODO(battre): Remove this. http://crbug.com/89049 | 786 // TODO(battre): Remove this. http://crbug.com/89049 |
787 bool has_notified_completion_; | 787 bool has_notified_completion_; |
788 | 788 |
789 DISALLOW_COPY_AND_ASSIGN(URLRequest); | 789 DISALLOW_COPY_AND_ASSIGN(URLRequest); |
790 }; | 790 }; |
791 | 791 |
792 } // namespace net | 792 } // namespace net |
793 | 793 |
794 #endif // NET_URL_REQUEST_URL_REQUEST_H_ | 794 #endif // NET_URL_REQUEST_URL_REQUEST_H_ |
OLD | NEW |