Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: content/browser/loader/mojo_async_resource_handler.cc

Issue 2633123002: [Mojo-Loading] OnStartLoadingResponseBody should be called after OnReceiveResponse (Closed)
Patch Set: fix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (!data_pipe.producer_handle.is_valid() ||
217 std::move(data_pipe.consumer_handle)); 216 !data_pipe.consumer_handle.is_valid()) {
mmenke 2017/01/18 16:26:12 Random comments on the mojo API: C++ constructors
mmenke 2017/01/18 16:26:12 Do we have any tests where this fails?
yhirano 2017/01/19 03:25:49 It looks impossible: https://cs.chromium.org/chrom
218 if (!data_pipe.producer_handle.is_valid())
219 return false; 217 return false;
218 }
220 219
220 response_body_consumer_handle_ = std::move(data_pipe.consumer_handle);
221 shared_writer_ = new SharedWriter(std::move(data_pipe.producer_handle)); 221 shared_writer_ = new SharedWriter(std::move(data_pipe.producer_handle));
222 handle_watcher_.Start(shared_writer_->writer(), MOJO_HANDLE_SIGNAL_WRITABLE, 222 handle_watcher_.Start(shared_writer_->writer(), MOJO_HANDLE_SIGNAL_WRITABLE,
223 base::Bind(&MojoAsyncResourceHandler::OnWritable, 223 base::Bind(&MojoAsyncResourceHandler::OnWritable,
224 base::Unretained(this))); 224 base::Unretained(this)));
225 225
226 bool defer = false; 226 bool defer = false;
227 scoped_refptr<net::IOBufferWithSize> buffer; 227 scoped_refptr<net::IOBufferWithSize> buffer;
228 if (!AllocateWriterIOBuffer(&buffer, &defer)) 228 if (!AllocateWriterIOBuffer(&buffer, &defer))
229 return false; 229 return false;
230 if (!defer) { 230 if (!defer) {
(...skipping 25 matching lines...) Expand all
256 if (!bytes_read) 256 if (!bytes_read)
257 return true; 257 return true;
258 258
259 const ResourceRequestInfoImpl* info = GetRequestInfo(); 259 const ResourceRequestInfoImpl* info = GetRequestInfo();
260 if (info->ShouldReportRawHeaders()) { 260 if (info->ShouldReportRawHeaders()) {
261 auto transfer_size_diff = CalculateRecentlyReceivedBytes(); 261 auto transfer_size_diff = CalculateRecentlyReceivedBytes();
262 if (transfer_size_diff > 0) 262 if (transfer_size_diff > 0)
263 url_loader_client_->OnTransferSizeUpdated(transfer_size_diff); 263 url_loader_client_->OnTransferSizeUpdated(transfer_size_diff);
264 } 264 }
265 265
266 if (response_body_consumer_handle_.is_valid()) {
267 // Send the data pipe on the first OnReadCompleted call.
268 url_loader_client_->OnStartLoadingResponseBody(
269 std::move(response_body_consumer_handle_));
270 response_body_consumer_handle_.reset();
271 }
272
266 if (is_using_io_buffer_not_from_writer_) { 273 if (is_using_io_buffer_not_from_writer_) {
267 // Couldn't allocate a buffer on the data pipe in OnWillRead. 274 // Couldn't allocate a buffer on the data pipe in OnWillRead.
268 DCHECK_EQ(0u, buffer_bytes_read_); 275 DCHECK_EQ(0u, buffer_bytes_read_);
269 buffer_bytes_read_ = bytes_read; 276 buffer_bytes_read_ = bytes_read;
270 if (!CopyReadDataToDataPipe(defer)) 277 if (!CopyReadDataToDataPipe(defer))
271 return false; 278 return false;
272 if (*defer) { 279 if (*defer) {
273 request()->LogBlockedBy("MojoAsyncResourceHandler"); 280 request()->LogBlockedBy("MojoAsyncResourceHandler");
274 did_defer_on_writing_ = true; 281 did_defer_on_writing_ = true;
275 } 282 }
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 mojom::URLLoaderAssociatedRequest mojo_request, 492 mojom::URLLoaderAssociatedRequest mojo_request,
486 mojom::URLLoaderClientAssociatedPtr url_loader_client) { 493 mojom::URLLoaderClientAssociatedPtr url_loader_client) {
487 binding_.Unbind(); 494 binding_.Unbind();
488 binding_.Bind(std::move(mojo_request)); 495 binding_.Bind(std::move(mojo_request));
489 binding_.set_connection_error_handler( 496 binding_.set_connection_error_handler(
490 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); 497 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this)));
491 url_loader_client_ = std::move(url_loader_client); 498 url_loader_client_ = std::move(url_loader_client);
492 } 499 }
493 500
494 } // namespace content 501 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698