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

Side by Side Diff: content/browser/renderer_host/resource_request_info_impl.h

Issue 10501004: Refactor the guts of ResourceDispatcherHostImpl into a new class named (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 CONTENT_BROWSER_RENDERER_HOST_RESOURCE_REQUEST_INFO_IMPL_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RESOURCE_REQUEST_INFO_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_REQUEST_INFO_IMPL_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_REQUEST_INFO_IMPL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/supports_user_data.h" 14 #include "base/supports_user_data.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "content/public/browser/resource_request_info.h" 16 #include "content/public/browser/resource_request_info.h"
17 #include "content/public/common/page_transition_types.h" 17 #include "content/public/common/page_transition_types.h"
18 #include "content/public/common/process_type.h" 18 #include "content/public/common/process_type.h"
19 #include "content/public/common/referrer.h" 19 #include "content/public/common/referrer.h"
20 #include "net/base/load_states.h" 20 #include "net/base/load_states.h"
21 #include "webkit/glue/resource_type.h" 21 #include "webkit/glue/resource_type.h"
22 22
23 class SSLClientAuthHandler;
24
25 namespace webkit_blob { 23 namespace webkit_blob {
26 class BlobData; 24 class BlobData;
27 } 25 }
28 26
29 namespace content { 27 namespace content {
30 class CrossSiteResourceHandler; 28 class CrossSiteResourceHandler;
31 class ResourceContext; 29 class ResourceContext;
32 class ResourceDispatcherHostImpl; 30 struct GlobalRequestID;
33 class ResourceDispatcherHostLoginDelegate;
34 class ResourceHandler;
35 31
36 // Holds the data ResourceDispatcherHost associates with each request. 32 // Holds the data ResourceDispatcherHost associates with each request.
37 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest. 33 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest.
38 class ResourceRequestInfoImpl : public ResourceRequestInfo, 34 class ResourceRequestInfoImpl : public ResourceRequestInfo,
39 public base::SupportsUserData::Data { 35 public base::SupportsUserData::Data {
40 public: 36 public:
41 // Returns the ResourceRequestInfoImpl associated with the given URLRequest. 37 // Returns the ResourceRequestInfoImpl associated with the given URLRequest.
42 CONTENT_EXPORT static ResourceRequestInfoImpl* ForRequest( 38 CONTENT_EXPORT static ResourceRequestInfoImpl* ForRequest(
43 net::URLRequest* request); 39 net::URLRequest* request);
44 40
45 // And, a const version for cases where you only need read access. 41 // And, a const version for cases where you only need read access.
46 static const ResourceRequestInfoImpl* ForRequest( 42 static const ResourceRequestInfoImpl* ForRequest(
47 const net::URLRequest* request); 43 const net::URLRequest* request);
48 44
49 // This will take a reference to the handler.
50 CONTENT_EXPORT ResourceRequestInfoImpl( 45 CONTENT_EXPORT ResourceRequestInfoImpl(
51 scoped_ptr<ResourceHandler> handler,
52 ProcessType process_type, 46 ProcessType process_type,
53 int child_id, 47 int child_id,
54 int route_id, 48 int route_id,
55 int origin_pid, 49 int origin_pid,
56 int request_id, 50 int request_id,
57 bool is_main_frame, 51 bool is_main_frame,
58 int64 frame_id, 52 int64 frame_id,
59 bool parent_is_main_frame, 53 bool parent_is_main_frame,
60 int64 parent_frame_id, 54 int64 parent_frame_id,
61 ResourceType::Type resource_type, 55 ResourceType::Type resource_type,
(...skipping 17 matching lines...) Expand all
79 virtual bool ParentIsMainFrame() const OVERRIDE; 73 virtual bool ParentIsMainFrame() const OVERRIDE;
80 virtual int64 GetParentFrameID() const OVERRIDE; 74 virtual int64 GetParentFrameID() const OVERRIDE;
81 virtual ResourceType::Type GetResourceType() const OVERRIDE; 75 virtual ResourceType::Type GetResourceType() const OVERRIDE;
82 virtual WebKit::WebReferrerPolicy GetReferrerPolicy() const OVERRIDE; 76 virtual WebKit::WebReferrerPolicy GetReferrerPolicy() const OVERRIDE;
83 virtual uint64 GetUploadSize() const OVERRIDE; 77 virtual uint64 GetUploadSize() const OVERRIDE;
84 virtual bool GetAssociatedRenderView(int* render_process_id, 78 virtual bool GetAssociatedRenderView(int* render_process_id,
85 int* render_view_id) const OVERRIDE; 79 int* render_view_id) const OVERRIDE;
86 80
87 void AssociateWithRequest(net::URLRequest* request); 81 void AssociateWithRequest(net::URLRequest* request);
88 82
89 // Top-level ResourceHandler servicing this request. 83 GlobalRequestID GetGlobalRequestID() const;
90 ResourceHandler* resource_handler() { return resource_handler_.get(); }
91
92 // Inserts a DoomedResourceHandler in front of the existing ResourceHandler.
93 void InsertDoomedResourceHandler();
94 84
95 // CrossSiteResourceHandler for this request, if it is a cross-site request. 85 // CrossSiteResourceHandler for this request, if it is a cross-site request.
96 // (NULL otherwise.) This handler is part of the chain of ResourceHandlers 86 // (NULL otherwise.) This handler is part of the chain of ResourceHandlers
97 // pointed to by resource_handler, and is not owned by this class. 87 // pointed to by resource_handler, and is not owned by this class.
98 CrossSiteResourceHandler* cross_site_handler() { 88 CrossSiteResourceHandler* cross_site_handler() {
99 return cross_site_handler_; 89 return cross_site_handler_;
100 } 90 }
101 void set_cross_site_handler(CrossSiteResourceHandler* h) { 91 void set_cross_site_handler(CrossSiteResourceHandler* h) {
102 cross_site_handler_ = h; 92 cross_site_handler_ = h;
103 } 93 }
104 94
105 // Pointer to the login delegate, or NULL if there is none for this request.
106 ResourceDispatcherHostLoginDelegate* login_delegate() const {
107 return login_delegate_.get();
108 }
109 CONTENT_EXPORT void set_login_delegate(
110 ResourceDispatcherHostLoginDelegate* ld);
111
112 // Pointer to the SSL auth, or NULL if there is none for this request.
113 SSLClientAuthHandler* ssl_client_auth_handler() const {
114 return ssl_client_auth_handler_.get();
115 }
116 void set_ssl_client_auth_handler(SSLClientAuthHandler* s);
117
118 // Identifies the type of process (renderer, plugin, etc.) making the request. 95 // Identifies the type of process (renderer, plugin, etc.) making the request.
119 ProcessType process_type() const { 96 ProcessType process_type() const {
120 return process_type_; 97 return process_type_;
121 } 98 }
122 99
123 // Number of messages we've sent to the renderer that we haven't gotten an 100 // Number of messages we've sent to the renderer that we haven't gotten an
124 // ACK for. This allows us to avoid having too many messages in flight. 101 // ACK for. This allows us to avoid having too many messages in flight.
125 int pending_data_count() const { return pending_data_count_; } 102 int pending_data_count() const { return pending_data_count_; }
126 void IncrementPendingDataCount() { pending_data_count_++; } 103 void IncrementPendingDataCount() { pending_data_count_++; }
127 void DecrementPendingDataCount() { pending_data_count_--; } 104 void DecrementPendingDataCount() { pending_data_count_--; }
128 105
129 // Downloads are allowed only as a top level request. 106 // Downloads are allowed only as a top level request.
130 bool allow_download() const { return allow_download_; } 107 bool allow_download() const { return allow_download_; }
131 108
132 bool has_user_gesture() const { return has_user_gesture_; } 109 bool has_user_gesture() const { return has_user_gesture_; }
133 110
134 // Whether this is a download. 111 // Whether this is a download.
135 bool is_download() const { return is_download_; } 112 bool is_download() const { return is_download_; }
136 void set_is_download(bool download) { is_download_ = download; } 113 void set_is_download(bool download) { is_download_ = download; }
137 114
138 // The number of clients that have called pause on this request.
139 int pause_count() const { return pause_count_; }
140 void set_pause_count(int count) { pause_count_ = count; }
141
142 PageTransition transition_type() const { return transition_type_; } 115 PageTransition transition_type() const { return transition_type_; }
143 116
144 void set_upload_size(uint64 upload_size) { upload_size_ = upload_size; } 117 void set_upload_size(uint64 upload_size) { upload_size_ = upload_size; }
145 118
146 // When we're uploading data, this is the the byte offset into the uploaded
147 // data that we've uploaded that we've send an upload progress update about.
148 // The ResourceDispatcherHost will periodically update this value to track
149 // upload progress and make sure it doesn't sent out duplicate updates.
150 uint64 last_upload_position() const { return last_upload_position_; }
151 void set_last_upload_position(uint64 p) { last_upload_position_ = p; }
152
153 // Indicates when the ResourceDispatcherHost last update the upload
154 // position. This is used to make sure we don't send too many updates.
155 base::TimeTicks last_upload_ticks() const { return last_upload_ticks_; }
156 void set_last_upload_ticks(base::TimeTicks t) { last_upload_ticks_ = t; }
157
158 // Set when the ResourceDispatcherHost has sent out an upload progress, and
159 // cleared whtn the ACK is received. This is used to throttle updates so
160 // multiple updates aren't in flight at once.
161 bool waiting_for_upload_progress_ack() const {
162 return waiting_for_upload_progress_ack_;
163 }
164 void set_waiting_for_upload_progress_ack(bool waiting) {
165 waiting_for_upload_progress_ack_ = waiting;
166 }
167
168 // The approximate in-memory size (bytes) that we credited this request 119 // The approximate in-memory size (bytes) that we credited this request
169 // as consuming in |outstanding_requests_memory_cost_map_|. 120 // as consuming in |outstanding_requests_memory_cost_map_|.
170 int memory_cost() const { return memory_cost_; } 121 int memory_cost() const { return memory_cost_; }
171 void set_memory_cost(int cost) { memory_cost_ = cost; } 122 void set_memory_cost(int cost) { memory_cost_ = cost; }
172 123
173 // We hold a reference to the requested blob data to ensure it doesn't 124 // We hold a reference to the requested blob data to ensure it doesn't
174 // get finally released prior to the net::URLRequestJob being started. 125 // get finally released prior to the net::URLRequestJob being started.
175 webkit_blob::BlobData* requested_blob_data() const { 126 webkit_blob::BlobData* requested_blob_data() const {
176 return requested_blob_data_.get(); 127 return requested_blob_data_.get();
177 } 128 }
178 void set_requested_blob_data(webkit_blob::BlobData* data); 129 void set_requested_blob_data(webkit_blob::BlobData* data);
179 130
180 private: 131 private:
181 friend class ResourceDispatcherHostImpl;
182
183 // Request is temporarily not handling network data. Should be used only
184 // by the ResourceDispatcherHost, not the event handlers (accessors are
185 // provided for consistency with the rest of the interface).
186 bool is_paused() const { return is_paused_; }
187 void set_is_paused(bool paused) { is_paused_ = paused; }
188
189 // Whether we called OnResponseStarted for this request or not. Should be used
190 // only by the ResourceDispatcherHost, not the event handlers (accessors are
191 // provided for consistency with the rest of the interface).
192 bool called_on_response_started() const {
193 return called_on_response_started_;
194 }
195 void set_called_on_response_started(bool called) {
196 called_on_response_started_ = called;
197 }
198
199 // Whether this request has started reading any bytes from the response
200 // yet. Will be true after the first (unpaused) call to Read. Should be used
201 // only by the ResourceDispatcherHost, not the event handlers (accessors are
202 // provided for consistency with the rest of the interface).
203 bool has_started_reading() const { return has_started_reading_; }
204 void set_has_started_reading(bool reading) { has_started_reading_ = reading; }
205
206 // How many bytes have been read while this request has been paused. Should be
207 // used only by the ResourceDispatcherHost, not the event handlers (accessors
208 // are provided for consistency with the rest of the interface).
209 int paused_read_bytes() const { return paused_read_bytes_; }
210 void set_paused_read_bytes(int bytes) { paused_read_bytes_ = bytes; }
211
212 scoped_ptr<ResourceHandler> resource_handler_;
213
214 // Non-owning, may be NULL. 132 // Non-owning, may be NULL.
215 CrossSiteResourceHandler* cross_site_handler_; 133 CrossSiteResourceHandler* cross_site_handler_;
216 134
217 scoped_refptr<ResourceDispatcherHostLoginDelegate> login_delegate_;
218 scoped_refptr<SSLClientAuthHandler> ssl_client_auth_handler_;
219 ProcessType process_type_; 135 ProcessType process_type_;
220 int child_id_; 136 int child_id_;
221 int route_id_; 137 int route_id_;
222 int origin_pid_; 138 int origin_pid_;
223 int request_id_; 139 int request_id_;
224 bool is_main_frame_; 140 bool is_main_frame_;
225 int64 frame_id_; 141 int64 frame_id_;
226 bool parent_is_main_frame_; 142 bool parent_is_main_frame_;
227 int64 parent_frame_id_; 143 int64 parent_frame_id_;
228 int pending_data_count_; 144 int pending_data_count_;
229 bool is_download_; 145 bool is_download_;
230 bool allow_download_; 146 bool allow_download_;
231 bool has_user_gesture_; 147 bool has_user_gesture_;
232 int pause_count_;
233 ResourceType::Type resource_type_; 148 ResourceType::Type resource_type_;
234 PageTransition transition_type_; 149 PageTransition transition_type_;
235 uint64 upload_size_; 150 uint64 upload_size_;
236 uint64 last_upload_position_;
237 base::TimeTicks last_upload_ticks_;
238 bool waiting_for_upload_progress_ack_;
239 int memory_cost_; 151 int memory_cost_;
240 scoped_refptr<webkit_blob::BlobData> requested_blob_data_; 152 scoped_refptr<webkit_blob::BlobData> requested_blob_data_;
241 WebKit::WebReferrerPolicy referrer_policy_; 153 WebKit::WebReferrerPolicy referrer_policy_;
242 ResourceContext* context_; 154 ResourceContext* context_;
243 155
244 // "Private" data accessible only to ResourceDispatcherHost (use the
245 // accessors above for consistency).
246 bool is_paused_;
247 bool called_on_response_started_;
248 bool has_started_reading_;
249 int paused_read_bytes_;
250
251 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl); 156 DISALLOW_COPY_AND_ASSIGN(ResourceRequestInfoImpl);
252 }; 157 };
253 158
254 } // namespace content 159 } // namespace content
255 160
256 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_REQUEST_INFO_IMPL_H_ 161 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_REQUEST_INFO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698