2019-05-11 00:14:48 +02:00
|
|
|
// Copyright (c) 2019 The Chromium Embedded Framework Authors. Portions
|
|
|
|
// Copyright (c) 2018 The Chromium Authors. All rights reserved. Use of this
|
|
|
|
// source code is governed by a BSD-style license that can be found in the
|
|
|
|
// LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_NET_SERVICE_URL_LOADER_FACTORY_GETTER_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_NET_SERVICE_URL_LOADER_FACTORY_GETTER_H_
|
|
|
|
|
|
|
|
#include "base/memory/ref_counted.h"
|
2021-11-10 22:57:31 +01:00
|
|
|
#include "base/task/sequenced_task_runner.h"
|
|
|
|
#include "base/task/sequenced_task_runner_helpers.h"
|
2019-05-11 00:14:48 +02:00
|
|
|
#include "services/network/public/mojom/url_loader_factory.mojom.h"
|
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class BrowserContext;
|
|
|
|
class RenderFrameHost;
|
|
|
|
} // namespace content
|
|
|
|
|
|
|
|
namespace network {
|
|
|
|
class SharedURLLoaderFactory;
|
2020-02-10 18:10:17 +01:00
|
|
|
class PendingSharedURLLoaderFactory;
|
2019-05-11 00:14:48 +02:00
|
|
|
} // namespace network
|
|
|
|
|
|
|
|
namespace net_service {
|
|
|
|
|
|
|
|
struct URLLoaderFactoryGetterDeleter;
|
|
|
|
|
|
|
|
// Helper class for retrieving a URLLoaderFactory that can be bound on any
|
|
|
|
// thread, and that correctly handles proxied requests.
|
|
|
|
class URLLoaderFactoryGetter
|
|
|
|
: public base::RefCountedThreadSafe<URLLoaderFactoryGetter,
|
|
|
|
URLLoaderFactoryGetterDeleter> {
|
|
|
|
public:
|
2021-12-06 21:40:25 +01:00
|
|
|
URLLoaderFactoryGetter(const URLLoaderFactoryGetter&) = delete;
|
|
|
|
URLLoaderFactoryGetter& operator=(const URLLoaderFactoryGetter&) = delete;
|
|
|
|
|
2019-05-11 00:14:48 +02:00
|
|
|
// Create a URLLoaderFactoryGetter on the UI thread.
|
|
|
|
// |render_frame_host| may be nullptr.
|
|
|
|
static scoped_refptr<URLLoaderFactoryGetter> Create(
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
content::BrowserContext* browser_context);
|
|
|
|
|
|
|
|
// Create a SharedURLLoaderFactory on the current thread. All future calls
|
|
|
|
// to this method must be on the same thread.
|
|
|
|
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory();
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class base::DeleteHelper<URLLoaderFactoryGetter>;
|
|
|
|
friend class base::RefCountedThreadSafe<URLLoaderFactoryGetter,
|
|
|
|
URLLoaderFactoryGetterDeleter>;
|
|
|
|
friend struct URLLoaderFactoryGetterDeleter;
|
|
|
|
|
2022-03-26 02:12:30 +01:00
|
|
|
URLLoaderFactoryGetter(std::unique_ptr<network::PendingSharedURLLoaderFactory>
|
|
|
|
loader_factory_info,
|
|
|
|
mojo::PendingRemote<network::mojom::URLLoaderFactory>
|
|
|
|
proxy_factory_remote,
|
|
|
|
mojo::PendingReceiver<network::mojom::URLLoaderFactory>
|
|
|
|
proxy_factory_receiver);
|
2019-05-11 00:14:48 +02:00
|
|
|
~URLLoaderFactoryGetter();
|
|
|
|
|
|
|
|
void DeleteOnCorrectThread() const;
|
|
|
|
|
2020-02-10 18:10:17 +01:00
|
|
|
std::unique_ptr<network::PendingSharedURLLoaderFactory> loader_factory_info_;
|
2019-05-11 00:14:48 +02:00
|
|
|
scoped_refptr<network::SharedURLLoaderFactory> lazy_factory_;
|
2022-03-26 02:12:30 +01:00
|
|
|
mojo::PendingRemote<network::mojom::URLLoaderFactory> proxy_factory_remote_;
|
|
|
|
mojo::PendingReceiver<network::mojom::URLLoaderFactory>
|
|
|
|
proxy_factory_receiver_;
|
2019-05-11 00:14:48 +02:00
|
|
|
scoped_refptr<base::SequencedTaskRunner> task_runner_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct URLLoaderFactoryGetterDeleter {
|
|
|
|
static void Destruct(const URLLoaderFactoryGetter* factory_getter) {
|
|
|
|
factory_getter->DeleteOnCorrectThread();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace net_service
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_NET_SERVICE_URL_LOADER_FACTORY_GETTER_H_
|