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 #include "content/browser/loader/async_resource_handler.h" | 5 #include "content/browser/loader/async_resource_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 buffer_->RecycleLeastRecentlyAllocated(); | 129 buffer_->RecycleLeastRecentlyAllocated(); |
130 if (buffer_->CanAllocate()) | 130 if (buffer_->CanAllocate()) |
131 ResumeIfDeferred(); | 131 ResumeIfDeferred(); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 bool AsyncResourceHandler::OnUploadProgress(int request_id, | 135 bool AsyncResourceHandler::OnUploadProgress(int request_id, |
136 uint64 position, | 136 uint64 position, |
137 uint64 size) { | 137 uint64 size) { |
138 ResourceMessageFilter* filter = GetFilter(); | 138 const ResourceRequestInfoImpl* info = GetRequestInfo(); |
139 if (!filter) | 139 // Cancel the request if the renderer is gone unless it's detachable. |
140 return false; | 140 if (!info->filter()) |
141 return filter->Send( | 141 return info->is_detached(); |
| 142 return info->filter()->Send( |
142 new ResourceMsg_UploadProgress(request_id, position, size)); | 143 new ResourceMsg_UploadProgress(request_id, position, size)); |
143 } | 144 } |
144 | 145 |
145 bool AsyncResourceHandler::OnRequestRedirected(int request_id, | 146 bool AsyncResourceHandler::OnRequestRedirected(int request_id, |
146 const GURL& new_url, | 147 const GURL& new_url, |
147 ResourceResponse* response, | 148 ResourceResponse* response, |
148 bool* defer) { | 149 bool* defer) { |
149 const ResourceRequestInfoImpl* info = GetRequestInfo(); | 150 const ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 151 // Cancel the request if the renderer is gone unless it's detached. |
150 if (!info->filter()) | 152 if (!info->filter()) |
151 return false; | 153 return info->is_detached(); |
152 | 154 |
153 *defer = did_defer_ = true; | 155 *defer = did_defer_ = true; |
154 | 156 |
155 if (rdh_->delegate()) { | 157 if (rdh_->delegate()) { |
156 rdh_->delegate()->OnRequestRedirected( | 158 rdh_->delegate()->OnRequestRedirected( |
157 new_url, request(), info->GetContext(), response); | 159 new_url, request(), info->GetContext(), response); |
158 } | 160 } |
159 | 161 |
160 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); | 162 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); |
161 response->head.request_start = request()->creation_time(); | 163 response->head.request_start = request()->creation_time(); |
162 response->head.response_start = TimeTicks::Now(); | 164 response->head.response_start = TimeTicks::Now(); |
163 return info->filter()->Send(new ResourceMsg_ReceivedRedirect( | 165 return info->filter()->Send(new ResourceMsg_ReceivedRedirect( |
164 request_id, new_url, response->head)); | 166 request_id, new_url, response->head)); |
165 } | 167 } |
166 | 168 |
167 bool AsyncResourceHandler::OnResponseStarted(int request_id, | 169 bool AsyncResourceHandler::OnResponseStarted(int request_id, |
168 ResourceResponse* response, | 170 ResourceResponse* response, |
169 bool* defer) { | 171 bool* defer) { |
170 // For changes to the main frame, inform the renderer of the new URL's | 172 // For changes to the main frame, inform the renderer of the new URL's |
171 // per-host settings before the request actually commits. This way the | 173 // per-host settings before the request actually commits. This way the |
172 // renderer will be able to set these precisely at the time the | 174 // renderer will be able to set these precisely at the time the |
173 // request commits, avoiding the possibility of e.g. zooming the old content | 175 // request commits, avoiding the possibility of e.g. zooming the old content |
174 // or of having to layout the new content twice. | 176 // or of having to layout the new content twice. |
| 177 const ResourceRequestInfoImpl* info = GetRequestInfo(); |
175 | 178 |
176 const ResourceRequestInfoImpl* info = GetRequestInfo(); | 179 // Cancel the request if the renderer is gone unless it's detachable. |
177 if (!info->filter()) | 180 if (!info->filter()) |
178 return false; | 181 return info->is_detached(); |
179 | 182 |
180 if (rdh_->delegate()) { | 183 if (rdh_->delegate()) { |
181 rdh_->delegate()->OnResponseStarted( | 184 rdh_->delegate()->OnResponseStarted( |
182 request(), info->GetContext(), response, info->filter()); | 185 request(), info->GetContext(), response, info->filter()); |
183 } | 186 } |
184 | 187 |
185 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); | 188 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); |
186 | 189 |
187 HostZoomMap* host_zoom_map = | 190 HostZoomMap* host_zoom_map = |
188 GetHostZoomMapForResourceContext(info->GetContext()); | 191 GetHostZoomMapForResourceContext(info->GetContext()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 return true; | 244 return true; |
242 } | 245 } |
243 | 246 |
244 bool AsyncResourceHandler::OnReadCompleted(int request_id, int bytes_read, | 247 bool AsyncResourceHandler::OnReadCompleted(int request_id, int bytes_read, |
245 bool* defer) { | 248 bool* defer) { |
246 DCHECK_GE(bytes_read, 0); | 249 DCHECK_GE(bytes_read, 0); |
247 | 250 |
248 if (!bytes_read) | 251 if (!bytes_read) |
249 return true; | 252 return true; |
250 | 253 |
| 254 const ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 255 // Don't send any data if the resource is detached from the renderer. |
| 256 if (info->is_detached()) { |
| 257 buffer_->RecycleLeastRecentlyAllocated(); |
| 258 return true; |
| 259 } |
| 260 |
251 ResourceMessageFilter* filter = GetFilter(); | 261 ResourceMessageFilter* filter = GetFilter(); |
252 if (!filter) | 262 // Cancel the request if the renderer is gone. |
| 263 if (!filter) { |
| 264 DCHECK(!info->is_detachable()); |
253 return false; | 265 return false; |
| 266 } |
254 | 267 |
255 buffer_->ShrinkLastAllocation(bytes_read); | 268 buffer_->ShrinkLastAllocation(bytes_read); |
256 | 269 |
257 UMA_HISTOGRAM_CUSTOM_COUNTS( | 270 UMA_HISTOGRAM_CUSTOM_COUNTS( |
258 "Net.AsyncResourceHandler_SharedIOBuffer_Used", | 271 "Net.AsyncResourceHandler_SharedIOBuffer_Used", |
259 bytes_read, 0, kMaxAllocationSize, 100); | 272 bytes_read, 0, kMaxAllocationSize, 100); |
260 UMA_HISTOGRAM_PERCENTAGE( | 273 UMA_HISTOGRAM_PERCENTAGE( |
261 "Net.AsyncResourceHandler_SharedIOBuffer_UsedPercentage", | 274 "Net.AsyncResourceHandler_SharedIOBuffer_UsedPercentage", |
262 CalcUsedPercentage(bytes_read, allocation_size_)); | 275 CalcUsedPercentage(bytes_read, allocation_size_)); |
263 | 276 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 filter->Send(new ResourceMsg_DataDownloaded( | 315 filter->Send(new ResourceMsg_DataDownloaded( |
303 request_id, bytes_downloaded, encoded_data_length)); | 316 request_id, bytes_downloaded, encoded_data_length)); |
304 } | 317 } |
305 } | 318 } |
306 | 319 |
307 bool AsyncResourceHandler::OnResponseCompleted( | 320 bool AsyncResourceHandler::OnResponseCompleted( |
308 int request_id, | 321 int request_id, |
309 const net::URLRequestStatus& status, | 322 const net::URLRequestStatus& status, |
310 const std::string& security_info) { | 323 const std::string& security_info) { |
311 const ResourceRequestInfoImpl* info = GetRequestInfo(); | 324 const ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 325 |
| 326 // Cancel the request if the renderer is gone unless it's detachable. |
312 if (!info->filter()) | 327 if (!info->filter()) |
313 return false; | 328 return info->is_detachable(); |
314 | 329 |
315 // If we crash here, figure out what URL the renderer was requesting. | 330 // If we crash here, figure out what URL the renderer was requesting. |
316 // http://crbug.com/107692 | 331 // http://crbug.com/107692 |
317 char url_buf[128]; | 332 char url_buf[128]; |
318 base::strlcpy(url_buf, request()->url().spec().c_str(), arraysize(url_buf)); | 333 base::strlcpy(url_buf, request()->url().spec().c_str(), arraysize(url_buf)); |
319 base::debug::Alias(url_buf); | 334 base::debug::Alias(url_buf); |
320 | 335 |
321 // TODO(gavinp): Remove this CHECK when we figure out the cause of | 336 // TODO(gavinp): Remove this CHECK when we figure out the cause of |
322 // http://crbug.com/124680 . This check mirrors closely check in | 337 // http://crbug.com/124680 . This check mirrors closely check in |
323 // WebURLLoaderImpl::OnCompletedRequest that routes this message to a WebCore | 338 // WebURLLoaderImpl::OnCompletedRequest that routes this message to a WebCore |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 390 } |
376 | 391 |
377 void AsyncResourceHandler::ResumeIfDeferred() { | 392 void AsyncResourceHandler::ResumeIfDeferred() { |
378 if (did_defer_) { | 393 if (did_defer_) { |
379 did_defer_ = false; | 394 did_defer_ = false; |
380 controller()->Resume(); | 395 controller()->Resume(); |
381 } | 396 } |
382 } | 397 } |
383 | 398 |
384 } // namespace content | 399 } // namespace content |
OLD | NEW |