Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "content/common/url_loader_factory.mojom.h" | 10 #include "content/common/url_loader_factory.mojom.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 class ResourceContext; | 14 class ResourceContext; |
| 15 struct ResourceRequest; | 15 struct ResourceRequest; |
| 16 | 16 |
| 17 using LoaderFactoryCallback = | 17 using URLLoaderCallback = base::OnceCallback<void(mojom::URLLoader*)>; |
| 18 base::OnceCallback<void(mojom::URLLoaderFactory*)>; | |
| 19 | 18 |
| 20 // An instance of this class is a per-request object and kept around during | 19 // An instance of this class is a per-request object and kept around during |
| 21 // the lifetime of a request (including multiple redirect legs) on IO thread. | 20 // the lifetime of a request (including multiple redirect legs) on IO thread. |
| 22 class CONTENT_EXPORT URLLoaderRequestHandler { | 21 class CONTENT_EXPORT URLLoaderRequestHandler { |
| 23 public: | 22 public: |
| 24 URLLoaderRequestHandler() = default; | 23 URLLoaderRequestHandler() = default; |
| 25 virtual ~URLLoaderRequestHandler() = default; | 24 virtual ~URLLoaderRequestHandler() = default; |
| 26 | 25 |
| 27 // Calls |callback| with non-null factory if this handler can handle | 26 // Calls |callback| with a non-null URLLoader that is not started yet |
| 28 // the request, calls it with nullptr otherwise. | 27 // if this handler can handle the request, calls it with nullptr otherwise. |
| 29 // Some implementation notes: | 28 // Some implementation notes: |
| 30 // 1) The returned pointer needs to be valid only until a single | 29 // 1) The caller will immediately call Start() method on the returned ptr |
| 31 // CreateLoaderAndStart call is made, and it is okay to do CHECK(false) for | 30 // if it is non-null. |
| 32 // any subsequent calls. | 31 // 2) The implementor is not supposed to set up and return URLLoader until |
| 33 // 2) The implementor is not supposed to set up and return URLLoaderFactory | 32 // it finds out that the handler is really going to handle the request. |
| 34 // until it finds out that the handler is really going to handle the | 33 virtual void MaybeCreateLoader(const ResourceRequest& resource_request, |
|
jam
2017/06/05 19:39:24
I'm probably missing something, but why can't this
michaeln
2017/06/05 21:52:39
There is a use case for a non-started loaders.
Lo
jam
2017/06/06 00:07:45
This could also be implemented by using a callback
jam
2017/06/06 00:55:40
(I'm guessing I'm missing the obvious reason here,
| |
| 35 // request. (For example ServiceWorker's request handler would not need to | 34 ResourceContext* resource_context, |
| 36 // call the callback until it gets response from SW, and it may still | 35 URLLoaderCallback callback) = 0; |
| 37 // call the callback with nullptr if it turns out that it needs to fallback | |
| 38 // to the network.) | |
| 39 virtual void MaybeCreateLoaderFactory(const ResourceRequest& resource_request, | |
| 40 ResourceContext* resource_context, | |
| 41 LoaderFactoryCallback callback) = 0; | |
| 42 }; | 36 }; |
| 43 | 37 |
| 44 } // namespace content | 38 } // namespace content |
| 45 | 39 |
| 46 #endif // CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ | 40 #endif // CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ |
| OLD | NEW |