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

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

Issue 2574143003: Implement upload progress handling in Mojo loading (Closed)
Patch Set: rebase Created 4 years 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 <algorithm>
yhirano 2016/12/16 08:47:56 Why is this needed?
tzik 2017/01/05 05:14:33 This is for std::min().
7 #include <utility> 8 #include <utility>
8 9
10 #include "base/bind.h"
9 #include "base/command_line.h" 11 #include "base/command_line.h"
10 #include "base/containers/hash_tables.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
yhirano 2016/12/16 08:47:56 +base/memory/ptr_util.h
tzik 2017/01/05 05:14:33 Done.
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "content/browser/loader/downloaded_temp_file_impl.h" 16 #include "content/browser/loader/downloaded_temp_file_impl.h"
16 #include "content/browser/loader/netlog_observer.h" 17 #include "content/browser/loader/netlog_observer.h"
17 #include "content/browser/loader/resource_controller.h" 18 #include "content/browser/loader/resource_controller.h"
18 #include "content/browser/loader/resource_dispatcher_host_impl.h" 19 #include "content/browser/loader/resource_dispatcher_host_impl.h"
19 #include "content/browser/loader/resource_request_info_impl.h" 20 #include "content/browser/loader/resource_request_info_impl.h"
21 #include "content/browser/loader/upload_progress_tracker.h"
20 #include "content/common/resource_request_completion_status.h" 22 #include "content/common/resource_request_completion_status.h"
21 #include "content/public/browser/global_request_id.h" 23 #include "content/public/browser/global_request_id.h"
22 #include "content/public/browser/resource_dispatcher_host_delegate.h" 24 #include "content/public/browser/resource_dispatcher_host_delegate.h"
23 #include "content/public/common/resource_response.h" 25 #include "content/public/common/resource_response.h"
24 #include "mojo/public/c/system/data_pipe.h" 26 #include "mojo/public/c/system/data_pipe.h"
25 #include "mojo/public/cpp/bindings/message.h" 27 #include "mojo/public/cpp/bindings/message.h"
26 #include "mojo/public/cpp/system/data_pipe.h" 28 #include "mojo/public/cpp/system/data_pipe.h"
27 #include "net/base/io_buffer.h" 29 #include "net/base/io_buffer.h"
28 #include "net/base/load_flags.h"
29 #include "net/base/mime_sniffer.h" 30 #include "net/base/mime_sniffer.h"
30 #include "net/url_request/redirect_info.h" 31 #include "net/url_request/redirect_info.h"
31 32
32 namespace content { 33 namespace content {
33 namespace { 34 namespace {
34 35
35 int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize; 36 int g_allocation_size = MojoAsyncResourceHandler::kDefaultAllocationSize;
36 37
37 // MimeTypeResourceHandler *implicitly* requires that the buffer size 38 // MimeTypeResourceHandler *implicitly* requires that the buffer size
38 // returned from OnWillRead should be larger than certain size. 39 // returned from OnWillRead should be larger than certain size.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // TODO(davidben): Is it necessary to pass the new first party URL for 150 // TODO(davidben): Is it necessary to pass the new first party URL for
150 // cookies? The only case where it can change is top-level navigation requests 151 // cookies? The only case where it can change is top-level navigation requests
151 // and hopefully those will eventually all be owned by the browser. It's 152 // and hopefully those will eventually all be owned by the browser. It's
152 // possible this is still needed while renderer-owned ones exist. 153 // possible this is still needed while renderer-owned ones exist.
153 url_loader_client_->OnReceiveRedirect(redirect_info, response->head); 154 url_loader_client_->OnReceiveRedirect(redirect_info, response->head);
154 return true; 155 return true;
155 } 156 }
156 157
157 bool MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response, 158 bool MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
158 bool* defer) { 159 bool* defer) {
160 if (upload_progress_tracker_) {
161 upload_progress_tracker_->OnUploadCompleted();
162 upload_progress_tracker_ = nullptr;
163 }
164
159 const ResourceRequestInfoImpl* info = GetRequestInfo(); 165 const ResourceRequestInfoImpl* info = GetRequestInfo();
160
161 if (rdh_->delegate()) { 166 if (rdh_->delegate()) {
162 rdh_->delegate()->OnResponseStarted(request(), info->GetContext(), 167 rdh_->delegate()->OnResponseStarted(request(), info->GetContext(),
163 response); 168 response);
164 } 169 }
165 170
166 NetLogObserver::PopulateResponseInfo(request(), response); 171 NetLogObserver::PopulateResponseInfo(request(), response);
167 172
168 response->head.request_start = request()->creation_time(); 173 response->head.request_start = request()->creation_time();
169 response->head.response_start = base::TimeTicks::Now(); 174 response->head.response_start = base::TimeTicks::Now();
170 sent_received_response_message_ = true; 175 sent_received_response_message_ = true;
171 176
172 mojom::DownloadedTempFilePtr downloaded_file_ptr; 177 mojom::DownloadedTempFilePtr downloaded_file_ptr;
173 if (!response->head.download_file_path.empty()) { 178 if (!response->head.download_file_path.empty()) {
174 downloaded_file_ptr = DownloadedTempFileImpl::Create(info->GetChildID(), 179 downloaded_file_ptr = DownloadedTempFileImpl::Create(info->GetChildID(),
175 info->GetRequestID()); 180 info->GetRequestID());
176 rdh_->RegisterDownloadedTempFile(info->GetChildID(), info->GetRequestID(), 181 rdh_->RegisterDownloadedTempFile(info->GetChildID(), info->GetRequestID(),
177 response->head.download_file_path); 182 response->head.download_file_path);
178 } 183 }
179 184
180 url_loader_client_->OnReceiveResponse(response->head, 185 url_loader_client_->OnReceiveResponse(response->head,
181 std::move(downloaded_file_ptr)); 186 std::move(downloaded_file_ptr));
182 return true; 187 return true;
183 } 188 }
184 189
185 bool MojoAsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) { 190 bool MojoAsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) {
191 if (GetRequestInfo()->is_upload_progress_enabled() &&
192 request()->has_upload()) {
193 upload_progress_tracker_ = base::MakeUnique<UploadProgressTracker>(
194 FROM_HERE,
195 base::BindRepeating(&MojoAsyncResourceHandler::SendUploadProgress,
196 base::Unretained(this)),
197 request());
198 }
199
186 return true; 200 return true;
187 } 201 }
188 202
189 bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, 203 bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
190 int* buf_size, 204 int* buf_size,
191 int min_size) { 205 int min_size) {
192 DCHECK_EQ(-1, min_size); 206 DCHECK_EQ(-1, min_size);
193 207
194 if (!CheckForSufficientResource()) 208 if (!CheckForSufficientResource())
195 return false; 209 return false;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 return result; 329 return result;
316 } 330 }
317 331
318 MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) { 332 MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) {
319 return mojo::EndWriteDataRaw(shared_writer_->writer(), written); 333 return mojo::EndWriteDataRaw(shared_writer_->writer(), written);
320 } 334 }
321 335
322 void MojoAsyncResourceHandler::OnResponseCompleted( 336 void MojoAsyncResourceHandler::OnResponseCompleted(
323 const net::URLRequestStatus& status, 337 const net::URLRequestStatus& status,
324 bool* defer) { 338 bool* defer) {
339 if (upload_progress_tracker_) {
340 upload_progress_tracker_->OnUploadCompleted();
341 upload_progress_tracker_ = nullptr;
342 }
343
325 shared_writer_ = nullptr; 344 shared_writer_ = nullptr;
326 buffer_ = nullptr; 345 buffer_ = nullptr;
327 handle_watcher_.Cancel(); 346 handle_watcher_.Cancel();
328 347
329 const ResourceRequestInfoImpl* info = GetRequestInfo(); 348 const ResourceRequestInfoImpl* info = GetRequestInfo();
330 349
331 // TODO(gavinp): Remove this CHECK when we figure out the cause of 350 // TODO(gavinp): Remove this CHECK when we figure out the cause of
332 // http://crbug.com/124680 . This check mirrors closely check in 351 // http://crbug.com/124680 . This check mirrors closely check in
333 // WebURLLoaderImpl::OnCompletedRequest that routes this message to a WebCore 352 // WebURLLoaderImpl::OnCompletedRequest that routes this message to a WebCore
334 // ResourceHandleInternal which asserts on its state and crashes. By crashing 353 // ResourceHandleInternal which asserts on its state and crashes. By crashing
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 void MojoAsyncResourceHandler::OnTransfer( 476 void MojoAsyncResourceHandler::OnTransfer(
458 mojom::URLLoaderAssociatedRequest mojo_request, 477 mojom::URLLoaderAssociatedRequest mojo_request,
459 mojom::URLLoaderClientAssociatedPtr url_loader_client) { 478 mojom::URLLoaderClientAssociatedPtr url_loader_client) {
460 binding_.Unbind(); 479 binding_.Unbind();
461 binding_.Bind(std::move(mojo_request)); 480 binding_.Bind(std::move(mojo_request));
462 binding_.set_connection_error_handler( 481 binding_.set_connection_error_handler(
463 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); 482 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this)));
464 url_loader_client_ = std::move(url_loader_client); 483 url_loader_client_ = std::move(url_loader_client);
465 } 484 }
466 485
486 void MojoAsyncResourceHandler::OnUploadProgressACK() {
487 if (upload_progress_tracker_)
488 upload_progress_tracker_->OnAckReceived();
489 }
490
491 void MojoAsyncResourceHandler::SendUploadProgress(int64_t current_position,
492 int64_t total_size) {
493 url_loader_client_->OnUploadProgress(
494 current_position, total_size,
495 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK,
496 weak_factory_.GetWeakPtr()));
497 }
498
467 } // namespace content 499 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698