blob: 7497bbee7183bf2900e70d5735d2f1837b8bf9db [file] [log] [blame]
yhiranof6c76cf2016-12-22 11:42:181// 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
John Abd-El-Malek6b56ef712017-10-21 22:52:465#ifndef CONTENT_RENDERER_LOADER_URL_LOADER_CLIENT_IMPL_H_
6#define CONTENT_RENDERER_LOADER_URL_LOADER_CLIENT_IMPL_H_
yhiranof6c76cf2016-12-22 11:42:187
8#include <stdint.h>
yhirano6a0e9c72016-12-27 08:31:049#include <vector>
yhiranof6c76cf2016-12-22 11:42:1810#include "base/callback_forward.h"
11#include "base/memory/ref_counted.h"
yhirano6a0e9c72016-12-27 08:31:0412#include "base/memory/weak_ptr.h"
yhiranof6c76cf2016-12-22 11:42:1813#include "content/common/content_export.h"
mmenke680c2142017-07-05 19:08:5614#include "content/public/common/url_loader.mojom.h"
yhiranof6c76cf2016-12-22 11:42:1815#include "ipc/ipc_message.h"
arthursonzogni3a4ca9f2017-12-07 17:58:3416#include "mojo/public/cpp/bindings/binding.h"
yhiranof6c76cf2016-12-22 11:42:1817#include "mojo/public/cpp/system/data_pipe.h"
18
19namespace base {
20class SingleThreadTaskRunner;
21} // namespace base
22
yhiranof6c76cf2016-12-22 11:42:1823namespace net {
24struct RedirectInfo;
25} // namespace net
26
Takashi Toyoshima8f988532017-11-13 07:32:3727namespace network {
Takashi Toyoshimaaa278662017-11-20 11:11:2628struct URLLoaderCompletionStatus;
Takashi Toyoshima8f988532017-11-13 07:32:3729} // namespace network
30
yhiranof6c76cf2016-12-22 11:42:1831namespace content {
32class ResourceDispatcher;
33class URLResponseBodyConsumer;
yhiranof6c76cf2016-12-22 11:42:1834struct ResourceResponseHead;
35
36class CONTENT_EXPORT URLLoaderClientImpl final : public mojom::URLLoaderClient {
37 public:
38 URLLoaderClientImpl(int request_id,
39 ResourceDispatcher* resource_dispatcher,
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
41 ~URLLoaderClientImpl() override;
42
yhirano6a0e9c72016-12-27 08:31:0443 // Sets |is_deferred_|. From now, the received messages are not dispatched
44 // to clients until UnsetDefersLoading is called.
45 void SetDefersLoading();
46
47 // Unsets |is_deferred_|.
48 void UnsetDefersLoading();
49
50 // Disaptches the messages received after SetDefersLoading is called.
51 void FlushDeferredMessages();
52
arthursonzogni3a4ca9f2017-12-07 17:58:3453 // Binds this instance to the given URLLoaderClient endpoints so that it can
54 // start getting the mojo calls from the given loader. This is used only for
55 // the main resource loading when NavigationMojoResponse and/or NetworkService
56 // is enabled. Otherwise (in regular subresource loading cases) |this| is not
57 // bound to a client request, but used via ThrottlingURLLoader to get client
58 // upcalls from the loader.
59 void Bind(mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints);
60
yhiranof6c76cf2016-12-22 11:42:1861 // mojom::URLLoaderClient implementation
yhirano6f57b502017-03-01 03:44:2062 void OnReceiveResponse(const ResourceResponseHead& response_head,
jam33d897e2017-04-14 21:28:4663 const base::Optional<net::SSLInfo>& ssl_info,
yhirano6f57b502017-03-01 03:44:2064 mojom::DownloadedTempFilePtr downloaded_file) override;
yhiranof6c76cf2016-12-22 11:42:1865 void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
66 const ResourceResponseHead& response_head) override;
67 void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override;
tzikbedcbce2017-01-24 15:08:0568 void OnUploadProgress(int64_t current_position,
69 int64_t total_size,
tzikc2007562017-04-25 07:48:2470 OnUploadProgressCallback ack_callback) override;
yhirano2a525f92017-01-18 08:16:4671 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override;
yhiranof6c76cf2016-12-22 11:42:1872 void OnTransferSizeUpdated(int32_t transfer_size_diff) override;
73 void OnStartLoadingResponseBody(
74 mojo::ScopedDataPipeConsumerHandle body) override;
Takashi Toyoshimaaa278662017-11-20 11:11:2675 void OnComplete(const network::URLLoaderCompletionStatus& status) override;
yhiranof6c76cf2016-12-22 11:42:1876
yhirano6a0e9c72016-12-27 08:31:0477 private:
yhiranoe45a888f2017-04-14 01:24:2078 bool NeedsStoringMessage() const;
79 void StoreAndDispatch(const IPC::Message& message);
arthursonzogni3a4ca9f2017-12-07 17:58:3480 void OnConnectionClosed();
yhiranof6c76cf2016-12-22 11:42:1881
yhiranof6c76cf2016-12-22 11:42:1882 scoped_refptr<URLResponseBodyConsumer> body_consumer_;
yhirano6f57b502017-03-01 03:44:2083 mojom::DownloadedTempFilePtr downloaded_file_;
yhirano6a0e9c72016-12-27 08:31:0484 std::vector<IPC::Message> deferred_messages_;
yhiranof6c76cf2016-12-22 11:42:1885 const int request_id_;
86 bool has_received_response_ = false;
arthursonzogni3a4ca9f2017-12-07 17:58:3487 bool has_received_complete_ = false;
yhirano6a0e9c72016-12-27 08:31:0488 bool is_deferred_ = false;
89 int32_t accumulated_transfer_size_diff_during_deferred_ = 0;
yhiranof6c76cf2016-12-22 11:42:1890 ResourceDispatcher* const resource_dispatcher_;
91 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
arthursonzogni3a4ca9f2017-12-07 17:58:3492
93 // Used in NavigationMojoResponse and NetworkService.
94 mojom::URLLoaderPtr url_loader_;
95 mojo::Binding<mojom::URLLoaderClient> url_loader_client_binding_;
96
yhirano6a0e9c72016-12-27 08:31:0497 base::WeakPtrFactory<URLLoaderClientImpl> weak_factory_;
yhiranof6c76cf2016-12-22 11:42:1898};
99
100} // namespace content
101
John Abd-El-Malek6b56ef712017-10-21 22:52:46102#endif // CONTENT_RENDERER_LOADER_URL_LOADER_CLIENT_IMPL_H_