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