| OLD | NEW |
| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 MojoAsyncResourceHandler::MojoAsyncResourceHandler( | 106 MojoAsyncResourceHandler::MojoAsyncResourceHandler( |
| 107 net::URLRequest* request, | 107 net::URLRequest* request, |
| 108 ResourceDispatcherHostImpl* rdh, | 108 ResourceDispatcherHostImpl* rdh, |
| 109 mojom::URLLoaderAssociatedRequest mojo_request, | 109 mojom::URLLoaderAssociatedRequest mojo_request, |
| 110 mojom::URLLoaderClientAssociatedPtr url_loader_client) | 110 mojom::URLLoaderClientAssociatedPtr url_loader_client) |
| 111 : ResourceHandler(request), | 111 : ResourceHandler(request), |
| 112 rdh_(rdh), | 112 rdh_(rdh), |
| 113 binding_(this, std::move(mojo_request)), | 113 binding_(this, std::move(mojo_request)), |
| 114 url_loader_client_(std::move(url_loader_client)) { | 114 url_loader_client_(std::move(url_loader_client)), |
| 115 weak_factory_(this) { |
| 115 DCHECK(url_loader_client_); | 116 DCHECK(url_loader_client_); |
| 116 InitializeResourceBufferConstants(); | 117 InitializeResourceBufferConstants(); |
| 117 // This unretained pointer is safe, because |binding_| is owned by |this| and | 118 // This unretained pointer is safe, because |binding_| is owned by |this| and |
| 118 // the callback will never be called after |this| is destroyed. | 119 // the callback will never be called after |this| is destroyed. |
| 119 binding_.set_connection_error_handler( | 120 binding_.set_connection_error_handler( |
| 120 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); | 121 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); |
| 121 } | 122 } |
| 122 | 123 |
| 123 MojoAsyncResourceHandler::~MojoAsyncResourceHandler() { | 124 MojoAsyncResourceHandler::~MojoAsyncResourceHandler() { |
| 124 if (has_checked_for_sufficient_resources_) | 125 if (has_checked_for_sufficient_resources_) |
| 125 rdh_->FinishedWithResourcesForRequest(request()); | 126 rdh_->FinishedWithResourcesForRequest(request()); |
| 126 } | 127 } |
| 127 | 128 |
| 129 MojoAsyncResourceHandler::TransferCallback |
| 130 MojoAsyncResourceHandler::GetTransferCallback() { |
| 131 return base::Bind(&MojoAsyncResourceHandler::OnTransfer, |
| 132 weak_factory_.GetWeakPtr()); |
| 133 } |
| 134 |
| 128 bool MojoAsyncResourceHandler::OnRequestRedirected( | 135 bool MojoAsyncResourceHandler::OnRequestRedirected( |
| 129 const net::RedirectInfo& redirect_info, | 136 const net::RedirectInfo& redirect_info, |
| 130 ResourceResponse* response, | 137 ResourceResponse* response, |
| 131 bool* defer) { | 138 bool* defer) { |
| 132 // Unlike OnResponseStarted, OnRequestRedirected will NOT be preceded by | 139 // Unlike OnResponseStarted, OnRequestRedirected will NOT be preceded by |
| 133 // OnWillRead. | 140 // OnWillRead. |
| 134 DCHECK(!shared_writer_); | 141 DCHECK(!shared_writer_); |
| 135 | 142 |
| 136 *defer = true; | 143 *defer = true; |
| 137 request()->LogBlockedBy("MojoAsyncResourceHandler"); | 144 request()->LogBlockedBy("MojoAsyncResourceHandler"); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 void MojoAsyncResourceHandler::Cancel() { | 438 void MojoAsyncResourceHandler::Cancel() { |
| 432 const ResourceRequestInfoImpl* info = GetRequestInfo(); | 439 const ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 433 ResourceDispatcherHostImpl::Get()->CancelRequestFromRenderer( | 440 ResourceDispatcherHostImpl::Get()->CancelRequestFromRenderer( |
| 434 GlobalRequestID(info->GetChildID(), info->GetRequestID())); | 441 GlobalRequestID(info->GetChildID(), info->GetRequestID())); |
| 435 } | 442 } |
| 436 | 443 |
| 437 void MojoAsyncResourceHandler::ReportBadMessage(const std::string& error) { | 444 void MojoAsyncResourceHandler::ReportBadMessage(const std::string& error) { |
| 438 mojo::ReportBadMessage(error); | 445 mojo::ReportBadMessage(error); |
| 439 } | 446 } |
| 440 | 447 |
| 448 void MojoAsyncResourceHandler::OnTransfer( |
| 449 mojom::URLLoaderAssociatedRequest mojo_request, |
| 450 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 451 if (!url_loader_client) { |
| 452 // Resumes the request without transferring it to a new process. |
| 453 return; |
| 454 } |
| 455 |
| 456 binding_.Unbind(); |
| 457 binding_.Bind(std::move(mojo_request)); |
| 458 binding_.set_connection_error_handler( |
| 459 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); |
| 460 url_loader_client_ = std::move(url_loader_client); |
| 461 } |
| 462 |
| 441 } // namespace content | 463 } // namespace content |
| OLD | NEW |