Index: content/common/throttling_url_loader.h |
diff --git a/content/common/throttling_url_loader.h b/content/common/throttling_url_loader.h |
index 98dc5e43d60868e61def6f97dbceb53ae96cea52..70de1697956f8cd199cb4a120093e292c7e96ee3 100644 |
--- a/content/common/throttling_url_loader.h |
+++ b/content/common/throttling_url_loader.h |
@@ -7,9 +7,11 @@ |
#include <memory> |
+#include "base/callback.h" |
#include "base/memory/ref_counted.h" |
#include "base/threading/thread_task_runner_handle.h" |
#include "content/common/content_export.h" |
+#include "content/common/possibly_associated_interface_ptr.h" |
#include "content/common/url_loader.mojom.h" |
#include "content/common/url_loader_factory.mojom.h" |
#include "content/public/common/url_loader_throttle.h" |
@@ -33,13 +35,30 @@ class CONTENT_EXPORT ThrottlingURLLoader : public mojom::URLLoaderClient, |
public: |
// |factory| and |client| must stay alive during the lifetime of the returned |
// object. |
+ // Please note that the request may not start immediately since it could be |
+ // deferred by throttles. |
static std::unique_ptr<ThrottlingURLLoader> CreateLoaderAndStart( |
mojom::URLLoaderFactory* factory, |
std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, |
int32_t routing_id, |
int32_t request_id, |
uint32_t options, |
- std::unique_ptr<ResourceRequest> url_request, |
+ const ResourceRequest& url_request, |
+ mojom::URLLoaderClient* client, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
+ base::ThreadTaskRunnerHandle::Get()); |
+ |
+ using StartLoaderCallback = |
+ base::OnceCallback<void(mojom::URLLoaderRequest request, |
+ mojom::URLLoaderClientPtr client)>; |
+ |
+ // Similar to the method above, but uses a |start_loader_callback| instead of |
+ // a mojom::URLLoaderFactory to start the loader. The callback must be safe |
+ // to call during the lifetime of the returned object. |
+ static std::unique_ptr<ThrottlingURLLoader> CreateLoaderAndStart( |
+ StartLoaderCallback start_loader_callback, |
+ std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, |
+ const ResourceRequest& url_request, |
mojom::URLLoaderClient* client, |
scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
base::ThreadTaskRunnerHandle::Get()); |
@@ -53,13 +72,25 @@ class CONTENT_EXPORT ThrottlingURLLoader : public mojom::URLLoaderClient, |
ThrottlingURLLoader(std::vector<std::unique_ptr<URLLoaderThrottle>> throttles, |
mojom::URLLoaderClient* client); |
+ // Either of the two sets of arguments below is valid but not both: |
+ // - |factory|, |routing_id|, |request_id| and |options|; |
+ // - |start_loader_callback|. |
void Start(mojom::URLLoaderFactory* factory, |
int32_t routing_id, |
int32_t request_id, |
uint32_t options, |
- std::unique_ptr<ResourceRequest> url_request, |
+ StartLoaderCallback start_loader_callback, |
+ const ResourceRequest& url_request, |
scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
+ void StartNow(mojom::URLLoaderFactory* factory, |
+ int32_t routing_id, |
+ int32_t request_id, |
+ uint32_t options, |
+ StartLoaderCallback start_loader_callback, |
+ const ResourceRequest& url_request, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
+ |
// mojom::URLLoaderClient implementation: |
void OnReceiveResponse(const ResourceResponseHead& response_head, |
const base::Optional<net::SSLInfo>& ssl_info, |
@@ -94,14 +125,15 @@ class CONTENT_EXPORT ThrottlingURLLoader : public mojom::URLLoaderClient, |
mojom::URLLoaderClient* forwarding_client_; |
mojo::Binding<mojom::URLLoaderClient> client_binding_; |
- mojom::URLLoaderAssociatedPtr url_loader_; |
+ PossiblyAssociatedInterfacePtr<mojom::URLLoader> url_loader_; |
struct StartInfo { |
StartInfo(mojom::URLLoaderFactory* in_url_loader_factory, |
int32_t in_routing_id, |
int32_t in_request_id, |
uint32_t in_options, |
- std::unique_ptr<ResourceRequest> in_url_request, |
+ StartLoaderCallback in_start_loader_callback, |
+ const ResourceRequest& in_url_request, |
scoped_refptr<base::SingleThreadTaskRunner> in_task_runner); |
~StartInfo(); |
@@ -109,7 +141,10 @@ class CONTENT_EXPORT ThrottlingURLLoader : public mojom::URLLoaderClient, |
int32_t routing_id; |
int32_t request_id; |
uint32_t options; |
- std::unique_ptr<ResourceRequest> url_request; |
+ |
+ StartLoaderCallback start_loader_callback; |
+ |
+ ResourceRequest url_request; |
// |task_runner_| is used to set up |client_binding_|. |
scoped_refptr<base::SingleThreadTaskRunner> task_runner; |
}; |