| 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 #include <vector> |
| 8 | 9 |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/containers/hash_tables.h" | 11 #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" |
| 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" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 mojom::DownloadedTempFilePtr downloaded_file_ptr; | 175 mojom::DownloadedTempFilePtr downloaded_file_ptr; |
| 175 if (!response->head.download_file_path.empty()) { | 176 if (!response->head.download_file_path.empty()) { |
| 176 downloaded_file_ptr = DownloadedTempFileImpl::Create(info->GetChildID(), | 177 downloaded_file_ptr = DownloadedTempFileImpl::Create(info->GetChildID(), |
| 177 info->GetRequestID()); | 178 info->GetRequestID()); |
| 178 rdh_->RegisterDownloadedTempFile(info->GetChildID(), info->GetRequestID(), | 179 rdh_->RegisterDownloadedTempFile(info->GetChildID(), info->GetRequestID(), |
| 179 response->head.download_file_path); | 180 response->head.download_file_path); |
| 180 } | 181 } |
| 181 | 182 |
| 182 url_loader_client_->OnReceiveResponse(response->head, | 183 url_loader_client_->OnReceiveResponse(response->head, |
| 183 std::move(downloaded_file_ptr)); | 184 std::move(downloaded_file_ptr)); |
| 185 |
| 186 net::IOBufferWithSize* metadata = GetResponseMetadata(request()); |
| 187 if (metadata) { |
| 188 const uint8_t* data = reinterpret_cast<const uint8_t*>(metadata->data()); |
| 189 |
| 190 url_loader_client_->OnReceiveCachedMetadata( |
| 191 std::vector<uint8_t>(data, data + metadata->size())); |
| 192 } |
| 184 return true; | 193 return true; |
| 185 } | 194 } |
| 186 | 195 |
| 187 bool MojoAsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) { | 196 bool MojoAsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) { |
| 188 return true; | 197 return true; |
| 189 } | 198 } |
| 190 | 199 |
| 191 bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 200 bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 192 int* buf_size, | 201 int* buf_size, |
| 193 int min_size) { | 202 int min_size) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 shared_writer_->writer(), data, available, MOJO_WRITE_DATA_FLAG_NONE); | 325 shared_writer_->writer(), data, available, MOJO_WRITE_DATA_FLAG_NONE); |
| 317 if (result == MOJO_RESULT_OK) | 326 if (result == MOJO_RESULT_OK) |
| 318 *available = std::min(*available, static_cast<uint32_t>(kMaxChunkSize)); | 327 *available = std::min(*available, static_cast<uint32_t>(kMaxChunkSize)); |
| 319 return result; | 328 return result; |
| 320 } | 329 } |
| 321 | 330 |
| 322 MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) { | 331 MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) { |
| 323 return mojo::EndWriteDataRaw(shared_writer_->writer(), written); | 332 return mojo::EndWriteDataRaw(shared_writer_->writer(), written); |
| 324 } | 333 } |
| 325 | 334 |
| 335 net::IOBufferWithSize* MojoAsyncResourceHandler::GetResponseMetadata( |
| 336 net::URLRequest* request) { |
| 337 return request->response_info().metadata.get(); |
| 338 } |
| 339 |
| 326 void MojoAsyncResourceHandler::OnResponseCompleted( | 340 void MojoAsyncResourceHandler::OnResponseCompleted( |
| 327 const net::URLRequestStatus& status, | 341 const net::URLRequestStatus& status, |
| 328 bool* defer) { | 342 bool* defer) { |
| 329 shared_writer_ = nullptr; | 343 shared_writer_ = nullptr; |
| 330 buffer_ = nullptr; | 344 buffer_ = nullptr; |
| 331 handle_watcher_.Cancel(); | 345 handle_watcher_.Cancel(); |
| 332 | 346 |
| 333 const ResourceRequestInfoImpl* info = GetRequestInfo(); | 347 const ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 334 | 348 |
| 335 // TODO(gavinp): Remove this CHECK when we figure out the cause of | 349 // TODO(gavinp): Remove this CHECK when we figure out the cause of |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 mojom::URLLoaderAssociatedRequest mojo_request, | 485 mojom::URLLoaderAssociatedRequest mojo_request, |
| 472 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 486 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 473 binding_.Unbind(); | 487 binding_.Unbind(); |
| 474 binding_.Bind(std::move(mojo_request)); | 488 binding_.Bind(std::move(mojo_request)); |
| 475 binding_.set_connection_error_handler( | 489 binding_.set_connection_error_handler( |
| 476 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); | 490 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); |
| 477 url_loader_client_ = std::move(url_loader_client); | 491 url_loader_client_ = std::move(url_loader_client); |
| 478 } | 492 } |
| 479 | 493 |
| 480 } // namespace content | 494 } // namespace content |
| OLD | NEW |