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

Side by Side Diff: content/child/throttling_url_loader.h

Issue 2914423002: Network service: move URLLoaderThrottle and ThrottlingURLLoader. (Closed)
Patch Set: Created 3 years, 6 months 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
« no previous file with comments | « content/child/resource_dispatcher.cc ('k') | content/child/throttling_url_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 #ifndef CONTENT_CHILD_THROTTLING_URL_LOADER_H_
6 #define CONTENT_CHILD_THROTTLING_URL_LOADER_H_
7
8 #include <memory>
9
10 #include "content/common/content_export.h"
11 #include "content/common/url_loader.mojom.h"
12 #include "content/common/url_loader_factory.mojom.h"
13 #include "content/public/child/url_loader_throttle.h"
14 #include "mojo/public/cpp/bindings/binding.h"
15
16 namespace content {
17
18 namespace mojom {
19 class URLLoaderFactory;
20 }
21
22 // ThrottlingURLLoader is a wrapper around the mojom::URLLoader[Factory]
23 // interfaces. It applies a list of URLLoaderThrottle instances which could
24 // defer, resume or cancel the URL loading.
25 class CONTENT_EXPORT ThrottlingURLLoader : public mojom::URLLoaderClient,
26 public URLLoaderThrottle::Delegate {
27 public:
28 // |factory| and |client| must stay alive during the lifetime of the returned
29 // object.
30 static std::unique_ptr<ThrottlingURLLoader> CreateLoaderAndStart(
31 mojom::URLLoaderFactory* factory,
32 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
33 int32_t routing_id,
34 int32_t request_id,
35 uint32_t options,
36 std::unique_ptr<ResourceRequest> url_request,
37 mojom::URLLoaderClient* client);
38
39 ~ThrottlingURLLoader() override;
40
41 void FollowRedirect();
42 void SetPriority(net::RequestPriority priority, int32_t intra_priority_value);
43
44 private:
45 ThrottlingURLLoader(std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
46 mojom::URLLoaderClient* client);
47
48 void Start(mojom::URLLoaderFactory* factory,
49 int32_t routing_id,
50 int32_t request_id,
51 uint32_t options,
52 std::unique_ptr<ResourceRequest> url_request);
53
54 // mojom::URLLoaderClient implementation:
55 void OnReceiveResponse(const ResourceResponseHead& response_head,
56 const base::Optional<net::SSLInfo>& ssl_info,
57 mojom::DownloadedTempFilePtr downloaded_file) override;
58 void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
59 const ResourceResponseHead& response_head) override;
60 void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override;
61 void OnUploadProgress(int64_t current_position,
62 int64_t total_size,
63 OnUploadProgressCallback ack_callback) override;
64 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override;
65 void OnTransferSizeUpdated(int32_t transfer_size_diff) override;
66 void OnStartLoadingResponseBody(
67 mojo::ScopedDataPipeConsumerHandle body) override;
68 void OnComplete(const ResourceRequestCompletionStatus& status) override;
69
70 // URLLoaderThrottle::Delegate:
71 void CancelWithError(int error_code) override;
72 void Resume() override;
73
74 enum DeferredStage {
75 DEFERRED_NONE,
76 DEFERRED_START,
77 DEFERRED_REDIRECT,
78 DEFERRED_RESPONSE
79 };
80 DeferredStage deferred_stage_ = DEFERRED_NONE;
81 bool cancelled_by_throttle_ = false;
82
83 std::unique_ptr<URLLoaderThrottle> throttle_;
84
85 mojom::URLLoaderClient* forwarding_client_;
86 mojo::Binding<mojom::URLLoaderClient> client_binding_;
87
88 mojom::URLLoaderAssociatedPtr url_loader_;
89
90 // Set if start is deferred.
91 mojom::URLLoaderFactory* url_loader_factory_ = nullptr;
92 int32_t routing_id_ = -1;
93 int32_t request_id_ = -1;
94 uint32_t options_ = mojom::kURLLoadOptionNone;
95 std::unique_ptr<ResourceRequest> url_request_;
96
97 // Set if either response or redirect is deferred.
98 ResourceResponseHead response_head_;
99
100 // Set if response is deferred.
101 base::Optional<net::SSLInfo> ssl_info_;
102 mojom::DownloadedTempFilePtr downloaded_file_;
103
104 // Set if redirect is deferred.
105 net::RedirectInfo redirect_info_;
106
107 // Set if request is deferred and SetPriority() is called.
108 bool set_priority_cached_ = false;
109 net::RequestPriority priority_ = net::MINIMUM_PRIORITY;
110 int32_t intra_priority_value_ = 0;
111
112 DISALLOW_COPY_AND_ASSIGN(ThrottlingURLLoader);
113 };
114
115 } // namespace content
116
117 #endif // CONTENT_CHILD_THROTTLING_URL_LOADER_H_
OLDNEW
« no previous file with comments | « content/child/resource_dispatcher.cc ('k') | content/child/throttling_url_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698