Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1292)

Side by Side Diff: net/url_request/url_request.h

Issue 9348109: Add extra data to BrowserContext so that content layer and other embedders can stash data with it t… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #pragma once 7 #pragma once
8 8
9 #include <map>
10 #include <string> 9 #include <string>
11 #include <vector> 10 #include <vector>
12 11
13 #include "base/debug/leak_tracker.h" 12 #include "base/debug/leak_tracker.h"
14 #include "base/logging.h" 13 #include "base/logging.h"
15 #include "base/memory/linked_ptr.h"
16 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
17 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "base/supports_user_data.h"
18 #include "base/time.h" 17 #include "base/time.h"
19 #include "base/threading/non_thread_safe.h" 18 #include "base/threading/non_thread_safe.h"
20 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
21 #include "net/base/auth.h" 20 #include "net/base/auth.h"
22 #include "net/base/completion_callback.h" 21 #include "net/base/completion_callback.h"
23 #include "net/base/load_states.h" 22 #include "net/base/load_states.h"
24 #include "net/base/net_export.h" 23 #include "net/base/net_export.h"
25 #include "net/base/net_log.h" 24 #include "net/base/net_log.h"
26 #include "net/base/network_delegate.h" 25 #include "net/base/network_delegate.h"
27 #include "net/base/request_priority.h" 26 #include "net/base/request_priority.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // A class representing the asynchronous load of a data stream from an URL. 91 // A class representing the asynchronous load of a data stream from an URL.
93 // 92 //
94 // The lifetime of an instance of this class is completely controlled by the 93 // The lifetime of an instance of this class is completely controlled by the
95 // consumer, and the instance is not required to live on the heap or be 94 // consumer, and the instance is not required to live on the heap or be
96 // allocated in any special way. It is also valid to delete an URLRequest 95 // allocated in any special way. It is also valid to delete an URLRequest
97 // object during the handling of a callback to its delegate. Of course, once 96 // object during the handling of a callback to its delegate. Of course, once
98 // the URLRequest is deleted, no further callbacks to its delegate will occur. 97 // the URLRequest is deleted, no further callbacks to its delegate will occur.
99 // 98 //
100 // NOTE: All usage of all instances of this class should be on the same thread. 99 // NOTE: All usage of all instances of this class should be on the same thread.
101 // 100 //
102 class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe) { 101 class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
102 public base::SupportsUserData {
103 public: 103 public:
104 // Callback function implemented by protocol handlers to create new jobs. 104 // Callback function implemented by protocol handlers to create new jobs.
105 // The factory may return NULL to indicate an error, which will cause other 105 // The factory may return NULL to indicate an error, which will cause other
106 // factories to be queried. If no factory handles the request, then the 106 // factories to be queried. If no factory handles the request, then the
107 // default job will be used. 107 // default job will be used.
108 typedef URLRequestJob* (ProtocolFactory)(URLRequest* request, 108 typedef URLRequestJob* (ProtocolFactory)(URLRequest* request,
109 const std::string& scheme); 109 const std::string& scheme);
110 110
111 // HTTP request/response header IDs (via some preprocessor fun) for use with 111 // HTTP request/response header IDs (via some preprocessor fun) for use with
112 // SetRequestHeaderById and GetResponseHeaderById. 112 // SetRequestHeaderById and GetResponseHeaderById.
113 enum { 113 enum {
114 #define HTTP_ATOM(x) HTTP_ ## x, 114 #define HTTP_ATOM(x) HTTP_ ## x,
115 #include "net/http/http_atom_list.h" 115 #include "net/http/http_atom_list.h"
116 #undef HTTP_ATOM 116 #undef HTTP_ATOM
117 }; 117 };
118 118
119 // Derive from this class and add your own data members to associate extra
120 // information with a URLRequest. Use GetUserData(key) and SetUserData()
121 class UserData {
122 public:
123 UserData() {}
124 virtual ~UserData() {}
125 };
126
127 // This class handles network interception. Use with 119 // This class handles network interception. Use with
128 // (Un)RegisterRequestInterceptor. 120 // (Un)RegisterRequestInterceptor.
129 class NET_EXPORT Interceptor { 121 class NET_EXPORT Interceptor {
130 public: 122 public:
131 virtual ~Interceptor() {} 123 virtual ~Interceptor() {}
132 124
133 // Called for every request made. Should return a new job to handle the 125 // Called for every request made. Should return a new job to handle the
134 // request if it should be intercepted, or NULL to allow the request to 126 // request if it should be intercepted, or NULL to allow the request to
135 // be handled in the normal manner. 127 // be handled in the normal manner.
136 virtual URLRequestJob* MaybeIntercept(URLRequest* request) = 0; 128 virtual URLRequestJob* MaybeIntercept(URLRequest* request) = 0;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // and bytes read will be -1. 292 // and bytes read will be -1.
301 virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; 293 virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0;
302 }; 294 };
303 295
304 // Initialize an URL request. 296 // Initialize an URL request.
305 URLRequest(const GURL& url, Delegate* delegate); 297 URLRequest(const GURL& url, Delegate* delegate);
306 298
307 // 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,
308 // then the request will be effectively canceled and the delegate 300 // then the request will be effectively canceled and the delegate
309 // will not have any more of its methods called. 301 // will not have any more of its methods called.
310 ~URLRequest(); 302 virtual ~URLRequest();
311
312 // The user data allows the clients to associate data with this request.
313 // Multiple user data values can be stored under different keys.
314 // This request will TAKE OWNERSHIP of the given data pointer, and will
315 // delete the object if it is changed or the request is destroyed.
316 UserData* GetUserData(const void* key) const;
317 void SetUserData(const void* key, UserData* data);
318 303
319 // Returns true if the scheme can be handled by URLRequest. False otherwise. 304 // Returns true if the scheme can be handled by URLRequest. False otherwise.
320 static bool IsHandledProtocol(const std::string& scheme); 305 static bool IsHandledProtocol(const std::string& scheme);
321 306
322 // Returns true if the url can be handled by URLRequest. False otherwise. 307 // Returns true if the url can be handled by URLRequest. False otherwise.
323 // The function returns true for invalid urls because URLRequest knows how 308 // The function returns true for invalid urls because URLRequest knows how
324 // to handle those. 309 // to handle those.
325 // NOTE: This will also return true for URLs that are handled by 310 // NOTE: This will also return true for URLs that are handled by
326 // ProtocolFactories that only work for requests that are scoped to a 311 // ProtocolFactories that only work for requests that are scoped to a
327 // Profile. 312 // Profile.
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 // Called by URLRequestJob to allow interception when a redirect occurs. 609 // Called by URLRequestJob to allow interception when a redirect occurs.
625 void NotifyReceivedRedirect(const GURL& location, bool* defer_redirect); 610 void NotifyReceivedRedirect(const GURL& location, bool* defer_redirect);
626 611
627 // Allow an interceptor's URLRequestJob to restart this request. 612 // Allow an interceptor's URLRequestJob to restart this request.
628 // Should only be called if the original job has not started a response. 613 // Should only be called if the original job has not started a response.
629 void Restart(); 614 void Restart();
630 615
631 private: 616 private:
632 friend class URLRequestJob; 617 friend class URLRequestJob;
633 618
634 typedef std::map<const void*, linked_ptr<UserData> > UserDataMap;
635
636 // Registers a new protocol handler for the given scheme. If the scheme is 619 // Registers a new protocol handler for the given scheme. If the scheme is
637 // already handled, this will overwrite the given factory. To delete the 620 // already handled, this will overwrite the given factory. To delete the
638 // protocol factory, use NULL for the factory BUT this WILL NOT put back 621 // protocol factory, use NULL for the factory BUT this WILL NOT put back
639 // any previously registered protocol factory. It will have returned 622 // any previously registered protocol factory. It will have returned
640 // the previously registered factory (or NULL if none is registered) when 623 // the previously registered factory (or NULL if none is registered) when
641 // the scheme was first registered so that the caller can manually put it 624 // the scheme was first registered so that the caller can manually put it
642 // back if desired. 625 // back if desired.
643 // 626 //
644 // The scheme must be all-lowercase ASCII. See the ProtocolFactory 627 // The scheme must be all-lowercase ASCII. See the ProtocolFactory
645 // declaration for its requirements. 628 // declaration for its requirements.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 URLRequestStatus status_; 717 URLRequestStatus status_;
735 718
736 // The HTTP response info, lazily initialized. 719 // The HTTP response info, lazily initialized.
737 HttpResponseInfo response_info_; 720 HttpResponseInfo response_info_;
738 721
739 // Tells us whether the job is outstanding. This is true from the time 722 // Tells us whether the job is outstanding. This is true from the time
740 // Start() is called to the time we dispatch RequestComplete and indicates 723 // Start() is called to the time we dispatch RequestComplete and indicates
741 // whether the job is active. 724 // whether the job is active.
742 bool is_pending_; 725 bool is_pending_;
743 726
744 // Externally-defined data accessible by key
745 UserDataMap user_data_;
746
747 // Number of times we're willing to redirect. Used to guard against 727 // Number of times we're willing to redirect. Used to guard against
748 // infinite redirects. 728 // infinite redirects.
749 int redirect_limit_; 729 int redirect_limit_;
750 730
751 // Cached value for use after we've orphaned the job handling the 731 // Cached value for use after we've orphaned the job handling the
752 // first transaction in a request involving redirects. 732 // first transaction in a request involving redirects.
753 uint64 final_upload_progress_; 733 uint64 final_upload_progress_;
754 734
755 // The priority level for this request. Objects like ClientSocketPool use 735 // The priority level for this request. Objects like ClientSocketPool use
756 // this to determine which URLRequest to allocate sockets to first. 736 // this to determine which URLRequest to allocate sockets to first.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 scoped_refptr<AuthChallengeInfo> auth_info_; 772 scoped_refptr<AuthChallengeInfo> auth_info_;
793 773
794 base::TimeTicks creation_time_; 774 base::TimeTicks creation_time_;
795 775
796 DISALLOW_COPY_AND_ASSIGN(URLRequest); 776 DISALLOW_COPY_AND_ASSIGN(URLRequest);
797 }; 777 };
798 778
799 } // namespace net 779 } // namespace net
800 780
801 #endif // NET_URL_REQUEST_URL_REQUEST_H_ 781 #endif // NET_URL_REQUEST_URL_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698