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 task_runner_(std::move(task_runner)) {} | |
25 | |
26 URLLoaderClientImpl::~URLLoaderClientImpl() { | |
27 if (body_consumer_) | |
28 body_consumer_->Cancel(); | |
29 } | |
30 | |
31 void URLLoaderClientImpl::OnReceiveResponse( | |
32 const ResourceResponseHead& response_head, | |
33 mojom::DownloadedTempFilePtr downloaded_file) { | |
34 has_received_response_ = true; | |
35 if (body_consumer_) | |
36 body_consumer_->Start(); | |
37 downloaded_file_ = std::move(downloaded_file); | |
38 Dispatch(ResourceMsg_ReceivedResponse(request_id_, response_head)); | |
39 } | |
40 | |
41 void URLLoaderClientImpl::OnReceiveRedirect( | |
42 const net::RedirectInfo& redirect_info, | |
43 const ResourceResponseHead& response_head) { | |
44 DCHECK(!has_received_response_); | |
45 DCHECK(!body_consumer_); | |
46 Dispatch( | |
47 ResourceMsg_ReceivedRedirect(request_id_, redirect_info, response_head)); | |
48 } | |
49 | |
50 void URLLoaderClientImpl::OnDataDownloaded(int64_t data_len, | |
51 int64_t encoded_data_len) { | |
52 Dispatch(ResourceMsg_DataDownloaded(request_id_, data_len, encoded_data_len)); | |
53 } | |
54 | |
55 void URLLoaderClientImpl::OnTransferSizeUpdated(int32_t transfer_size_diff) { | |
56 resource_dispatcher_->OnTransferSizeUpdated(request_id_, | |
57 transfer_size_diff); | |
58 } | |
59 | |
60 void URLLoaderClientImpl::OnStartLoadingResponseBody( | |
61 mojo::ScopedDataPipeConsumerHandle body) { | |
62 DCHECK(!body_consumer_); | |
63 body_consumer_ = new URLResponseBodyConsumer( | |
64 request_id_, resource_dispatcher_, std::move(body), task_runner_); | |
65 if (has_received_response_) | |
66 body_consumer_->Start(); | |
67 } | |
68 | |
69 void URLLoaderClientImpl::OnComplete( | |
70 const ResourceRequestCompletionStatus& status) { | |
71 if (!body_consumer_) { | |
72 Dispatch(ResourceMsg_RequestComplete(request_id_, status)); | |
73 return; | |
74 } | |
75 body_consumer_->OnComplete(status); | |
76 } | |
77 | |
78 void URLLoaderClientImpl::Bind( | |
79 mojom::URLLoaderClientAssociatedPtrInfo* client_ptr_info, | |
80 mojo::AssociatedGroup* associated_group) { | |
81 binding_.Bind(client_ptr_info, associated_group); | |
82 } | |
kinuko
2016/12/22 08:12:37
nit: match the method order as in .h
yhirano
2016/12/22 08:18:15
Done.
| |
83 | |
84 void URLLoaderClientImpl::Dispatch(const IPC::Message& message) { | |
85 resource_dispatcher_->OnMessageReceived(message); | |
86 } | |
87 | |
88 } // namespace content | |
OLD | NEW |