| 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
| 6 | 6 |
| 7 #include "content/child/resource_dispatcher.h" | 7 #include "content/child/resource_dispatcher.h" |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // document blocking policy. We only do this for the first chunk of data. | 324 // document blocking policy. We only do this for the first chunk of data. |
| 325 if (request_info->site_isolation_metadata.get()) { | 325 if (request_info->site_isolation_metadata.get()) { |
| 326 SiteIsolationStatsGatherer::OnReceivedFirstChunk( | 326 SiteIsolationStatsGatherer::OnReceivedFirstChunk( |
| 327 request_info->site_isolation_metadata, data.data(), data.size()); | 327 request_info->site_isolation_metadata, data.data(), data.size()); |
| 328 request_info->site_isolation_metadata.reset(); | 328 request_info->site_isolation_metadata.reset(); |
| 329 } | 329 } |
| 330 | 330 |
| 331 DCHECK(!request_info->buffer.get()); | 331 DCHECK(!request_info->buffer.get()); |
| 332 | 332 |
| 333 request_info->peer->OnReceivedData( | 333 request_info->peer->OnReceivedData( |
| 334 base::MakeUnique<content::FixedReceivedData>(data, encoded_data_length)); | 334 base::MakeUnique<content::FixedReceivedData>(data)); |
| 335 |
| 336 // Get the request info again as the client callback may modify the info. |
| 337 request_info = GetPendingRequestInfo(request_id); |
| 338 if (request_info && encoded_data_length > 0) |
| 339 request_info->peer->OnTransferSizeUpdated(encoded_data_length); |
| 335 } | 340 } |
| 336 | 341 |
| 337 void ResourceDispatcher::OnReceivedData(int request_id, | 342 void ResourceDispatcher::OnReceivedData(int request_id, |
| 338 int data_offset, | 343 int data_offset, |
| 339 int data_length, | 344 int data_length, |
| 340 int encoded_data_length) { | 345 int encoded_data_length) { |
| 341 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedData"); | 346 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedData"); |
| 342 DCHECK_GT(data_length, 0); | 347 DCHECK_GT(data_length, 0); |
| 343 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 348 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
| 344 bool send_ack = true; | 349 bool send_ack = true; |
| 345 if (request_info && data_length > 0) { | 350 if (request_info && data_length > 0) { |
| 346 CHECK(base::SharedMemory::IsHandleValid(request_info->buffer->handle())); | 351 CHECK(base::SharedMemory::IsHandleValid(request_info->buffer->handle())); |
| 347 CHECK_GE(request_info->buffer_size, data_offset + data_length); | 352 CHECK_GE(request_info->buffer_size, data_offset + data_length); |
| 348 | 353 |
| 349 const char* data_start = static_cast<char*>(request_info->buffer->memory()); | 354 const char* data_start = static_cast<char*>(request_info->buffer->memory()); |
| 350 CHECK(data_start); | 355 CHECK(data_start); |
| 351 CHECK(data_start + data_offset); | 356 CHECK(data_start + data_offset); |
| 352 const char* data_ptr = data_start + data_offset; | 357 const char* data_ptr = data_start + data_offset; |
| 353 | 358 |
| 354 // Check whether this response data is compliant with our cross-site | 359 // Check whether this response data is compliant with our cross-site |
| 355 // document blocking policy. We only do this for the first chunk of data. | 360 // document blocking policy. We only do this for the first chunk of data. |
| 356 if (request_info->site_isolation_metadata.get()) { | 361 if (request_info->site_isolation_metadata.get()) { |
| 357 SiteIsolationStatsGatherer::OnReceivedFirstChunk( | 362 SiteIsolationStatsGatherer::OnReceivedFirstChunk( |
| 358 request_info->site_isolation_metadata, data_ptr, data_length); | 363 request_info->site_isolation_metadata, data_ptr, data_length); |
| 359 request_info->site_isolation_metadata.reset(); | 364 request_info->site_isolation_metadata.reset(); |
| 360 } | 365 } |
| 361 | 366 |
| 362 std::unique_ptr<RequestPeer::ReceivedData> data = | 367 std::unique_ptr<RequestPeer::ReceivedData> data = |
| 363 request_info->received_data_factory->Create(data_offset, data_length, | 368 request_info->received_data_factory->Create(data_offset, data_length); |
| 364 encoded_data_length); | |
| 365 // |data| takes care of ACKing. | 369 // |data| takes care of ACKing. |
| 366 send_ack = false; | 370 send_ack = false; |
| 367 request_info->peer->OnReceivedData(std::move(data)); | 371 request_info->peer->OnReceivedData(std::move(data)); |
| 368 } | 372 } |
| 369 | 373 |
| 374 // Get the request info again as the client callback may modify the info. |
| 375 request_info = GetPendingRequestInfo(request_id); |
| 376 if (request_info && encoded_data_length > 0) |
| 377 request_info->peer->OnTransferSizeUpdated(encoded_data_length); |
| 378 |
| 370 // Acknowledge the reception of this data. | 379 // Acknowledge the reception of this data. |
| 371 if (send_ack) | 380 if (send_ack) |
| 372 message_sender_->Send(new ResourceHostMsg_DataReceived_ACK(request_id)); | 381 message_sender_->Send(new ResourceHostMsg_DataReceived_ACK(request_id)); |
| 373 } | 382 } |
| 374 | 383 |
| 375 void ResourceDispatcher::OnDownloadedData(int request_id, | 384 void ResourceDispatcher::OnDownloadedData(int request_id, |
| 376 int data_len, | 385 int data_len, |
| 377 int encoded_data_length) { | 386 int encoded_data_length) { |
| 378 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 387 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
| 379 if (!request_info) | 388 if (!request_info) |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 delete message; | 861 delete message; |
| 853 } | 862 } |
| 854 } | 863 } |
| 855 | 864 |
| 856 void ResourceDispatcher::SetResourceSchedulingFilter( | 865 void ResourceDispatcher::SetResourceSchedulingFilter( |
| 857 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter) { | 866 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter) { |
| 858 resource_scheduling_filter_ = resource_scheduling_filter; | 867 resource_scheduling_filter_ = resource_scheduling_filter; |
| 859 } | 868 } |
| 860 | 869 |
| 861 } // namespace content | 870 } // namespace content |
| OLD | NEW |