| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/mojo_async_resource_handler.h" | 5 #include "content/browser/loader/mojo_async_resource_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "content/browser/loader/downloaded_temp_file_impl.h" | 16 #include "content/browser/loader/downloaded_temp_file_impl.h" |
| 17 #include "content/browser/loader/netlog_observer.h" | 17 #include "content/browser/loader/netlog_observer.h" |
| 18 #include "content/browser/loader/resource_controller.h" | 18 #include "content/browser/loader/resource_controller.h" |
| 19 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 19 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 20 #include "content/browser/loader/resource_request_info_impl.h" | 20 #include "content/browser/loader/resource_request_info_impl.h" |
| 21 #include "content/common/resource_request_completion_status.h" | 21 #include "content/common/resource_request_completion_status.h" |
| 22 #include "content/public/browser/global_request_id.h" | 22 #include "content/public/browser/global_request_id.h" |
| 23 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 23 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 24 #include "content/public/common/resource_response.h" | 24 #include "content/public/common/resource_response.h" |
| 25 #include "mojo/public/c/system/data_pipe.h" | 25 #include "mojo/public/c/system/data_pipe.h" |
| 26 #include "mojo/public/cpp/bindings/message.h" | 26 #include "mojo/public/cpp/bindings/message.h" |
| 27 #include "mojo/public/cpp/system/data_pipe.h" | |
| 28 #include "net/base/io_buffer.h" | 27 #include "net/base/io_buffer.h" |
| 29 #include "net/base/load_flags.h" | 28 #include "net/base/load_flags.h" |
| 30 #include "net/base/mime_sniffer.h" | 29 #include "net/base/mime_sniffer.h" |
| 31 #include "net/url_request/redirect_info.h" | 30 #include "net/url_request/redirect_info.h" |
| 32 | 31 |
| 33 namespace content { | 32 namespace content { |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| 36 int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize; | 35 int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize; |
| 37 | 36 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return false; | 205 return false; |
| 207 | 206 |
| 208 if (!shared_writer_) { | 207 if (!shared_writer_) { |
| 209 MojoCreateDataPipeOptions options; | 208 MojoCreateDataPipeOptions options; |
| 210 options.struct_size = sizeof(MojoCreateDataPipeOptions); | 209 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
| 211 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | 210 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
| 212 options.element_num_bytes = 1; | 211 options.element_num_bytes = 1; |
| 213 options.capacity_num_bytes = g_allocation_size; | 212 options.capacity_num_bytes = g_allocation_size; |
| 214 mojo::DataPipe data_pipe(options); | 213 mojo::DataPipe data_pipe(options); |
| 215 | 214 |
| 216 url_loader_client_->OnStartLoadingResponseBody( | 215 DCHECK(data_pipe.producer_handle.is_valid()); |
| 217 std::move(data_pipe.consumer_handle)); | 216 DCHECK(data_pipe.consumer_handle.is_valid()); |
| 218 if (!data_pipe.producer_handle.is_valid()) | |
| 219 return false; | |
| 220 | 217 |
| 218 response_body_consumer_handle_ = std::move(data_pipe.consumer_handle); |
| 221 shared_writer_ = new SharedWriter(std::move(data_pipe.producer_handle)); | 219 shared_writer_ = new SharedWriter(std::move(data_pipe.producer_handle)); |
| 222 handle_watcher_.Start(shared_writer_->writer(), MOJO_HANDLE_SIGNAL_WRITABLE, | 220 handle_watcher_.Start(shared_writer_->writer(), MOJO_HANDLE_SIGNAL_WRITABLE, |
| 223 base::Bind(&MojoAsyncResourceHandler::OnWritable, | 221 base::Bind(&MojoAsyncResourceHandler::OnWritable, |
| 224 base::Unretained(this))); | 222 base::Unretained(this))); |
| 225 | 223 |
| 226 bool defer = false; | 224 bool defer = false; |
| 227 scoped_refptr<net::IOBufferWithSize> buffer; | 225 scoped_refptr<net::IOBufferWithSize> buffer; |
| 228 if (!AllocateWriterIOBuffer(&buffer, &defer)) | 226 if (!AllocateWriterIOBuffer(&buffer, &defer)) |
| 229 return false; | 227 return false; |
| 230 if (!defer) { | 228 if (!defer) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 256 if (!bytes_read) | 254 if (!bytes_read) |
| 257 return true; | 255 return true; |
| 258 | 256 |
| 259 const ResourceRequestInfoImpl* info = GetRequestInfo(); | 257 const ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 260 if (info->ShouldReportRawHeaders()) { | 258 if (info->ShouldReportRawHeaders()) { |
| 261 auto transfer_size_diff = CalculateRecentlyReceivedBytes(); | 259 auto transfer_size_diff = CalculateRecentlyReceivedBytes(); |
| 262 if (transfer_size_diff > 0) | 260 if (transfer_size_diff > 0) |
| 263 url_loader_client_->OnTransferSizeUpdated(transfer_size_diff); | 261 url_loader_client_->OnTransferSizeUpdated(transfer_size_diff); |
| 264 } | 262 } |
| 265 | 263 |
| 264 if (response_body_consumer_handle_.is_valid()) { |
| 265 // Send the data pipe on the first OnReadCompleted call. |
| 266 url_loader_client_->OnStartLoadingResponseBody( |
| 267 std::move(response_body_consumer_handle_)); |
| 268 response_body_consumer_handle_.reset(); |
| 269 } |
| 270 |
| 266 if (is_using_io_buffer_not_from_writer_) { | 271 if (is_using_io_buffer_not_from_writer_) { |
| 267 // Couldn't allocate a buffer on the data pipe in OnWillRead. | 272 // Couldn't allocate a buffer on the data pipe in OnWillRead. |
| 268 DCHECK_EQ(0u, buffer_bytes_read_); | 273 DCHECK_EQ(0u, buffer_bytes_read_); |
| 269 buffer_bytes_read_ = bytes_read; | 274 buffer_bytes_read_ = bytes_read; |
| 270 if (!CopyReadDataToDataPipe(defer)) | 275 if (!CopyReadDataToDataPipe(defer)) |
| 271 return false; | 276 return false; |
| 272 if (*defer) { | 277 if (*defer) { |
| 273 request()->LogBlockedBy("MojoAsyncResourceHandler"); | 278 request()->LogBlockedBy("MojoAsyncResourceHandler"); |
| 274 did_defer_on_writing_ = true; | 279 did_defer_on_writing_ = true; |
| 275 } | 280 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 mojom::URLLoaderAssociatedRequest mojo_request, | 490 mojom::URLLoaderAssociatedRequest mojo_request, |
| 486 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 491 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 487 binding_.Unbind(); | 492 binding_.Unbind(); |
| 488 binding_.Bind(std::move(mojo_request)); | 493 binding_.Bind(std::move(mojo_request)); |
| 489 binding_.set_connection_error_handler( | 494 binding_.set_connection_error_handler( |
| 490 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); | 495 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); |
| 491 url_loader_client_ = std::move(url_loader_client); | 496 url_loader_client_ = std::move(url_loader_client); |
| 492 } | 497 } |
| 493 | 498 |
| 494 } // namespace content | 499 } // namespace content |
| OLD | NEW |