Chromium Code Reviews| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 mojom::DownloadedTempFilePtr downloaded_file_ptr; | 174 mojom::DownloadedTempFilePtr downloaded_file_ptr; |
| 175 if (!response->head.download_file_path.empty()) { | 175 if (!response->head.download_file_path.empty()) { |
| 176 downloaded_file_ptr = DownloadedTempFileImpl::Create(info->GetChildID(), | 176 downloaded_file_ptr = DownloadedTempFileImpl::Create(info->GetChildID(), |
| 177 info->GetRequestID()); | 177 info->GetRequestID()); |
| 178 rdh_->RegisterDownloadedTempFile(info->GetChildID(), info->GetRequestID(), | 178 rdh_->RegisterDownloadedTempFile(info->GetChildID(), info->GetRequestID(), |
| 179 response->head.download_file_path); | 179 response->head.download_file_path); |
| 180 } | 180 } |
| 181 | 181 |
| 182 url_loader_client_->OnReceiveResponse(response->head, | 182 url_loader_client_->OnReceiveResponse(response->head, |
| 183 std::move(downloaded_file_ptr)); | 183 std::move(downloaded_file_ptr)); |
| 184 | |
| 185 net::IOBufferWithSize* metadata = GetResponseMetadata(request()); | |
| 186 if (metadata) { | |
| 187 const uint8_t* ptr = reinterpret_cast<const uint8_t*>(metadata->data()); | |
|
mmenke
2017/01/17 18:39:57
nit: Maybe ptr -> data? data isn't exactly a det
yhirano
2017/01/18 06:22:42
Done.
| |
| 188 | |
| 189 url_loader_client_->OnReceiveCachedMetadata( | |
| 190 std::vector<uint8_t>(ptr, ptr + metadata->size())); | |
|
mmenke
2017/01/13 15:55:04
Not sure how big this tends to be, but can we some
dcheng
2017/01/14 11:30:17
This could be an interesting Mojo feature request.
yhirano
2017/01/16 05:40:41
How about adding net::IOBufferWithSize support to
mmenke
2017/01/17 18:39:57
It's a weird enough type that I don't think that's
yhirano
2017/01/18 06:22:42
OK, let's leave it be. We'll be able to remove the
| |
| 191 } | |
|
mmenke
2017/01/17 18:40:52
Also, include <vector> (Same probably goes for bot
yhirano
2017/01/18 06:22:42
Done.
| |
| 184 return true; | 192 return true; |
| 185 } | 193 } |
| 186 | 194 |
| 187 bool MojoAsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) { | 195 bool MojoAsyncResourceHandler::OnWillStart(const GURL& url, bool* defer) { |
| 188 return true; | 196 return true; |
| 189 } | 197 } |
| 190 | 198 |
| 191 bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 199 bool MojoAsyncResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 192 int* buf_size, | 200 int* buf_size, |
| 193 int min_size) { | 201 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); | 324 shared_writer_->writer(), data, available, MOJO_WRITE_DATA_FLAG_NONE); |
| 317 if (result == MOJO_RESULT_OK) | 325 if (result == MOJO_RESULT_OK) |
| 318 *available = std::min(*available, static_cast<uint32_t>(kMaxChunkSize)); | 326 *available = std::min(*available, static_cast<uint32_t>(kMaxChunkSize)); |
| 319 return result; | 327 return result; |
| 320 } | 328 } |
| 321 | 329 |
| 322 MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) { | 330 MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) { |
| 323 return mojo::EndWriteDataRaw(shared_writer_->writer(), written); | 331 return mojo::EndWriteDataRaw(shared_writer_->writer(), written); |
| 324 } | 332 } |
| 325 | 333 |
| 334 net::IOBufferWithSize* MojoAsyncResourceHandler::GetResponseMetadata( | |
| 335 net::URLRequest* request) { | |
| 336 return request->response_info().metadata.get(); | |
| 337 } | |
| 338 | |
| 326 void MojoAsyncResourceHandler::OnResponseCompleted( | 339 void MojoAsyncResourceHandler::OnResponseCompleted( |
| 327 const net::URLRequestStatus& status, | 340 const net::URLRequestStatus& status, |
| 328 bool* defer) { | 341 bool* defer) { |
| 329 shared_writer_ = nullptr; | 342 shared_writer_ = nullptr; |
| 330 buffer_ = nullptr; | 343 buffer_ = nullptr; |
| 331 handle_watcher_.Cancel(); | 344 handle_watcher_.Cancel(); |
| 332 | 345 |
| 333 const ResourceRequestInfoImpl* info = GetRequestInfo(); | 346 const ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 334 | 347 |
| 335 // TODO(gavinp): Remove this CHECK when we figure out the cause of | 348 // 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, | 484 mojom::URLLoaderAssociatedRequest mojo_request, |
| 472 mojom::URLLoaderClientAssociatedPtr url_loader_client) { | 485 mojom::URLLoaderClientAssociatedPtr url_loader_client) { |
| 473 binding_.Unbind(); | 486 binding_.Unbind(); |
| 474 binding_.Bind(std::move(mojo_request)); | 487 binding_.Bind(std::move(mojo_request)); |
| 475 binding_.set_connection_error_handler( | 488 binding_.set_connection_error_handler( |
| 476 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); | 489 base::Bind(&MojoAsyncResourceHandler::Cancel, base::Unretained(this))); |
| 477 url_loader_client_ = std::move(url_loader_client); | 490 url_loader_client_ = std::move(url_loader_client); |
| 478 } | 491 } |
| 479 | 492 |
| 480 } // namespace content | 493 } // namespace content |
| OLD | NEW |