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

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

Issue 2924723002: Network service: SafeBrowsing check for frame-resources from browser. (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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_COMMON_THROTTLING_URL_LOADER_H_ 5 #ifndef CONTENT_COMMON_THROTTLING_URL_LOADER_H_
6 #define CONTENT_COMMON_THROTTLING_URL_LOADER_H_ 6 #define CONTENT_COMMON_THROTTLING_URL_LOADER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
12 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "content/common/possibly_associated_interface_ptr.h"
13 #include "content/common/url_loader.mojom.h" 15 #include "content/common/url_loader.mojom.h"
14 #include "content/common/url_loader_factory.mojom.h" 16 #include "content/common/url_loader_factory.mojom.h"
15 #include "content/public/common/url_loader_throttle.h" 17 #include "content/public/common/url_loader_throttle.h"
16 #include "mojo/public/cpp/bindings/binding.h" 18 #include "mojo/public/cpp/bindings/binding.h"
17 19
18 namespace base { 20 namespace base {
19 class SingleThreadTaskRunner; 21 class SingleThreadTaskRunner;
20 } 22 }
21 23
22 namespace content { 24 namespace content {
23 25
24 namespace mojom { 26 namespace mojom {
25 class URLLoaderFactory; 27 class URLLoaderFactory;
26 } 28 }
27 29
28 // ThrottlingURLLoader is a wrapper around the mojom::URLLoader[Factory] 30 // ThrottlingURLLoader is a wrapper around the mojom::URLLoader[Factory]
29 // interfaces. It applies a list of URLLoaderThrottle instances which could 31 // interfaces. It applies a list of URLLoaderThrottle instances which could
30 // defer, resume or cancel the URL loading. 32 // defer, resume or cancel the URL loading.
31 class CONTENT_EXPORT ThrottlingURLLoader : public mojom::URLLoaderClient, 33 class CONTENT_EXPORT ThrottlingURLLoader : public mojom::URLLoaderClient,
32 public URLLoaderThrottle::Delegate { 34 public URLLoaderThrottle::Delegate {
33 public: 35 public:
34 // |factory| and |client| must stay alive during the lifetime of the returned 36 // |factory| and |client| must stay alive during the lifetime of the returned
35 // object. 37 // object.
38 // Please note that the request may not start immediately since it could be
39 // deferred by throttles.
36 static std::unique_ptr<ThrottlingURLLoader> CreateLoaderAndStart( 40 static std::unique_ptr<ThrottlingURLLoader> CreateLoaderAndStart(
37 mojom::URLLoaderFactory* factory, 41 mojom::URLLoaderFactory* factory,
38 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, 42 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
39 int32_t routing_id, 43 int32_t routing_id,
40 int32_t request_id, 44 int32_t request_id,
41 uint32_t options, 45 uint32_t options,
42 std::unique_ptr<ResourceRequest> url_request, 46 const ResourceRequest& url_request,
43 mojom::URLLoaderClient* client, 47 mojom::URLLoaderClient* client,
44 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation, 48 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
45 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 49 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
46 base::ThreadTaskRunnerHandle::Get()); 50 base::ThreadTaskRunnerHandle::Get());
47 51
52 using StartLoaderCallback =
53 base::OnceCallback<void(mojom::URLLoaderRequest request,
54 mojom::URLLoaderClientPtr client)>;
55
56 // Similar to the method above, but uses a |start_loader_callback| instead of
57 // a mojom::URLLoaderFactory to start the loader. The callback must be safe
58 // to call during the lifetime of the returned object.
59 static std::unique_ptr<ThrottlingURLLoader> CreateLoaderAndStart(
60 StartLoaderCallback start_loader_callback,
61 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
62 const ResourceRequest& url_request,
63 mojom::URLLoaderClient* client,
64 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
65 base::ThreadTaskRunnerHandle::Get());
66
48 ~ThrottlingURLLoader() override; 67 ~ThrottlingURLLoader() override;
49 68
50 void FollowRedirect(); 69 void FollowRedirect();
51 void SetPriority(net::RequestPriority priority, int32_t intra_priority_value); 70 void SetPriority(net::RequestPriority priority, int32_t intra_priority_value);
52 71
53 private: 72 private:
54 ThrottlingURLLoader( 73 ThrottlingURLLoader(
55 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, 74 std::vector<std::unique_ptr<URLLoaderThrottle>> throttles,
56 mojom::URLLoaderClient* client, 75 mojom::URLLoaderClient* client,
57 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation); 76 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation);
58 77
78 // Either of the two sets of arguments below is valid but not both:
79 // - |factory|, |routing_id|, |request_id| and |options|;
80 // - |start_loader_callback|.
59 void Start(mojom::URLLoaderFactory* factory, 81 void Start(mojom::URLLoaderFactory* factory,
60 int32_t routing_id, 82 int32_t routing_id,
61 int32_t request_id, 83 int32_t request_id,
62 uint32_t options, 84 uint32_t options,
63 std::unique_ptr<ResourceRequest> url_request, 85 StartLoaderCallback start_loader_callback,
86 const ResourceRequest& url_request,
64 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 87 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
65 88
89 void StartNow(mojom::URLLoaderFactory* factory,
90 int32_t routing_id,
91 int32_t request_id,
92 uint32_t options,
93 StartLoaderCallback start_loader_callback,
94 const ResourceRequest& url_request,
95 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
96
66 // mojom::URLLoaderClient implementation: 97 // mojom::URLLoaderClient implementation:
67 void OnReceiveResponse(const ResourceResponseHead& response_head, 98 void OnReceiveResponse(const ResourceResponseHead& response_head,
68 const base::Optional<net::SSLInfo>& ssl_info, 99 const base::Optional<net::SSLInfo>& ssl_info,
69 mojom::DownloadedTempFilePtr downloaded_file) override; 100 mojom::DownloadedTempFilePtr downloaded_file) override;
70 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, 101 void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
71 const ResourceResponseHead& response_head) override; 102 const ResourceResponseHead& response_head) override;
72 void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override; 103 void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override;
73 void OnUploadProgress(int64_t current_position, 104 void OnUploadProgress(int64_t current_position,
74 int64_t total_size, 105 int64_t total_size,
75 OnUploadProgressCallback ack_callback) override; 106 OnUploadProgressCallback ack_callback) override;
(...skipping 14 matching lines...) Expand all
90 DEFERRED_RESPONSE 121 DEFERRED_RESPONSE
91 }; 122 };
92 DeferredStage deferred_stage_ = DEFERRED_NONE; 123 DeferredStage deferred_stage_ = DEFERRED_NONE;
93 bool cancelled_by_throttle_ = false; 124 bool cancelled_by_throttle_ = false;
94 125
95 std::unique_ptr<URLLoaderThrottle> throttle_; 126 std::unique_ptr<URLLoaderThrottle> throttle_;
96 127
97 mojom::URLLoaderClient* forwarding_client_; 128 mojom::URLLoaderClient* forwarding_client_;
98 mojo::Binding<mojom::URLLoaderClient> client_binding_; 129 mojo::Binding<mojom::URLLoaderClient> client_binding_;
99 130
100 mojom::URLLoaderAssociatedPtr url_loader_; 131 PossiblyAssociatedInterfacePtr<mojom::URLLoader> url_loader_;
101 132
102 struct StartInfo { 133 struct StartInfo {
103 StartInfo(mojom::URLLoaderFactory* in_url_loader_factory, 134 StartInfo(mojom::URLLoaderFactory* in_url_loader_factory,
104 int32_t in_routing_id, 135 int32_t in_routing_id,
105 int32_t in_request_id, 136 int32_t in_request_id,
106 uint32_t in_options, 137 uint32_t in_options,
107 std::unique_ptr<ResourceRequest> in_url_request, 138 StartLoaderCallback in_start_loader_callback,
139 const ResourceRequest& in_url_request,
108 scoped_refptr<base::SingleThreadTaskRunner> in_task_runner); 140 scoped_refptr<base::SingleThreadTaskRunner> in_task_runner);
109 ~StartInfo(); 141 ~StartInfo();
110 142
111 mojom::URLLoaderFactory* url_loader_factory; 143 mojom::URLLoaderFactory* url_loader_factory;
112 int32_t routing_id; 144 int32_t routing_id;
113 int32_t request_id; 145 int32_t request_id;
114 uint32_t options; 146 uint32_t options;
115 std::unique_ptr<ResourceRequest> url_request; 147
148 StartLoaderCallback start_loader_callback;
149
150 ResourceRequest url_request;
116 // |task_runner_| is used to set up |client_binding_|. 151 // |task_runner_| is used to set up |client_binding_|.
117 scoped_refptr<base::SingleThreadTaskRunner> task_runner; 152 scoped_refptr<base::SingleThreadTaskRunner> task_runner;
118 }; 153 };
119 // Set if start is deferred. 154 // Set if start is deferred.
120 std::unique_ptr<StartInfo> start_info_; 155 std::unique_ptr<StartInfo> start_info_;
121 156
122 struct ResponseInfo { 157 struct ResponseInfo {
123 ResponseInfo(const ResourceResponseHead& in_response_head, 158 ResponseInfo(const ResourceResponseHead& in_response_head,
124 const base::Optional<net::SSLInfo>& in_ssl_info, 159 const base::Optional<net::SSLInfo>& in_ssl_info,
125 mojom::DownloadedTempFilePtr in_downloaded_file); 160 mojom::DownloadedTempFilePtr in_downloaded_file);
(...skipping 29 matching lines...) Expand all
155 std::unique_ptr<PriorityInfo> priority_info_; 190 std::unique_ptr<PriorityInfo> priority_info_;
156 191
157 const net::MutableNetworkTrafficAnnotationTag traffic_annotation_; 192 const net::MutableNetworkTrafficAnnotationTag traffic_annotation_;
158 193
159 DISALLOW_COPY_AND_ASSIGN(ThrottlingURLLoader); 194 DISALLOW_COPY_AND_ASSIGN(ThrottlingURLLoader);
160 }; 195 };
161 196
162 } // namespace content 197 } // namespace content
163 198
164 #endif // CONTENT_COMMON_THROTTLING_URL_LOADER_H_ 199 #endif // CONTENT_COMMON_THROTTLING_URL_LOADER_H_
OLDNEW
« no previous file with comments | « content/common/possibly_associated_interface_ptr.h ('k') | content/common/throttling_url_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698