| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ | |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/supports_user_data.h" | |
| 14 #include "base/time.h" | |
| 15 #include "content/common/content_export.h" | |
| 16 #include "content/public/common/page_transition_types.h" | |
| 17 #include "content/public/common/process_type.h" | |
| 18 #include "content/public/common/referrer.h" | |
| 19 #include "net/base/load_states.h" | |
| 20 #include "webkit/glue/resource_type.h" | |
| 21 | |
| 22 class ResourceDispatcherHost; | |
| 23 class ResourceHandler; | |
| 24 class SSLClientAuthHandler; | |
| 25 | |
| 26 namespace content { | |
| 27 class CrossSiteResourceHandler; | |
| 28 class ResourceContext; | |
| 29 class ResourceDispatcherHostLoginDelegate; | |
| 30 } | |
| 31 | |
| 32 namespace net { | |
| 33 class URLRequest; | |
| 34 } | |
| 35 | |
| 36 namespace webkit_blob { | |
| 37 class BlobData; | |
| 38 } | |
| 39 | |
| 40 // Holds the data ResourceDispatcherHost associates with each request. | |
| 41 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest. | |
| 42 class ResourceDispatcherHostRequestInfo : public base::SupportsUserData::Data { | |
| 43 public: | |
| 44 // This will take a reference to the handler. | |
| 45 CONTENT_EXPORT ResourceDispatcherHostRequestInfo( | |
| 46 ResourceHandler* handler, | |
| 47 content::ProcessType process_type, | |
| 48 int child_id, | |
| 49 int route_id, | |
| 50 int origin_pid, | |
| 51 int request_id, | |
| 52 bool is_main_frame, | |
| 53 int64 frame_id, | |
| 54 bool parent_is_main_frame, | |
| 55 int64 parent_frame_id, | |
| 56 ResourceType::Type resource_type, | |
| 57 content::PageTransition transition_type, | |
| 58 uint64 upload_size, | |
| 59 bool is_download, | |
| 60 bool allow_download, | |
| 61 bool has_user_gesture, | |
| 62 WebKit::WebReferrerPolicy referrer_policy, | |
| 63 content::ResourceContext* context); | |
| 64 virtual ~ResourceDispatcherHostRequestInfo(); | |
| 65 | |
| 66 // Top-level ResourceHandler servicing this request. | |
| 67 ResourceHandler* resource_handler() { return resource_handler_.get(); } | |
| 68 void set_resource_handler(ResourceHandler* resource_handler); | |
| 69 | |
| 70 // CrossSiteResourceHandler for this request, if it is a cross-site request. | |
| 71 // (NULL otherwise.) This handler is part of the chain of ResourceHandlers | |
| 72 // pointed to by resource_handler, and is not owned by this class. | |
| 73 content::CrossSiteResourceHandler* cross_site_handler() { | |
| 74 return cross_site_handler_; | |
| 75 } | |
| 76 void set_cross_site_handler(content::CrossSiteResourceHandler* h) { | |
| 77 cross_site_handler_ = h; | |
| 78 } | |
| 79 | |
| 80 // Pointer to the login delegate, or NULL if there is none for this request. | |
| 81 content::ResourceDispatcherHostLoginDelegate* login_delegate() const { | |
| 82 return login_delegate_.get(); | |
| 83 } | |
| 84 CONTENT_EXPORT void set_login_delegate( | |
| 85 content::ResourceDispatcherHostLoginDelegate* ld); | |
| 86 | |
| 87 // Pointer to the SSL auth, or NULL if there is none for this request. | |
| 88 SSLClientAuthHandler* ssl_client_auth_handler() const { | |
| 89 return ssl_client_auth_handler_.get(); | |
| 90 } | |
| 91 void set_ssl_client_auth_handler(SSLClientAuthHandler* s); | |
| 92 | |
| 93 // Identifies the type of process (renderer, plugin, etc.) making the request. | |
| 94 content::ProcessType process_type() const { | |
| 95 return process_type_; | |
| 96 } | |
| 97 | |
| 98 // The child process unique ID of the requestor. This duplicates the value | |
| 99 // stored on the request by SetChildProcessUniqueIDForRequest in | |
| 100 // url_request_tracking. | |
| 101 int child_id() const { return child_id_; } | |
| 102 | |
| 103 // The IPC route identifier for this request (this identifies the RenderView | |
| 104 // or like-thing in the renderer that the request gets routed to). | |
| 105 int route_id() const { return route_id_; } | |
| 106 | |
| 107 // The route_id of pending request can change when it is transferred to a new | |
| 108 // page (as in iframe transfer using adoptNode JS API). | |
| 109 void set_route_id(int route_id) { route_id_ = route_id; } | |
| 110 | |
| 111 // The pid of the originating process, if the request is sent on behalf of a | |
| 112 // another process. Otherwise it is 0. | |
| 113 int origin_pid() const { return origin_pid_; } | |
| 114 | |
| 115 // Unique identifier for this resource request. | |
| 116 int request_id() const { return request_id_; } | |
| 117 | |
| 118 // True if |frame_id_| represents a main frame in the RenderView. | |
| 119 bool is_main_frame() const { return is_main_frame_; } | |
| 120 | |
| 121 // Frame ID that sent this resource request. -1 if unknown / invalid. | |
| 122 int64 frame_id() const { return frame_id_; } | |
| 123 | |
| 124 // True if |parent_frame_id_| represents a main frame in the RenderView. | |
| 125 bool parent_is_main_frame() const { return parent_is_main_frame_; } | |
| 126 | |
| 127 // Frame ID of parent frame of frame that sent this resource request. | |
| 128 // -1 if unknown / invalid. | |
| 129 int64 parent_frame_id() const { return parent_frame_id_; } | |
| 130 | |
| 131 // Number of messages we've sent to the renderer that we haven't gotten an | |
| 132 // ACK for. This allows us to avoid having too many messages in flight. | |
| 133 int pending_data_count() const { return pending_data_count_; } | |
| 134 void IncrementPendingDataCount() { pending_data_count_++; } | |
| 135 void DecrementPendingDataCount() { pending_data_count_--; } | |
| 136 | |
| 137 // Downloads are allowed only as a top level request. | |
| 138 bool allow_download() const { return allow_download_; } | |
| 139 | |
| 140 bool has_user_gesture() const { return has_user_gesture_; } | |
| 141 | |
| 142 // Whether this is a download. | |
| 143 bool is_download() const { return is_download_; } | |
| 144 void set_is_download(bool download) { is_download_ = download; } | |
| 145 | |
| 146 // The number of clients that have called pause on this request. | |
| 147 int pause_count() const { return pause_count_; } | |
| 148 void set_pause_count(int count) { pause_count_ = count; } | |
| 149 | |
| 150 // Identifies the type of resource, such as subframe, media, etc. | |
| 151 ResourceType::Type resource_type() const { return resource_type_; } | |
| 152 | |
| 153 content::PageTransition transition_type() const { return transition_type_; } | |
| 154 | |
| 155 // When there is upload data, this is the byte count of that data. When there | |
| 156 // is no upload, this will be 0. | |
| 157 uint64 upload_size() const { return upload_size_; } | |
| 158 void set_upload_size(uint64 upload_size) { upload_size_ = upload_size; } | |
| 159 | |
| 160 // When we're uploading data, this is the the byte offset into the uploaded | |
| 161 // data that we've uploaded that we've send an upload progress update about. | |
| 162 // The ResourceDispatcherHost will periodically update this value to track | |
| 163 // upload progress and make sure it doesn't sent out duplicate updates. | |
| 164 uint64 last_upload_position() const { return last_upload_position_; } | |
| 165 void set_last_upload_position(uint64 p) { last_upload_position_ = p; } | |
| 166 | |
| 167 // Indicates when the ResourceDispatcherHost last update the upload | |
| 168 // position. This is used to make sure we don't send too many updates. | |
| 169 base::TimeTicks last_upload_ticks() const { return last_upload_ticks_; } | |
| 170 void set_last_upload_ticks(base::TimeTicks t) { last_upload_ticks_ = t; } | |
| 171 | |
| 172 // Set when the ResourceDispatcherHost has sent out an upload progress, and | |
| 173 // cleared whtn the ACK is received. This is used to throttle updates so | |
| 174 // multiple updates aren't in flight at once. | |
| 175 bool waiting_for_upload_progress_ack() const { | |
| 176 return waiting_for_upload_progress_ack_; | |
| 177 } | |
| 178 void set_waiting_for_upload_progress_ack(bool waiting) { | |
| 179 waiting_for_upload_progress_ack_ = waiting; | |
| 180 } | |
| 181 | |
| 182 // The approximate in-memory size (bytes) that we credited this request | |
| 183 // as consuming in |outstanding_requests_memory_cost_map_|. | |
| 184 int memory_cost() const { return memory_cost_; } | |
| 185 void set_memory_cost(int cost) { memory_cost_ = cost; } | |
| 186 | |
| 187 // We hold a reference to the requested blob data to ensure it doesn't | |
| 188 // get finally released prior to the net::URLRequestJob being started. | |
| 189 webkit_blob::BlobData* requested_blob_data() const { | |
| 190 return requested_blob_data_.get(); | |
| 191 } | |
| 192 void set_requested_blob_data(webkit_blob::BlobData* data); | |
| 193 | |
| 194 WebKit::WebReferrerPolicy referrer_policy() const { return referrer_policy_; } | |
| 195 | |
| 196 content::ResourceContext* context() const { return context_; } | |
| 197 | |
| 198 private: | |
| 199 friend class ResourceDispatcherHost; | |
| 200 | |
| 201 // Request is temporarily not handling network data. Should be used only | |
| 202 // by the ResourceDispatcherHost, not the event handlers (accessors are | |
| 203 // provided for consistency with the rest of the interface). | |
| 204 bool is_paused() const { return is_paused_; } | |
| 205 void set_is_paused(bool paused) { is_paused_ = paused; } | |
| 206 | |
| 207 // Whether we called OnResponseStarted for this request or not. Should be used | |
| 208 // only by the ResourceDispatcherHost, not the event handlers (accessors are | |
| 209 // provided for consistency with the rest of the interface). | |
| 210 bool called_on_response_started() const { | |
| 211 return called_on_response_started_; | |
| 212 } | |
| 213 void set_called_on_response_started(bool called) { | |
| 214 called_on_response_started_ = called; | |
| 215 } | |
| 216 | |
| 217 // Whether this request has started reading any bytes from the response | |
| 218 // yet. Will be true after the first (unpaused) call to Read. Should be used | |
| 219 // only by the ResourceDispatcherHost, not the event handlers (accessors are | |
| 220 // provided for consistency with the rest of the interface). | |
| 221 bool has_started_reading() const { return has_started_reading_; } | |
| 222 void set_has_started_reading(bool reading) { has_started_reading_ = reading; } | |
| 223 | |
| 224 // How many bytes have been read while this request has been paused. Should be | |
| 225 // used only by the ResourceDispatcherHost, not the event handlers (accessors | |
| 226 // are provided for consistency with the rest of the interface). | |
| 227 int paused_read_bytes() const { return paused_read_bytes_; } | |
| 228 void set_paused_read_bytes(int bytes) { paused_read_bytes_ = bytes; } | |
| 229 | |
| 230 scoped_refptr<ResourceHandler> resource_handler_; | |
| 231 | |
| 232 // Non-owning, may be NULL. | |
| 233 content::CrossSiteResourceHandler* cross_site_handler_; | |
| 234 | |
| 235 scoped_refptr<content::ResourceDispatcherHostLoginDelegate> login_delegate_; | |
| 236 scoped_refptr<SSLClientAuthHandler> ssl_client_auth_handler_; | |
| 237 content::ProcessType process_type_; | |
| 238 int child_id_; | |
| 239 int route_id_; | |
| 240 int origin_pid_; | |
| 241 int request_id_; | |
| 242 bool is_main_frame_; | |
| 243 int64 frame_id_; | |
| 244 bool parent_is_main_frame_; | |
| 245 int64 parent_frame_id_; | |
| 246 int pending_data_count_; | |
| 247 bool is_download_; | |
| 248 bool allow_download_; | |
| 249 bool has_user_gesture_; | |
| 250 int pause_count_; | |
| 251 ResourceType::Type resource_type_; | |
| 252 content::PageTransition transition_type_; | |
| 253 uint64 upload_size_; | |
| 254 uint64 last_upload_position_; | |
| 255 base::TimeTicks last_upload_ticks_; | |
| 256 bool waiting_for_upload_progress_ack_; | |
| 257 int memory_cost_; | |
| 258 scoped_refptr<webkit_blob::BlobData> requested_blob_data_; | |
| 259 WebKit::WebReferrerPolicy referrer_policy_; | |
| 260 content::ResourceContext* context_; | |
| 261 | |
| 262 // "Private" data accessible only to ResourceDispatcherHost (use the | |
| 263 // accessors above for consistency). | |
| 264 bool is_paused_; | |
| 265 bool called_on_response_started_; | |
| 266 bool has_started_reading_; | |
| 267 int paused_read_bytes_; | |
| 268 | |
| 269 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostRequestInfo); | |
| 270 }; | |
| 271 | |
| 272 #endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H
_ | |
| OLD | NEW |