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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 net::URLRequest* request, | 80 net::URLRequest* request, |
81 ResourceDispatcherHostImpl* rdh) | 81 ResourceDispatcherHostImpl* rdh) |
82 : ResourceMessageDelegate(request), | 82 : ResourceMessageDelegate(request), |
83 request_(request), | 83 request_(request), |
84 rdh_(rdh), | 84 rdh_(rdh), |
85 pending_data_count_(0), | 85 pending_data_count_(0), |
86 allocation_size_(0), | 86 allocation_size_(0), |
87 did_defer_(false), | 87 did_defer_(false), |
88 has_checked_for_sufficient_resources_(false), | 88 has_checked_for_sufficient_resources_(false), |
89 sent_received_response_msg_(false), | 89 sent_received_response_msg_(false), |
90 sent_first_data_msg_(false) { | 90 sent_first_data_msg_(false), |
91 detached_reads_(false) { | |
91 InitializeResourceBufferConstants(); | 92 InitializeResourceBufferConstants(); |
92 } | 93 } |
93 | 94 |
94 AsyncResourceHandler::~AsyncResourceHandler() { | 95 AsyncResourceHandler::~AsyncResourceHandler() { |
95 if (has_checked_for_sufficient_resources_) | 96 if (has_checked_for_sufficient_resources_) |
96 rdh_->FinishedWithResourcesForRequest(request_); | 97 rdh_->FinishedWithResourcesForRequest(request_); |
97 } | 98 } |
98 | 99 |
99 bool AsyncResourceHandler::OnMessageReceived(const IPC::Message& message, | 100 bool AsyncResourceHandler::OnMessageReceived(const IPC::Message& message, |
100 bool* message_was_ok) { | 101 bool* message_was_ok) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 bool* defer) { | 172 bool* defer) { |
172 // For changes to the main frame, inform the renderer of the new URL's | 173 // For changes to the main frame, inform the renderer of the new URL's |
173 // per-host settings before the request actually commits. This way the | 174 // per-host settings before the request actually commits. This way the |
174 // renderer will be able to set these precisely at the time the | 175 // renderer will be able to set these precisely at the time the |
175 // request commits, avoiding the possibility of e.g. zooming the old content | 176 // request commits, avoiding the possibility of e.g. zooming the old content |
176 // or of having to layout the new content twice. | 177 // or of having to layout the new content twice. |
177 | 178 |
178 const ResourceRequestInfoImpl* info = | 179 const ResourceRequestInfoImpl* info = |
179 ResourceRequestInfoImpl::ForRequest(request_); | 180 ResourceRequestInfoImpl::ForRequest(request_); |
180 if (!info->filter()) | 181 if (!info->filter()) |
181 return false; | 182 return false; |
mmenke
2013/10/08 14:50:54
So we still cancel prefetches if the renderer is d
jkarlin2
2013/10/09 14:44:33
Are you saying that the 'return false' above will
mmenke
2013/10/09 14:59:08
The return false should indeed result in a cancel.
jkarlin2
2013/10/09 17:28:29
Right, not sure how I didn't see that. It seems r
| |
182 | 183 |
183 if (rdh_->delegate()) { | 184 if (rdh_->delegate()) { |
184 rdh_->delegate()->OnResponseStarted( | 185 rdh_->delegate()->OnResponseStarted( |
185 request_, info->GetContext(), response, info->filter()); | 186 request_, info->GetContext(), response, info->filter()); |
186 } | 187 } |
187 | 188 |
188 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); | 189 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); |
189 | 190 |
190 HostZoomMap* host_zoom_map = | 191 HostZoomMap* host_zoom_map = |
191 GetHostZoomMapForResourceContext(info->GetContext()); | 192 GetHostZoomMapForResourceContext(info->GetContext()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 "Net.AsyncResourceHandler_SharedIOBuffer_Alloc", | 241 "Net.AsyncResourceHandler_SharedIOBuffer_Alloc", |
241 *buf_size, 0, kMaxAllocationSize, 100); | 242 *buf_size, 0, kMaxAllocationSize, 100); |
242 return true; | 243 return true; |
243 } | 244 } |
244 | 245 |
245 bool AsyncResourceHandler::OnReadCompleted(int request_id, int bytes_read, | 246 bool AsyncResourceHandler::OnReadCompleted(int request_id, int bytes_read, |
246 bool* defer) { | 247 bool* defer) { |
247 if (!bytes_read) | 248 if (!bytes_read) |
248 return true; | 249 return true; |
249 | 250 |
251 if (detached_reads_) { | |
252 buffer_->RecycleLeastRecentlyAllocated(); | |
253 return true; | |
254 } | |
255 | |
250 const ResourceRequestInfoImpl* info = | 256 const ResourceRequestInfoImpl* info = |
251 ResourceRequestInfoImpl::ForRequest(request_); | 257 ResourceRequestInfoImpl::ForRequest(request_); |
252 if (!info->filter()) | 258 if (!info->filter()) |
253 return false; | 259 return false; |
254 | 260 |
255 buffer_->ShrinkLastAllocation(bytes_read); | 261 buffer_->ShrinkLastAllocation(bytes_read); |
256 | 262 |
257 UMA_HISTOGRAM_CUSTOM_COUNTS( | 263 UMA_HISTOGRAM_CUSTOM_COUNTS( |
258 "Net.AsyncResourceHandler_SharedIOBuffer_Used", | 264 "Net.AsyncResourceHandler_SharedIOBuffer_Used", |
259 bytes_read, 0, kMaxAllocationSize, 100); | 265 bytes_read, 0, kMaxAllocationSize, 100); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 kMaxAllocationSize); | 383 kMaxAllocationSize); |
378 } | 384 } |
379 | 385 |
380 void AsyncResourceHandler::ResumeIfDeferred() { | 386 void AsyncResourceHandler::ResumeIfDeferred() { |
381 if (did_defer_) { | 387 if (did_defer_) { |
382 did_defer_ = false; | 388 did_defer_ = false; |
383 controller()->Resume(); | 389 controller()->Resume(); |
384 } | 390 } |
385 } | 391 } |
386 | 392 |
393 void AsyncResourceHandler::DetachReads() { | |
394 detached_reads_ = true; | |
395 } | |
396 | |
387 } // namespace content | 397 } // namespace content |
OLD | NEW |