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_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 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/debug/leak_tracker.h" | 11 #include "base/debug/leak_tracker.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/supports_user_data.h" | 15 #include "base/supports_user_data.h" |
16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "net/base/auth.h" | 18 #include "net/base/auth.h" |
19 #include "net/base/completion_callback.h" | 19 #include "net/base/completion_callback.h" |
20 #include "net/base/load_states.h" | 20 #include "net/base/load_states.h" |
21 #include "net/base/load_timing_info.h" | 21 #include "net/base/load_timing_info.h" |
22 #include "net/base/net_export.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/network_delegate.h" | 24 #include "net/base/network_delegate.h" |
25 #include "net/base/request_priority.h" | 25 #include "net/base/request_priority.h" |
26 #include "net/base/upload_progress.h" | 26 #include "net/base/upload_progress.h" |
27 #include "net/cookies/canonical_cookie.h" | 27 #include "net/cookies/canonical_cookie.h" |
| 28 #include "net/cookies/cookie_store.h" |
28 #include "net/http/http_request_headers.h" | 29 #include "net/http/http_request_headers.h" |
29 #include "net/http/http_response_info.h" | 30 #include "net/http/http_response_info.h" |
30 #include "net/url_request/url_request_status.h" | 31 #include "net/url_request/url_request_status.h" |
31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
32 | 33 |
33 // Temporary layering violation to allow existing users of a deprecated | 34 // Temporary layering violation to allow existing users of a deprecated |
34 // interface. | 35 // interface. |
35 class ChildProcessSecurityPolicyTest; | 36 class ChildProcessSecurityPolicyTest; |
36 | 37 |
37 namespace base { | 38 namespace base { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // to Read() previously. | 285 // to Read() previously. |
285 // | 286 // |
286 // If an error occurred, request->status() will contain the error, | 287 // If an error occurred, request->status() will contain the error, |
287 // and bytes read will be -1. | 288 // and bytes read will be -1. |
288 virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; | 289 virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; |
289 | 290 |
290 protected: | 291 protected: |
291 virtual ~Delegate() {} | 292 virtual ~Delegate() {} |
292 }; | 293 }; |
293 | 294 |
| 295 // TODO(tburkard): we should get rid of this constructor, and have each |
| 296 // creator of a URLRequest specifically list the cookie store to be used. |
| 297 // For now, this constructor will use the cookie store in |context|. |
294 URLRequest(const GURL& url, | 298 URLRequest(const GURL& url, |
295 RequestPriority priority, | 299 RequestPriority priority, |
296 Delegate* delegate, | 300 Delegate* delegate, |
297 const URLRequestContext* context); | 301 const URLRequestContext* context); |
298 | 302 |
| 303 URLRequest(const GURL& url, |
| 304 RequestPriority priority, |
| 305 Delegate* delegate, |
| 306 const URLRequestContext* context, |
| 307 CookieStore* cookie_store); |
| 308 |
299 // If destroyed after Start() has been called but while IO is pending, | 309 // If destroyed after Start() has been called but while IO is pending, |
300 // then the request will be effectively canceled and the delegate | 310 // then the request will be effectively canceled and the delegate |
301 // will not have any more of its methods called. | 311 // will not have any more of its methods called. |
302 virtual ~URLRequest(); | 312 virtual ~URLRequest(); |
303 | 313 |
304 // Changes the default cookie policy from allowing all cookies to blocking all | 314 // Changes the default cookie policy from allowing all cookies to blocking all |
305 // cookies. Embedders that want to implement a more flexible policy should | 315 // cookies. Embedders that want to implement a more flexible policy should |
306 // change the default to blocking all cookies, and provide a NetworkDelegate | 316 // change the default to blocking all cookies, and provide a NetworkDelegate |
307 // with the URLRequestContext that maintains the CookieStore. | 317 // with the URLRequestContext that maintains the CookieStore. |
308 // The cookie policy default has to be set before the first URLRequest is | 318 // The cookie policy default has to be set before the first URLRequest is |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 return received_response_content_length_; | 694 return received_response_content_length_; |
685 } | 695 } |
686 | 696 |
687 protected: | 697 protected: |
688 // Allow the URLRequestJob class to control the is_pending() flag. | 698 // Allow the URLRequestJob class to control the is_pending() flag. |
689 void set_is_pending(bool value) { is_pending_ = value; } | 699 void set_is_pending(bool value) { is_pending_ = value; } |
690 | 700 |
691 // Allow the URLRequestJob class to set our status too | 701 // Allow the URLRequestJob class to set our status too |
692 void set_status(const URLRequestStatus& value) { status_ = value; } | 702 void set_status(const URLRequestStatus& value) { status_ = value; } |
693 | 703 |
| 704 CookieStore* cookie_store() const { return cookie_store_; } |
| 705 |
694 // Allow the URLRequestJob to redirect this request. Returns OK if | 706 // Allow the URLRequestJob to redirect this request. Returns OK if |
695 // successful, otherwise an error code is returned. | 707 // successful, otherwise an error code is returned. |
696 int Redirect(const GURL& location, int http_status_code); | 708 int Redirect(const GURL& location, int http_status_code); |
697 | 709 |
698 // Called by URLRequestJob to allow interception when a redirect occurs. | 710 // Called by URLRequestJob to allow interception when a redirect occurs. |
699 void NotifyReceivedRedirect(const GURL& location, bool* defer_redirect); | 711 void NotifyReceivedRedirect(const GURL& location, bool* defer_redirect); |
700 | 712 |
701 // Called by URLRequestHttpJob (note, only HTTP(S) jobs will call this) to | 713 // Called by URLRequestHttpJob (note, only HTTP(S) jobs will call this) to |
702 // allow deferral of network initialization. | 714 // allow deferral of network initialization. |
703 void NotifyBeforeNetworkStart(bool* defer); | 715 void NotifyBeforeNetworkStart(bool* defer); |
(...skipping 19 matching lines...) Expand all Loading... |
723 // The registered protocol factory may return NULL, which will cause the | 735 // The registered protocol factory may return NULL, which will cause the |
724 // regular "built-in" protocol factory to be used. | 736 // regular "built-in" protocol factory to be used. |
725 // | 737 // |
726 static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme, | 738 static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme, |
727 ProtocolFactory* factory); | 739 ProtocolFactory* factory); |
728 | 740 |
729 // Registers or unregisters a network interception class. | 741 // Registers or unregisters a network interception class. |
730 static void RegisterRequestInterceptor(Interceptor* interceptor); | 742 static void RegisterRequestInterceptor(Interceptor* interceptor); |
731 static void UnregisterRequestInterceptor(Interceptor* interceptor); | 743 static void UnregisterRequestInterceptor(Interceptor* interceptor); |
732 | 744 |
| 745 // Initializes the URLRequest. Code shared between the two constructors. |
| 746 // TODO(tburkard): This can ultimately be folded into a single constructor |
| 747 // again. |
| 748 void Init(const GURL& url, |
| 749 RequestPriority priotity, |
| 750 Delegate* delegate, |
| 751 const URLRequestContext* context, |
| 752 CookieStore* cookie_store); |
| 753 |
733 // Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest | 754 // Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest |
734 // handler. If |blocked| is true, the request is blocked and an error page is | 755 // handler. If |blocked| is true, the request is blocked and an error page is |
735 // returned indicating so. This should only be called after Start is called | 756 // returned indicating so. This should only be called after Start is called |
736 // and OnBeforeRequest returns true (signalling that the request should be | 757 // and OnBeforeRequest returns true (signalling that the request should be |
737 // paused). | 758 // paused). |
738 void BeforeRequestComplete(int error); | 759 void BeforeRequestComplete(int error); |
739 | 760 |
740 void StartJob(URLRequestJob* job); | 761 void StartJob(URLRequestJob* job); |
741 | 762 |
742 // Restarting involves replacing the current job with a new one such as what | 763 // Restarting involves replacing the current job with a new one such as what |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 | 909 |
889 // Timing information for the most recent request. Its start times are | 910 // Timing information for the most recent request. Its start times are |
890 // populated during Start(), and the rest are populated in OnResponseReceived. | 911 // populated during Start(), and the rest are populated in OnResponseReceived. |
891 LoadTimingInfo load_timing_info_; | 912 LoadTimingInfo load_timing_info_; |
892 | 913 |
893 scoped_ptr<const base::debug::StackTrace> stack_trace_; | 914 scoped_ptr<const base::debug::StackTrace> stack_trace_; |
894 | 915 |
895 // Keeps track of whether or not OnBeforeNetworkStart has been called yet. | 916 // Keeps track of whether or not OnBeforeNetworkStart has been called yet. |
896 bool notified_before_network_start_; | 917 bool notified_before_network_start_; |
897 | 918 |
| 919 // The cookie store to be used for this request. |
| 920 scoped_refptr<CookieStore> cookie_store_; |
| 921 |
898 DISALLOW_COPY_AND_ASSIGN(URLRequest); | 922 DISALLOW_COPY_AND_ASSIGN(URLRequest); |
899 }; | 923 }; |
900 | 924 |
901 } // namespace net | 925 } // namespace net |
902 | 926 |
903 #endif // NET_URL_REQUEST_URL_REQUEST_H_ | 927 #endif // NET_URL_REQUEST_URL_REQUEST_H_ |
OLD | NEW |