Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/child/url_loader_client_impl.h" | |
| 6 | |
| 7 #include "base/callback.h" | |
| 8 #include "base/single_thread_task_runner.h" | |
| 9 #include "content/child/resource_dispatcher.h" | |
| 10 #include "content/child/url_response_body_consumer.h" | |
| 11 #include "content/common/resource_messages.h" | |
| 12 #include "mojo/public/cpp/bindings/associated_group.h" | |
| 13 #include "net/url_request/redirect_info.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 URLLoaderClientImpl::URLLoaderClientImpl( | |
| 18 int request_id, | |
| 19 ResourceDispatcher* resource_dispatcher, | |
| 20 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | |
| 21 : binding_(this), | |
| 22 request_id_(request_id), | |
| 23 resource_dispatcher_(resource_dispatcher), | |
| 24 is_destroyed_(new SharedBoolean()), | |
| 25 task_runner_(std::move(task_runner)) {} | |
| 26 | |
| 27 URLLoaderClientImpl::~URLLoaderClientImpl() { | |
| 28 if (body_consumer_) | |
| 29 body_consumer_->Cancel(); | |
| 30 is_destroyed_->set(true); | |
|
kinuko
2016/12/22 07:54:48
Looks like this shared var is not yet necessary
yhirano
2016/12/22 08:03:31
Done.
| |
| 31 } | |
| 32 | |
| 33 void URLLoaderClientImpl::OnReceiveResponse( | |
| 34 const ResourceResponseHead& response_head, | |
| 35 mojom::DownloadedTempFilePtr downloaded_file) { | |
| 36 has_received_response_ = true; | |
| 37 if (body_consumer_) | |
| 38 body_consumer_->Start(); | |
| 39 downloaded_file_ = std::move(downloaded_file); | |
| 40 Dispatch(ResourceMsg_ReceivedResponse(request_id_, response_head)); | |
| 41 } | |
| 42 | |
| 43 void URLLoaderClientImpl::OnReceiveRedirect( | |
| 44 const net::RedirectInfo& redirect_info, | |
| 45 const ResourceResponseHead& response_head) { | |
| 46 DCHECK(!has_received_response_); | |
| 47 DCHECK(!body_consumer_); | |
| 48 Dispatch( | |
| 49 ResourceMsg_ReceivedRedirect(request_id_, redirect_info, response_head)); | |
| 50 } | |
| 51 | |
| 52 void URLLoaderClientImpl::OnDataDownloaded(int64_t data_len, | |
| 53 int64_t encoded_data_len) { | |
| 54 Dispatch(ResourceMsg_DataDownloaded(request_id_, data_len, encoded_data_len)); | |
| 55 } | |
| 56 | |
| 57 void URLLoaderClientImpl::OnTransferSizeUpdated(int32_t transfer_size_diff) { | |
| 58 resource_dispatcher_->OnTransferSizeUpdated(request_id_, | |
| 59 transfer_size_diff); | |
| 60 } | |
| 61 | |
| 62 void URLLoaderClientImpl::OnStartLoadingResponseBody( | |
| 63 mojo::ScopedDataPipeConsumerHandle body) { | |
| 64 DCHECK(!body_consumer_); | |
| 65 body_consumer_ = new URLResponseBodyConsumer( | |
| 66 request_id_, resource_dispatcher_, std::move(body), task_runner_); | |
| 67 if (has_received_response_) | |
| 68 body_consumer_->Start(); | |
| 69 } | |
| 70 | |
| 71 void URLLoaderClientImpl::OnComplete( | |
| 72 const ResourceRequestCompletionStatus& status) { | |
| 73 if (!body_consumer_) { | |
| 74 Dispatch(ResourceMsg_RequestComplete(request_id_, status)); | |
| 75 return; | |
| 76 } | |
| 77 body_consumer_->OnComplete(status); | |
| 78 } | |
| 79 | |
| 80 void URLLoaderClientImpl::Bind( | |
| 81 mojom::URLLoaderClientAssociatedPtrInfo* client_ptr_info, | |
| 82 mojo::AssociatedGroup* associated_group) { | |
| 83 binding_.Bind(client_ptr_info, associated_group); | |
| 84 } | |
| 85 | |
| 86 void URLLoaderClientImpl::Dispatch(const IPC::Message& message) { | |
| 87 resource_dispatcher_->OnMessageReceived(message); | |
| 88 } | |
| 89 | |
| 90 } // namespace content | |
| OLD | NEW |