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

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

Issue 2566943002: Dispatch transfer size update notification on mojo-loading (Closed)
Patch Set: fix 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 <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"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 bool MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response, 157 bool MojoAsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
158 bool* defer) { 158 bool* defer) {
159 const ResourceRequestInfoImpl* info = GetRequestInfo(); 159 const ResourceRequestInfoImpl* info = GetRequestInfo();
160 160
161 if (rdh_->delegate()) { 161 if (rdh_->delegate()) {
162 rdh_->delegate()->OnResponseStarted(request(), info->GetContext(), 162 rdh_->delegate()->OnResponseStarted(request(), info->GetContext(),
163 response); 163 response);
164 } 164 }
165 165
166 NetLogObserver::PopulateResponseInfo(request(), response); 166 NetLogObserver::PopulateResponseInfo(request(), response);
167 response->head.encoded_data_length = request()->raw_header_size();
168 reported_total_received_bytes_ = response->head.encoded_data_length;
167 169
168 response->head.request_start = request()->creation_time(); 170 response->head.request_start = request()->creation_time();
169 response->head.response_start = base::TimeTicks::Now(); 171 response->head.response_start = base::TimeTicks::Now();
170 sent_received_response_message_ = true; 172 sent_received_response_message_ = true;
171 173
172 mojom::DownloadedTempFilePtr downloaded_file_ptr; 174 mojom::DownloadedTempFilePtr downloaded_file_ptr;
173 if (!response->head.download_file_path.empty()) { 175 if (!response->head.download_file_path.empty()) {
174 downloaded_file_ptr = DownloadedTempFileImpl::Create(info->GetChildID(), 176 downloaded_file_ptr = DownloadedTempFileImpl::Create(info->GetChildID(),
175 info->GetRequestID()); 177 info->GetRequestID());
176 rdh_->RegisterDownloadedTempFile(info->GetChildID(), info->GetRequestID(), 178 rdh_->RegisterDownloadedTempFile(info->GetChildID(), info->GetRequestID(),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return true; 240 return true;
239 } 241 }
240 242
241 bool MojoAsyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) { 243 bool MojoAsyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
242 DCHECK_GE(bytes_read, 0); 244 DCHECK_GE(bytes_read, 0);
243 DCHECK(buffer_); 245 DCHECK(buffer_);
244 246
245 if (!bytes_read) 247 if (!bytes_read)
246 return true; 248 return true;
247 249
250 const ResourceRequestInfoImpl* info = GetRequestInfo();
251 if (info->ShouldReportRawHeaders()) {
252 auto transfer_size_diff = CalculateRecentlyReceivedBytes();
253 if (transfer_size_diff > 0)
254 url_loader_client_->OnTransferSizeUpdated(transfer_size_diff);
255 }
256
248 if (is_using_io_buffer_not_from_writer_) { 257 if (is_using_io_buffer_not_from_writer_) {
249 // Couldn't allocate a buffer on the data pipe in OnWillRead. 258 // Couldn't allocate a buffer on the data pipe in OnWillRead.
250 DCHECK_EQ(0u, buffer_bytes_read_); 259 DCHECK_EQ(0u, buffer_bytes_read_);
251 buffer_bytes_read_ = bytes_read; 260 buffer_bytes_read_ = bytes_read;
252 if (!CopyReadDataToDataPipe(defer)) 261 if (!CopyReadDataToDataPipe(defer))
253 return false; 262 return false;
254 if (*defer) { 263 if (*defer) {
255 request()->LogBlockedBy("MojoAsyncResourceHandler"); 264 request()->LogBlockedBy("MojoAsyncResourceHandler");
256 did_defer_on_writing_ = true; 265 did_defer_on_writing_ = true;
257 } 266 }
258 return true; 267 return true;
259 } 268 }
260 269
261 if (EndWrite(bytes_read) != MOJO_RESULT_OK) 270 if (EndWrite(bytes_read) != MOJO_RESULT_OK)
262 return false; 271 return false;
263 // Allocate a buffer for the next OnWillRead call here, because OnWillRead 272 // Allocate a buffer for the next OnWillRead call here, because OnWillRead
264 // doesn't have |defer| parameter. 273 // doesn't have |defer| parameter.
265 if (!AllocateWriterIOBuffer(&buffer_, defer)) 274 if (!AllocateWriterIOBuffer(&buffer_, defer))
266 return false; 275 return false;
267 if (*defer) { 276 if (*defer) {
268 request()->LogBlockedBy("MojoAsyncResourceHandler"); 277 request()->LogBlockedBy("MojoAsyncResourceHandler");
269 did_defer_on_writing_ = true; 278 did_defer_on_writing_ = true;
270 } 279 }
271 return true; 280 return true;
272 } 281 }
273 282
274 void MojoAsyncResourceHandler::OnDataDownloaded(int bytes_downloaded) { 283 void MojoAsyncResourceHandler::OnDataDownloaded(int bytes_downloaded) {
275 int64_t total_received_bytes = request()->GetTotalReceivedBytes(); 284 url_loader_client_->OnDataDownloaded(bytes_downloaded,
276 int64_t bytes_to_report = 285 CalculateRecentlyReceivedBytes());
277 total_received_bytes - reported_total_received_bytes_;
278 reported_total_received_bytes_ = total_received_bytes;
279 DCHECK_LE(0, bytes_to_report);
280
281 url_loader_client_->OnDataDownloaded(bytes_downloaded, bytes_to_report);
282 } 286 }
283 287
284 void MojoAsyncResourceHandler::FollowRedirect() { 288 void MojoAsyncResourceHandler::FollowRedirect() {
285 if (!request()->status().is_success()) { 289 if (!request()->status().is_success()) {
286 DVLOG(1) << "FollowRedirect for invalid request"; 290 DVLOG(1) << "FollowRedirect for invalid request";
287 return; 291 return;
288 } 292 }
289 if (!did_defer_on_redirect_) { 293 if (!did_defer_on_redirect_) {
290 DVLOG(1) << "Malformed FollowRedirect request"; 294 DVLOG(1) << "Malformed FollowRedirect request";
291 ReportBadMessage("Malformed FollowRedirect request"); 295 ReportBadMessage("Malformed FollowRedirect request");
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 request()->LogUnblocked(); 447 request()->LogUnblocked();
444 controller()->Resume(); 448 controller()->Resume();
445 } 449 }
446 450
447 void MojoAsyncResourceHandler::Cancel() { 451 void MojoAsyncResourceHandler::Cancel() {
448 const ResourceRequestInfoImpl* info = GetRequestInfo(); 452 const ResourceRequestInfoImpl* info = GetRequestInfo();
449 ResourceDispatcherHostImpl::Get()->CancelRequestFromRenderer( 453 ResourceDispatcherHostImpl::Get()->CancelRequestFromRenderer(
450 GlobalRequestID(info->GetChildID(), info->GetRequestID())); 454 GlobalRequestID(info->GetChildID(), info->GetRequestID()));
451 } 455 }
452 456
457 int64_t MojoAsyncResourceHandler::CalculateRecentlyReceivedBytes() {
458 int64_t total_received_bytes = request()->GetTotalReceivedBytes();
459 int64_t bytes_to_report =
460 total_received_bytes - reported_total_received_bytes_;
461 reported_total_received_bytes_ = total_received_bytes;
462 DCHECK_LE(0, bytes_to_report);
463 return bytes_to_report;
464 }
465
453 void MojoAsyncResourceHandler::ReportBadMessage(const std::string& error) { 466 void MojoAsyncResourceHandler::ReportBadMessage(const std::string& error) {
454 mojo::ReportBadMessage(error); 467 mojo::ReportBadMessage(error);
455 } 468 }
456 469
457 void MojoAsyncResourceHandler::OnTransfer( 470 void MojoAsyncResourceHandler::OnTransfer(
458 mojom::URLLoaderAssociatedRequest mojo_request, 471 mojom::URLLoaderAssociatedRequest mojo_request,
459 mojom::URLLoaderClientAssociatedPtr url_loader_client) { 472 mojom::URLLoaderClientAssociatedPtr url_loader_client) {
460 binding_.Unbind(); 473 binding_.Unbind();
461 binding_.Bind(std::move(mojo_request)); 474 binding_.Bind(std::move(mojo_request));
462 binding_.set_connection_error_handler( 475 binding_.set_connection_error_handler(
463 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); 476 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this)));
464 url_loader_client_ = std::move(url_loader_client); 477 url_loader_client_ = std::move(url_loader_client);
465 } 478 }
466 479
467 } // namespace content 480 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/mojo_async_resource_handler.h ('k') | content/browser/loader/test_url_loader_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698