| 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))); |
| 122 |
| 123 GetRequestInfo()->set_on_transfer(base::Bind( |
| 124 &MojoAsyncResourceHandler::OnTransfer, weak_factory_.GetWeakPtr())); |
| 121 } | 125 } |
| 122 | 126 |
| 123 MojoAsyncResourceHandler::~MojoAsyncResourceHandler() { | 127 MojoAsyncResourceHandler::~MojoAsyncResourceHandler() { |
| 124 if (has_checked_for_sufficient_resources_) | 128 if (has_checked_for_sufficient_resources_) |
| 125 rdh_->FinishedWithResourcesForRequest(request()); | 129 rdh_->FinishedWithResourcesForRequest(request()); |
| 126 } | 130 } |
| 127 | 131 |
| 128 bool MojoAsyncResourceHandler::OnRequestRedirected( | 132 bool MojoAsyncResourceHandler::OnRequestRedirected( |
| 129 const net::RedirectInfo& redirect_info, | 133 const net::RedirectInfo& redirect_info, |
| 130 ResourceResponse* response, | 134 ResourceResponse* response, |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 void MojoAsyncResourceHandler::Cancel() { | 435 void MojoAsyncResourceHandler::Cancel() { |
| 432 const ResourceRequestInfoImpl* info = GetRequestInfo(); | 436 const ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 433 ResourceDispatcherHostImpl::Get()->CancelRequestFromRenderer( | 437 ResourceDispatcherHostImpl::Get()->CancelRequestFromRenderer( |
| 434 GlobalRequestID(info->GetChildID(), info->GetRequestID())); | 438 GlobalRequestID(info->GetChildID(), info->GetRequestID())); |
| 435 } | 439 } |
| 436 | 440 |
| 437 void MojoAsyncResourceHandler::ReportBadMessage(const std::string& error) { | 441 void MojoAsyncResourceHandler::ReportBadMessage(const std::string& error) { |
| 438 mojo::ReportBadMessage(error); | 442 mojo::ReportBadMessage(error); |
| 439 } | 443 } |
| 440 | 444 |
| 445 void MojoAsyncResourceHandler::OnTransfer( |
| 446 mojom::URLLoaderAssociatedRequest mojo_request, |
| 447 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 448 binding_.Unbind(); |
| 449 binding_.Bind(std::move(mojo_request)); |
| 450 binding_.set_connection_error_handler( |
| 451 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); |
| 452 url_loader_client_ = std::move(url_loader_client); |
| 453 } |
| 454 |
| 441 } // namespace content | 455 } // namespace content |
| OLD | NEW |