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

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 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "content/browser/loader/downloaded_temp_file_impl.h" 15 #include "content/browser/loader/downloaded_temp_file_impl.h"
16 #include "content/browser/loader/netlog_observer.h" 16 #include "content/browser/loader/netlog_observer.h"
17 #include "content/browser/loader/resource_controller.h" 17 #include "content/browser/loader/resource_controller.h"
18 #include "content/browser/loader/resource_dispatcher_host_impl.h" 18 #include "content/browser/loader/resource_dispatcher_host_impl.h"
19 #include "content/browser/loader/resource_request_info_impl.h" 19 #include "content/browser/loader/resource_request_info_impl.h"
20 #include "content/common/resource_request_completion_status.h" 20 #include "content/common/resource_request_completion_status.h"
21 #include "content/public/browser/global_request_id.h" 21 #include "content/public/browser/global_request_id.h"
22 #include "content/public/browser/resource_dispatcher_host_delegate.h" 22 #include "content/public/browser/resource_dispatcher_host_delegate.h"
23 #include "content/public/common/resource_response.h" 23 #include "content/public/common/resource_response.h"
24 #include "mojo/public/c/system/data_pipe.h" 24 #include "mojo/public/c/system/data_pipe.h"
25 #include "mojo/public/cpp/bindings/message.h" 25 #include "mojo/public/cpp/bindings/message.h"
26 #include "mojo/public/cpp/system/data_pipe.h"
27 #include "net/base/io_buffer.h" 26 #include "net/base/io_buffer.h"
28 #include "net/base/load_flags.h" 27 #include "net/base/load_flags.h"
29 #include "net/base/mime_sniffer.h" 28 #include "net/base/mime_sniffer.h"
30 #include "net/url_request/redirect_info.h" 29 #include "net/url_request/redirect_info.h"
31 30
32 namespace content { 31 namespace content {
33 namespace { 32 namespace {
34 33
35 int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize; 34 int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize;
36 35
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 mojom::DownloadedTempFilePtr downloaded_file_ptr; 173 mojom::DownloadedTempFilePtr downloaded_file_ptr;
175 if (!response->head.download_file_path.empty()) { 174 if (!response->head.download_file_path.empty()) {
176 downloaded_file_ptr = DownloadedTempFileImpl::Create(info->GetChildID(), 175 downloaded_file_ptr = DownloadedTempFileImpl::Create(info->GetChildID(),
177 info->GetRequestID()); 176 info->GetRequestID());
178 rdh_->RegisterDownloadedTempFile(info->GetChildID(), info->GetRequestID(), 177 rdh_->RegisterDownloadedTempFile(info->GetChildID(), info->GetRequestID(),
179 response->head.download_file_path); 178 response->head.download_file_path);
180 } 179 }
181 180
182 url_loader_client_->OnReceiveResponse(response->head, 181 url_loader_client_->OnReceiveResponse(response->head,
183 std::move(downloaded_file_ptr)); 182 std::move(downloaded_file_ptr));
183
184 if (data_pipe_consumer_handle_.is_valid()) {
185 // OnStartLoadingResponseBody waited for OnReceiveResponse. Now it can be
186 // sent.
187 url_loader_client_->OnStartLoadingResponseBody(
188 std::move(data_pipe_consumer_handle_));
mmenke 2017/01/17 16:13:57 std::move leaves the original unique_ptr pointer i
dcheng 2017/01/17 23:20:18 Note that std::unique_ptr's moved from state is ac
yhirano 2017/01/18 09:10:45 Done (in OnReadCompleted), though I'm not sure if
189 }
190
184 return true; 191 return true;
185 } 192 }
186 193
187 bool MojoAsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) { 194 bool MojoAsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) {
188 return true; 195 return true;
189 } 196 }
190 197
191 bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, 198 bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
192 int* buf_size, 199 int* buf_size,
193 int min_size) { 200 int min_size) {
194 DCHECK_EQ(-1, min_size); 201 DCHECK_EQ(-1, min_size);
195 202
196 if (!CheckForSufficientResource()) 203 if (!CheckForSufficientResource())
197 return false; 204 return false;
198 205
199 if (!shared_writer_) { 206 if (!shared_writer_) {
200 MojoCreateDataPipeOptions options; 207 MojoCreateDataPipeOptions options;
201 options.struct_size = sizeof(MojoCreateDataPipeOptions); 208 options.struct_size = sizeof(MojoCreateDataPipeOptions);
202 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; 209 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
203 options.element_num_bytes = 1; 210 options.element_num_bytes = 1;
204 options.capacity_num_bytes = g_allocation_size; 211 options.capacity_num_bytes = g_allocation_size;
205 mojo::DataPipe data_pipe(options); 212 mojo::DataPipe data_pipe(options);
206 213
207 url_loader_client_->OnStartLoadingResponseBody( 214 if (sent_received_response_message_) {
208 std::move(data_pipe.consumer_handle)); 215 // OnResponseStarted has already been sent. It's OK to send this message.
216 url_loader_client_->OnStartLoadingResponseBody(
217 std::move(data_pipe.consumer_handle));
mmenke 2017/01/17 16:13:57 Is there any significant perf penalty with just al
Randy Smith (Not in Mondays) 2017/01/17 16:45:10 If you wanted to switch course, I don't currently
yhirano 2017/01/18 09:10:45 I found that moving this to OnReadCompleted simpli
218 } else {
219 // To keep the message ordering, store the handle for a while.
220 data_pipe_consumer_handle_ = std::move(data_pipe.consumer_handle);
221 }
209 if (!data_pipe.producer_handle.is_valid()) 222 if (!data_pipe.producer_handle.is_valid())
210 return false; 223 return false;
211 224
212 shared_writer_ = new SharedWriter(std::move(data_pipe.producer_handle)); 225 shared_writer_ = new SharedWriter(std::move(data_pipe.producer_handle));
213 handle_watcher_.Start(shared_writer_->writer(), MOJO_HANDLE_SIGNAL_WRITABLE, 226 handle_watcher_.Start(shared_writer_->writer(), MOJO_HANDLE_SIGNAL_WRITABLE,
214 base::Bind(&MojoAsyncResourceHandler::OnWritable, 227 base::Bind(&MojoAsyncResourceHandler::OnWritable,
215 base::Unretained(this))); 228 base::Unretained(this)));
216 229
217 bool defer = false; 230 bool defer = false;
218 scoped_refptr<net::IOBufferWithSize> buffer; 231 scoped_refptr<net::IOBufferWithSize> buffer;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 mojom::URLLoaderAssociatedRequest mojo_request, 484 mojom::URLLoaderAssociatedRequest mojo_request,
472 mojom::URLLoaderClientAssociatedPtr url_loader_client) { 485 mojom::URLLoaderClientAssociatedPtr url_loader_client) {
473 binding_.Unbind(); 486 binding_.Unbind();
474 binding_.Bind(std::move(mojo_request)); 487 binding_.Bind(std::move(mojo_request));
475 binding_.set_connection_error_handler( 488 binding_.set_connection_error_handler(
476 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); 489 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this)));
477 url_loader_client_ = std::move(url_loader_client); 490 url_loader_client_ = std::move(url_loader_client);
478 } 491 }
479 492
480 } // namespace content 493 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698