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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 ResourceResponse* response, | 166 ResourceResponse* response, |
167 bool* defer) { | 167 bool* defer) { |
168 // For changes to the main frame, inform the renderer of the new URL's | 168 // For changes to the main frame, inform the renderer of the new URL's |
169 // per-host settings before the request actually commits. This way the | 169 // per-host settings before the request actually commits. This way the |
170 // renderer will be able to set these precisely at the time the | 170 // renderer will be able to set these precisely at the time the |
171 // request commits, avoiding the possibility of e.g. zooming the old content | 171 // request commits, avoiding the possibility of e.g. zooming the old content |
172 // or of having to layout the new content twice. | 172 // or of having to layout the new content twice. |
173 | 173 |
174 ResourceContext* resource_context = filter_->resource_context(); | 174 ResourceContext* resource_context = filter_->resource_context(); |
175 if (rdh_->delegate()) { | 175 if (rdh_->delegate()) { |
176 rdh_->delegate()->OnResponseStarted(request_, resource_context, response, | 176 rdh_->delegate()->OnResponseStarted( |
177 filter_); | 177 request_, resource_context, response, filter_.get()); |
178 } | 178 } |
179 | 179 |
180 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); | 180 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); |
181 | 181 |
182 HostZoomMap* host_zoom_map = | 182 HostZoomMap* host_zoom_map = |
183 GetHostZoomMapForResourceContext(resource_context); | 183 GetHostZoomMapForResourceContext(resource_context); |
184 | 184 |
185 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | 185 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); |
186 if (info->GetResourceType() == ResourceType::MAIN_FRAME && host_zoom_map) { | 186 if (info->GetResourceType() == ResourceType::MAIN_FRAME && host_zoom_map) { |
187 const GURL& request_url = request_->url(); | 187 const GURL& request_url = request_->url(); |
188 filter_->Send(new ViewMsg_SetZoomLevelForLoadingURL( | 188 filter_->Send(new ViewMsg_SetZoomLevelForLoadingURL( |
189 info->GetRouteID(), | 189 info->GetRouteID(), |
190 request_url, host_zoom_map->GetZoomLevelForHostAndScheme( | 190 request_url, host_zoom_map->GetZoomLevelForHostAndScheme( |
191 request_url.scheme(), | 191 request_url.scheme(), |
192 net::GetHostOrSpecFromURL(request_url)))); | 192 net::GetHostOrSpecFromURL(request_url)))); |
193 } | 193 } |
194 | 194 |
195 response->head.request_start = request_->creation_time(); | 195 response->head.request_start = request_->creation_time(); |
196 response->head.response_start = TimeTicks::Now(); | 196 response->head.response_start = TimeTicks::Now(); |
197 filter_->Send(new ResourceMsg_ReceivedResponse( | 197 filter_->Send(new ResourceMsg_ReceivedResponse( |
198 routing_id_, request_id, response->head)); | 198 routing_id_, request_id, response->head)); |
199 sent_received_response_msg_ = true; | 199 sent_received_response_msg_ = true; |
200 | 200 |
201 if (request_->response_info().metadata) { | 201 if (request_->response_info().metadata.get()) { |
202 std::vector<char> copy(request_->response_info().metadata->data(), | 202 std::vector<char> copy(request_->response_info().metadata->data(), |
203 request_->response_info().metadata->data() + | 203 request_->response_info().metadata->data() + |
204 request_->response_info().metadata->size()); | 204 request_->response_info().metadata->size()); |
205 filter_->Send(new ResourceMsg_ReceivedCachedMetadata( | 205 filter_->Send(new ResourceMsg_ReceivedCachedMetadata( |
206 routing_id_, request_id, copy)); | 206 routing_id_, request_id, copy)); |
207 } | 207 } |
208 | 208 |
209 return true; | 209 return true; |
210 } | 210 } |
211 | 211 |
212 bool AsyncResourceHandler::OnWillStart(int request_id, | 212 bool AsyncResourceHandler::OnWillStart(int request_id, |
213 const GURL& url, | 213 const GURL& url, |
214 bool* defer) { | 214 bool* defer) { |
215 return true; | 215 return true; |
216 } | 216 } |
217 | 217 |
218 bool AsyncResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, | 218 bool AsyncResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, |
219 int* buf_size, int min_size) { | 219 int* buf_size, int min_size) { |
220 DCHECK_EQ(-1, min_size); | 220 DCHECK_EQ(-1, min_size); |
221 | 221 |
222 if (!EnsureResourceBufferIsInitialized()) | 222 if (!EnsureResourceBufferIsInitialized()) |
223 return false; | 223 return false; |
224 | 224 |
225 DCHECK(buffer_->CanAllocate()); | 225 DCHECK(buffer_->CanAllocate()); |
226 char* memory = buffer_->Allocate(&allocation_size_); | 226 char* memory = buffer_->Allocate(&allocation_size_); |
227 CHECK(memory); | 227 CHECK(memory); |
228 | 228 |
229 *buf = new DependentIOBuffer(buffer_, memory); | 229 *buf = new DependentIOBuffer(buffer_.get(), memory); |
230 *buf_size = allocation_size_; | 230 *buf_size = allocation_size_; |
231 | 231 |
232 UMA_HISTOGRAM_CUSTOM_COUNTS( | 232 UMA_HISTOGRAM_CUSTOM_COUNTS( |
233 "Net.AsyncResourceHandler_SharedIOBuffer_Alloc", | 233 "Net.AsyncResourceHandler_SharedIOBuffer_Alloc", |
234 *buf_size, 0, kMaxAllocationSize, 100); | 234 *buf_size, 0, kMaxAllocationSize, 100); |
235 return true; | 235 return true; |
236 } | 236 } |
237 | 237 |
238 bool AsyncResourceHandler::OnReadCompleted(int request_id, int bytes_read, | 238 bool AsyncResourceHandler::OnReadCompleted(int request_id, int bytes_read, |
239 bool* defer) { | 239 bool* defer) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 filter_->Send(new ResourceMsg_RequestComplete(routing_id_, | 331 filter_->Send(new ResourceMsg_RequestComplete(routing_id_, |
332 request_id, | 332 request_id, |
333 error_code, | 333 error_code, |
334 was_ignored_by_handler, | 334 was_ignored_by_handler, |
335 security_info, | 335 security_info, |
336 completion_time)); | 336 completion_time)); |
337 return true; | 337 return true; |
338 } | 338 } |
339 | 339 |
340 bool AsyncResourceHandler::EnsureResourceBufferIsInitialized() { | 340 bool AsyncResourceHandler::EnsureResourceBufferIsInitialized() { |
341 if (buffer_ && buffer_->IsInitialized()) | 341 if (buffer_.get() && buffer_->IsInitialized()) |
342 return true; | 342 return true; |
343 | 343 |
344 if (!has_checked_for_sufficient_resources_) { | 344 if (!has_checked_for_sufficient_resources_) { |
345 has_checked_for_sufficient_resources_ = true; | 345 has_checked_for_sufficient_resources_ = true; |
346 if (!rdh_->HasSufficientResourcesForRequest(request_)) { | 346 if (!rdh_->HasSufficientResourcesForRequest(request_)) { |
347 controller()->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); | 347 controller()->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); |
348 return false; | 348 return false; |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 buffer_ = new ResourceBuffer(); | 352 buffer_ = new ResourceBuffer(); |
353 return buffer_->Initialize(kBufferSize, | 353 return buffer_->Initialize(kBufferSize, |
354 kMinAllocationSize, | 354 kMinAllocationSize, |
355 kMaxAllocationSize); | 355 kMaxAllocationSize); |
356 } | 356 } |
357 | 357 |
358 void AsyncResourceHandler::ResumeIfDeferred() { | 358 void AsyncResourceHandler::ResumeIfDeferred() { |
359 if (did_defer_) { | 359 if (did_defer_) { |
360 did_defer_ = false; | 360 did_defer_ = false; |
361 controller()->Resume(); | 361 controller()->Resume(); |
362 } | 362 } |
363 } | 363 } |
364 | 364 |
365 } // namespace content | 365 } // namespace content |
OLD | NEW |