| 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_log.h" | 23 #include "net/base/net_log.h" |
| 23 #include "net/base/request_priority.h" | 24 #include "net/base/request_priority.h" |
| 24 #include "net/http/http_request_headers.h" | 25 #include "net/http/http_request_headers.h" |
| 25 #include "net/http/http_response_info.h" | 26 #include "net/http/http_response_info.h" |
| 26 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
| 27 | 28 |
| 28 namespace base { | 29 namespace base { |
| 29 class Time; | 30 class Time; |
| 30 } // namespace base | 31 } // namespace base |
| 31 | 32 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 // A class representing the asynchronous load of a data stream from an URL. | 52 // A class representing the asynchronous load of a data stream from an URL. |
| 52 // | 53 // |
| 53 // The lifetime of an instance of this class is completely controlled by the | 54 // The lifetime of an instance of this class is completely controlled by the |
| 54 // consumer, and the instance is not required to live on the heap or be | 55 // consumer, and the instance is not required to live on the heap or be |
| 55 // allocated in any special way. It is also valid to delete an URLRequest | 56 // allocated in any special way. It is also valid to delete an URLRequest |
| 56 // object during the handling of a callback to its delegate. Of course, once | 57 // object during the handling of a callback to its delegate. Of course, once |
| 57 // the URLRequest is deleted, no further callbacks to its delegate will occur. | 58 // the URLRequest is deleted, no further callbacks to its delegate will occur. |
| 58 // | 59 // |
| 59 // NOTE: All usage of all instances of this class should be on the same thread. | 60 // NOTE: All usage of all instances of this class should be on the same thread. |
| 60 // | 61 // |
| 61 class URLRequest : public base::NonThreadSafe { | 62 class NET_API URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 62 public: | 63 public: |
| 63 // Callback function implemented by protocol handlers to create new jobs. | 64 // Callback function implemented by protocol handlers to create new jobs. |
| 64 // The factory may return NULL to indicate an error, which will cause other | 65 // The factory may return NULL to indicate an error, which will cause other |
| 65 // factories to be queried. If no factory handles the request, then the | 66 // factories to be queried. If no factory handles the request, then the |
| 66 // default job will be used. | 67 // default job will be used. |
| 67 typedef URLRequestJob* (ProtocolFactory)(URLRequest* request, | 68 typedef URLRequestJob* (ProtocolFactory)(URLRequest* request, |
| 68 const std::string& scheme); | 69 const std::string& scheme); |
| 69 | 70 |
| 70 // HTTP request/response header IDs (via some preprocessor fun) for use with | 71 // HTTP request/response header IDs (via some preprocessor fun) for use with |
| 71 // SetRequestHeaderById and GetResponseHeaderById. | 72 // SetRequestHeaderById and GetResponseHeaderById. |
| 72 enum { | 73 enum { |
| 73 #define HTTP_ATOM(x) HTTP_ ## x, | 74 #define HTTP_ATOM(x) HTTP_ ## x, |
| 74 #include "net/http/http_atom_list.h" | 75 #include "net/http/http_atom_list.h" |
| 75 #undef HTTP_ATOM | 76 #undef HTTP_ATOM |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 // Derive from this class and add your own data members to associate extra | 79 // Derive from this class and add your own data members to associate extra |
| 79 // information with a URLRequest. Use GetUserData(key) and SetUserData() | 80 // information with a URLRequest. Use GetUserData(key) and SetUserData() |
| 80 class UserData { | 81 class UserData { |
| 81 public: | 82 public: |
| 82 UserData() {} | 83 UserData() {} |
| 83 virtual ~UserData() {} | 84 virtual ~UserData() {} |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 // This class handles network interception. Use with | 87 // This class handles network interception. Use with |
| 87 // (Un)RegisterRequestInterceptor. | 88 // (Un)RegisterRequestInterceptor. |
| 88 class Interceptor { | 89 class NET_API Interceptor { |
| 89 public: | 90 public: |
| 90 virtual ~Interceptor() {} | 91 virtual ~Interceptor() {} |
| 91 | 92 |
| 92 // Called for every request made. Should return a new job to handle the | 93 // Called for every request made. Should return a new job to handle the |
| 93 // request if it should be intercepted, or NULL to allow the request to | 94 // request if it should be intercepted, or NULL to allow the request to |
| 94 // be handled in the normal manner. | 95 // be handled in the normal manner. |
| 95 virtual URLRequestJob* MaybeIntercept(URLRequest* request) = 0; | 96 virtual URLRequestJob* MaybeIntercept(URLRequest* request) = 0; |
| 96 | 97 |
| 97 // Called after having received a redirect response, but prior to the | 98 // Called after having received a redirect response, but prior to the |
| 98 // the request delegate being informed of the redirect. Can return a new | 99 // the request delegate being informed of the redirect. Can return a new |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // - OnResponseStarted | 131 // - OnResponseStarted |
| 131 // Read() initiated by delegate | 132 // Read() initiated by delegate |
| 132 // - OnReadCompleted* (zero or more calls until all data is read) | 133 // - OnReadCompleted* (zero or more calls until all data is read) |
| 133 // | 134 // |
| 134 // Read() must be called at least once. Read() returns true when it completed | 135 // Read() must be called at least once. Read() returns true when it completed |
| 135 // immediately, and false if an IO is pending or if there is an error. When | 136 // immediately, and false if an IO is pending or if there is an error. When |
| 136 // Read() returns false, the caller can check the Request's status() to see | 137 // Read() returns false, the caller can check the Request's status() to see |
| 137 // if an error occurred, or if the IO is just pending. When Read() returns | 138 // if an error occurred, or if the IO is just pending. When Read() returns |
| 138 // true with zero bytes read, it indicates the end of the response. | 139 // true with zero bytes read, it indicates the end of the response. |
| 139 // | 140 // |
| 140 class Delegate { | 141 class NET_API Delegate { |
| 141 public: | 142 public: |
| 142 virtual ~Delegate() {} | 143 virtual ~Delegate() {} |
| 143 | 144 |
| 144 // Called upon a server-initiated redirect. The delegate may call the | 145 // Called upon a server-initiated redirect. The delegate may call the |
| 145 // request's Cancel method to prevent the redirect from being followed. | 146 // request's Cancel method to prevent the redirect from being followed. |
| 146 // Since there may be multiple chained redirects, there may also be more | 147 // Since there may be multiple chained redirects, there may also be more |
| 147 // than one redirect call. | 148 // than one redirect call. |
| 148 // | 149 // |
| 149 // When this function is called, the request will still contain the | 150 // When this function is called, the request will still contain the |
| 150 // original URL, the destination of the redirect is provided in 'new_url'. | 151 // original URL, the destination of the redirect is provided in 'new_url'. |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 // Callback passed to the network delegate to notify us when a blocked request | 671 // Callback passed to the network delegate to notify us when a blocked request |
| 671 // is ready to be resumed or canceled. | 672 // is ready to be resumed or canceled. |
| 672 CompletionCallbackImpl<URLRequest> before_request_callback_; | 673 CompletionCallbackImpl<URLRequest> before_request_callback_; |
| 673 | 674 |
| 674 DISALLOW_COPY_AND_ASSIGN(URLRequest); | 675 DISALLOW_COPY_AND_ASSIGN(URLRequest); |
| 675 }; | 676 }; |
| 676 | 677 |
| 677 } // namespace net | 678 } // namespace net |
| 678 | 679 |
| 679 #endif // NET_URL_REQUEST_URL_REQUEST_H_ | 680 #endif // NET_URL_REQUEST_URL_REQUEST_H_ |
| OLD | NEW |