| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 // TODO(jam): remove this file when all files have been converted. |
| 10 | 10 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/time.h" | |
| 13 #include "chrome/common/child_process_info.h" | |
| 14 #include "net/base/load_states.h" | |
| 15 #include "net/url_request/url_request.h" | |
| 16 #include "webkit/glue/resource_type.h" | |
| 17 | |
| 18 class CrossSiteResourceHandler; | |
| 19 class LoginHandler; | |
| 20 class ResourceDispatcherHost; | |
| 21 class ResourceHandler; | |
| 22 class SSLClientAuthHandler; | |
| 23 | |
| 24 namespace webkit_blob { | |
| 25 class BlobData; | |
| 26 } | |
| 27 | |
| 28 // Holds the data ResourceDispatcherHost associates with each request. | |
| 29 // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest. | |
| 30 class ResourceDispatcherHostRequestInfo : public net::URLRequest::UserData { | |
| 31 public: | |
| 32 // This will take a reference to the handler. | |
| 33 ResourceDispatcherHostRequestInfo( | |
| 34 ResourceHandler* handler, | |
| 35 ChildProcessInfo::ProcessType process_type, | |
| 36 int child_id, | |
| 37 int route_id, | |
| 38 int request_id, | |
| 39 ResourceType::Type resource_type, | |
| 40 uint64 upload_size, | |
| 41 bool is_download, | |
| 42 bool allow_download, | |
| 43 bool has_user_gesture, | |
| 44 int host_renderer_id, | |
| 45 int host_render_view_id); | |
| 46 virtual ~ResourceDispatcherHostRequestInfo(); | |
| 47 | |
| 48 // Top-level ResourceHandler servicing this request. | |
| 49 ResourceHandler* resource_handler() { return resource_handler_.get(); } | |
| 50 | |
| 51 // CrossSiteResourceHandler for this request, if it is a cross-site request. | |
| 52 // (NULL otherwise.) This handler is part of the chain of ResourceHandlers | |
| 53 // pointed to by resource_handler, and is not owned by this class. | |
| 54 CrossSiteResourceHandler* cross_site_handler() { | |
| 55 return cross_site_handler_; | |
| 56 } | |
| 57 void set_cross_site_handler(CrossSiteResourceHandler* h) { | |
| 58 cross_site_handler_ = h; | |
| 59 } | |
| 60 | |
| 61 // Pointer to the login handler, or NULL if there is none for this request. | |
| 62 LoginHandler* login_handler() const { return login_handler_.get(); } | |
| 63 void set_login_handler(LoginHandler* lh); | |
| 64 | |
| 65 // Pointer to the SSL auth, or NULL if there is none for this request. | |
| 66 SSLClientAuthHandler* ssl_client_auth_handler() const { | |
| 67 return ssl_client_auth_handler_.get(); | |
| 68 } | |
| 69 void set_ssl_client_auth_handler(SSLClientAuthHandler* s); | |
| 70 | |
| 71 // Identifies the type of process (renderer, plugin, etc.) making the request. | |
| 72 ChildProcessInfo::ProcessType process_type() const { | |
| 73 return process_type_; | |
| 74 } | |
| 75 | |
| 76 // The child process unique ID of the requestor. This duplicates the value | |
| 77 // stored on the request by SetChildProcessUniqueIDForRequest in | |
| 78 // url_request_tracking. | |
| 79 int child_id() const { return child_id_; } | |
| 80 | |
| 81 // The IPC route identifier for this request (this identifies the RenderView | |
| 82 // or like-thing in the renderer that the request gets routed to). | |
| 83 int route_id() const { return route_id_; } | |
| 84 | |
| 85 // Unique identifier for this resource request. | |
| 86 int request_id() const { return request_id_; } | |
| 87 | |
| 88 // Number of messages we've sent to the renderer that we haven't gotten an | |
| 89 // ACK for. This allows us to avoid having too many messages in flight. | |
| 90 int pending_data_count() const { return pending_data_count_; } | |
| 91 void IncrementPendingDataCount() { pending_data_count_++; } | |
| 92 void DecrementPendingDataCount() { pending_data_count_--; } | |
| 93 | |
| 94 // Downloads are allowed only as a top level request. | |
| 95 bool allow_download() const { return allow_download_; } | |
| 96 | |
| 97 bool has_user_gesture() const { return has_user_gesture_; } | |
| 98 | |
| 99 // Whether this is a download. | |
| 100 bool is_download() const { return is_download_; } | |
| 101 void set_is_download(bool download) { is_download_ = download; } | |
| 102 | |
| 103 // The number of clients that have called pause on this request. | |
| 104 int pause_count() const { return pause_count_; } | |
| 105 void set_pause_count(int count) { pause_count_ = count; } | |
| 106 | |
| 107 // Identifies the type of resource, such as subframe, media, etc. | |
| 108 ResourceType::Type resource_type() const { return resource_type_; } | |
| 109 | |
| 110 // Whether we should apply a filter to this resource that replaces | |
| 111 // localization templates with the appropriate localized strings. This is set | |
| 112 // for CSS resources used by extensions. | |
| 113 bool replace_extension_localization_templates() const { | |
| 114 return replace_extension_localization_templates_; | |
| 115 } | |
| 116 void set_replace_extension_localization_templates() { | |
| 117 replace_extension_localization_templates_ = true; | |
| 118 } | |
| 119 | |
| 120 // Returns the last updated state of the load. This is updated periodically | |
| 121 // by the ResourceDispatcherHost and tracked here so we don't send out | |
| 122 // unnecessary state change notifications. | |
| 123 net::LoadState last_load_state() const { return last_load_state_; } | |
| 124 void set_last_load_state(net::LoadState s) { last_load_state_ = s; } | |
| 125 | |
| 126 // When there is upload data, this is the byte count of that data. When there | |
| 127 // is no upload, this will be 0. | |
| 128 uint64 upload_size() const { return upload_size_; } | |
| 129 void set_upload_size(uint64 upload_size) { upload_size_ = upload_size; } | |
| 130 | |
| 131 // When we're uploading data, this is the the byte offset into the uploaded | |
| 132 // data that we've uploaded that we've send an upload progress update about. | |
| 133 // The ResourceDispatcherHost will periodically update this value to track | |
| 134 // upload progress and make sure it doesn't sent out duplicate updates. | |
| 135 uint64 last_upload_position() const { return last_upload_position_; } | |
| 136 void set_last_upload_position(uint64 p) { last_upload_position_ = p; } | |
| 137 | |
| 138 // Indicates when the ResourceDispatcherHost last update the upload | |
| 139 // position. This is used to make sure we don't send too many updates. | |
| 140 base::TimeTicks last_upload_ticks() const { return last_upload_ticks_; } | |
| 141 void set_last_upload_ticks(base::TimeTicks t) { last_upload_ticks_ = t; } | |
| 142 | |
| 143 // Set when the ResourceDispatcherHost has sent out an upload progress, and | |
| 144 // cleared whtn the ACK is received. This is used to throttle updates so | |
| 145 // multiple updates aren't in flight at once. | |
| 146 bool waiting_for_upload_progress_ack() const { | |
| 147 return waiting_for_upload_progress_ack_; | |
| 148 } | |
| 149 void set_waiting_for_upload_progress_ack(bool waiting) { | |
| 150 waiting_for_upload_progress_ack_ = waiting; | |
| 151 } | |
| 152 | |
| 153 // The approximate in-memory size (bytes) that we credited this request | |
| 154 // as consuming in |outstanding_requests_memory_cost_map_|. | |
| 155 int memory_cost() const { return memory_cost_; } | |
| 156 void set_memory_cost(int cost) { memory_cost_ = cost; } | |
| 157 | |
| 158 int host_renderer_id() const { return host_renderer_id_; } | |
| 159 int host_render_view_id() const { return host_render_view_id_; } | |
| 160 | |
| 161 // We hold a reference to the requested blob data to ensure it doesn't | |
| 162 // get finally released prior to the net::URLRequestJob being started. | |
| 163 webkit_blob::BlobData* requested_blob_data() const { | |
| 164 return requested_blob_data_.get(); | |
| 165 } | |
| 166 void set_requested_blob_data(webkit_blob::BlobData* data); | |
| 167 | |
| 168 private: | |
| 169 friend class ResourceDispatcherHost; | |
| 170 | |
| 171 // Request is temporarily not handling network data. Should be used only | |
| 172 // by the ResourceDispatcherHost, not the event handlers (accessors are | |
| 173 // provided for consistency with the rest of the interface). | |
| 174 bool is_paused() const { return is_paused_; } | |
| 175 void set_is_paused(bool paused) { is_paused_ = paused; } | |
| 176 | |
| 177 // Whether we called OnResponseStarted for this request or not. Should be used | |
| 178 // only by the ResourceDispatcherHost, not the event handlers (accessors are | |
| 179 // provided for consistency with the rest of the interface). | |
| 180 bool called_on_response_started() const { | |
| 181 return called_on_response_started_; | |
| 182 } | |
| 183 void set_called_on_response_started(bool called) { | |
| 184 called_on_response_started_ = called; | |
| 185 } | |
| 186 | |
| 187 // Whether this request has started reading any bytes from the response | |
| 188 // yet. Will be true after the first (unpaused) call to Read. Should be used | |
| 189 // only by the ResourceDispatcherHost, not the event handlers (accessors are | |
| 190 // provided for consistency with the rest of the interface). | |
| 191 bool has_started_reading() const { return has_started_reading_; } | |
| 192 void set_has_started_reading(bool reading) { has_started_reading_ = reading; } | |
| 193 | |
| 194 // How many bytes have been read while this request has been paused. Should be | |
| 195 // used only by the ResourceDispatcherHost, not the event handlers (accessors | |
| 196 // are provided for consistency with the rest of the interface). | |
| 197 int paused_read_bytes() const { return paused_read_bytes_; } | |
| 198 void set_paused_read_bytes(int bytes) { paused_read_bytes_ = bytes; } | |
| 199 | |
| 200 scoped_refptr<ResourceHandler> resource_handler_; | |
| 201 CrossSiteResourceHandler* cross_site_handler_; // Non-owning, may be NULL. | |
| 202 scoped_refptr<LoginHandler> login_handler_; | |
| 203 scoped_refptr<SSLClientAuthHandler> ssl_client_auth_handler_; | |
| 204 ChildProcessInfo::ProcessType process_type_; | |
| 205 int child_id_; | |
| 206 int route_id_; | |
| 207 int request_id_; | |
| 208 int pending_data_count_; | |
| 209 bool is_download_; | |
| 210 bool allow_download_; | |
| 211 bool has_user_gesture_; | |
| 212 int pause_count_; | |
| 213 ResourceType::Type resource_type_; | |
| 214 bool replace_extension_localization_templates_; | |
| 215 net::LoadState last_load_state_; | |
| 216 uint64 upload_size_; | |
| 217 uint64 last_upload_position_; | |
| 218 base::TimeTicks last_upload_ticks_; | |
| 219 bool waiting_for_upload_progress_ack_; | |
| 220 int memory_cost_; | |
| 221 scoped_refptr<webkit_blob::BlobData> requested_blob_data_; | |
| 222 | |
| 223 // "Private" data accessible only to ResourceDispatcherHost (use the | |
| 224 // accessors above for consistency). | |
| 225 bool is_paused_; | |
| 226 bool called_on_response_started_; | |
| 227 bool has_started_reading_; | |
| 228 int paused_read_bytes_; | |
| 229 | |
| 230 // The following two members are specified if the request is initiated by | |
| 231 // a plugin like Gears. | |
| 232 | |
| 233 // Contains the id of the host renderer. | |
| 234 int host_renderer_id_; | |
| 235 // Contains the id of the host render view. | |
| 236 int host_render_view_id_; | |
| 237 | |
| 238 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostRequestInfo); | |
| 239 }; | |
| 240 | 11 |
| 241 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ | 12 #endif // CHROME_BROWSER_RENDERER_HOST_RESOURCE_DISPATCHER_HOST_REQUEST_INFO_H_ |
| OLD | NEW |