Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: content/child/url_loader_client_impl.cc

Issue 2597873002: Move URLLoaderClientImpl to a separate file (Closed)
Patch Set: fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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::Bind(
32 mojom::URLLoaderClientAssociatedPtrInfo* client_ptr_info,
33 mojo::AssociatedGroup* associated_group) {
34 binding_.Bind(client_ptr_info, associated_group);
35 }
36
37 void URLLoaderClientImpl::OnReceiveResponse(
38 const ResourceResponseHead& response_head,
39 mojom::DownloadedTempFilePtr downloaded_file) {
40 has_received_response_ = true;
41 if (body_consumer_)
42 body_consumer_->Start();
43 downloaded_file_ = std::move(downloaded_file);
44 Dispatch(ResourceMsg_ReceivedResponse(request_id_, response_head));
45 }
46
47 void URLLoaderClientImpl::OnReceiveRedirect(
48 const net::RedirectInfo& redirect_info,
49 const ResourceResponseHead& response_head) {
50 DCHECK(!has_received_response_);
51 DCHECK(!body_consumer_);
52 Dispatch(
53 ResourceMsg_ReceivedRedirect(request_id_, redirect_info, response_head));
54 }
55
56 void URLLoaderClientImpl::OnDataDownloaded(int64_t data_len,
57 int64_t encoded_data_len) {
58 Dispatch(ResourceMsg_DataDownloaded(request_id_, data_len, encoded_data_len));
59 }
60
61 void URLLoaderClientImpl::OnTransferSizeUpdated(int32_t transfer_size_diff) {
62 resource_dispatcher_->OnTransferSizeUpdated(request_id_,
63 transfer_size_diff);
64 }
65
66 void URLLoaderClientImpl::OnStartLoadingResponseBody(
67 mojo::ScopedDataPipeConsumerHandle body) {
68 DCHECK(!body_consumer_);
69 body_consumer_ = new URLResponseBodyConsumer(
70 request_id_, resource_dispatcher_, std::move(body), task_runner_);
71 if (has_received_response_)
72 body_consumer_->Start();
73 }
74
75 void URLLoaderClientImpl::OnComplete(
76 const ResourceRequestCompletionStatus& status) {
77 if (!body_consumer_) {
78 Dispatch(ResourceMsg_RequestComplete(request_id_, status));
79 return;
80 }
81 body_consumer_->OnComplete(status);
82 }
83
84 void URLLoaderClientImpl::Dispatch(const IPC::Message& message) {
85 resource_dispatcher_->OnMessageReceived(message);
86 }
87
88 } // namespace content
OLDNEW
« no previous file with comments | « content/child/url_loader_client_impl.h ('k') | content/child/url_loader_client_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698