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

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

Issue 2919313004: Get rid of URLLoaderFactory in browser-side case (Closed)
Patch Set: . Created 3 years, 6 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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 }; 113 };
114 114
115 MojoAsyncResourceHandler::MojoAsyncResourceHandler( 115 MojoAsyncResourceHandler::MojoAsyncResourceHandler(
116 net::URLRequest* request, 116 net::URLRequest* request,
117 ResourceDispatcherHostImpl* rdh, 117 ResourceDispatcherHostImpl* rdh,
118 mojom::URLLoaderAssociatedRequest mojo_request, 118 mojom::URLLoaderAssociatedRequest mojo_request,
119 mojom::URLLoaderClientPtr url_loader_client, 119 mojom::URLLoaderClientPtr url_loader_client,
120 ResourceType resource_type) 120 ResourceType resource_type)
121 : ResourceHandler(request), 121 : ResourceHandler(request),
122 rdh_(rdh), 122 rdh_(rdh),
123 binding_(this, std::move(mojo_request)), 123 binding_(this),
124 handle_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL), 124 handle_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL),
125 url_loader_client_(std::move(url_loader_client)),
126 weak_factory_(this) { 125 weak_factory_(this) {
127 DCHECK(url_loader_client_); 126 Start(std::move(mojo_request), std::move(url_loader_client));
127
128 InitializeResourceBufferConstants(); 128 InitializeResourceBufferConstants();
129 // This unretained pointer is safe, because |binding_| is owned by |this| and
130 // the callback will never be called after |this| is destroyed.
131 binding_.set_connection_error_handler(
132 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this)));
133 129
134 if (IsResourceTypeFrame(resource_type)) { 130 if (IsResourceTypeFrame(resource_type)) {
135 GetRequestInfo()->set_on_transfer(base::Bind( 131 GetRequestInfo()->set_on_transfer(base::Bind(
136 &MojoAsyncResourceHandler::OnTransfer, weak_factory_.GetWeakPtr())); 132 &MojoAsyncResourceHandler::OnTransfer, weak_factory_.GetWeakPtr()));
137 } else { 133 } else {
138 GetRequestInfo()->set_on_transfer(base::Bind(&NotReached)); 134 GetRequestInfo()->set_on_transfer(base::Bind(&NotReached));
139 } 135 }
140 } 136 }
141 137
142 MojoAsyncResourceHandler::~MojoAsyncResourceHandler() { 138 MojoAsyncResourceHandler::~MojoAsyncResourceHandler() {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 request_complete_data.completion_time = base::TimeTicks::Now(); 455 request_complete_data.completion_time = base::TimeTicks::Now();
460 request_complete_data.encoded_data_length = 456 request_complete_data.encoded_data_length =
461 request()->GetTotalReceivedBytes(); 457 request()->GetTotalReceivedBytes();
462 request_complete_data.encoded_body_length = request()->GetRawBodyBytes(); 458 request_complete_data.encoded_body_length = request()->GetRawBodyBytes();
463 request_complete_data.decoded_body_length = total_written_bytes_; 459 request_complete_data.decoded_body_length = total_written_bytes_;
464 460
465 url_loader_client_->OnComplete(request_complete_data); 461 url_loader_client_->OnComplete(request_complete_data);
466 controller->Resume(); 462 controller->Resume();
467 } 463 }
468 464
465 void MojoAsyncResourceHandler::Start(
466 mojom::URLLoaderAssociatedRequest mojo_request,
467 mojom::URLLoaderClientPtr url_loader_client) {
468 DCHECK(!binding_.is_bound());
469
470 binding_.Bind(std::move(mojo_request));
471 // This unretained pointer is safe, because |binding_| is owned by |this| and
472 // the callback will never be called after |this| is destroyed.
473 binding_.set_connection_error_handler(
474 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this)));
475
476 url_loader_client_ = std::move(url_loader_client);
477 DCHECK(url_loader_client_);
478 }
479
469 bool MojoAsyncResourceHandler::CopyReadDataToDataPipe(bool* defer) { 480 bool MojoAsyncResourceHandler::CopyReadDataToDataPipe(bool* defer) {
470 while (buffer_bytes_read_ > 0) { 481 while (buffer_bytes_read_ > 0) {
471 scoped_refptr<net::IOBufferWithSize> dest; 482 scoped_refptr<net::IOBufferWithSize> dest;
472 if (!AllocateWriterIOBuffer(&dest, defer)) 483 if (!AllocateWriterIOBuffer(&dest, defer))
473 return false; 484 return false;
474 if (*defer) 485 if (*defer)
475 return true; 486 return true;
476 487
477 size_t copied_size = 488 size_t copied_size =
478 std::min(buffer_bytes_read_, static_cast<size_t>(dest->size())); 489 std::min(buffer_bytes_read_, static_cast<size_t>(dest->size()));
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK, 614 base::Bind(&MojoAsyncResourceHandler::OnUploadProgressACK,
604 weak_factory_.GetWeakPtr())); 615 weak_factory_.GetWeakPtr()));
605 } 616 }
606 617
607 void MojoAsyncResourceHandler::OnUploadProgressACK() { 618 void MojoAsyncResourceHandler::OnUploadProgressACK() {
608 if (upload_progress_tracker_) 619 if (upload_progress_tracker_)
609 upload_progress_tracker_->OnAckReceived(); 620 upload_progress_tracker_->OnAckReceived();
610 } 621 }
611 622
612 } // namespace content 623 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698