2018-10-04 18:08:56 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
#include <deque>
|
2024-01-10 22:23:35 +00:00
|
|
|
#include <optional>
|
2018-10-04 18:08:56 +00:00
|
|
|
#include <string>
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "base/memory/ref_counted.h"
|
2019-10-28 22:12:35 +00:00
|
|
|
#include "mojo/public/cpp/bindings/receiver.h"
|
2018-10-29 13:15:52 +00:00
|
|
|
#include "services/network/public/mojom/proxy_lookup_client.mojom.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "url/gurl.h"
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
2024-07-15 08:46:24 +00:00
|
|
|
class ElectronBrowserContext;
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
class ResolveProxyHelper
|
2018-10-29 13:15:52 +00:00
|
|
|
: public base::RefCountedThreadSafe<ResolveProxyHelper>,
|
|
|
|
network::mojom::ProxyLookupClient {
|
2018-10-04 18:08:56 +00:00
|
|
|
public:
|
2019-05-01 20:45:08 +00:00
|
|
|
using ResolveProxyCallback = base::OnceCallback<void(std::string)>;
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2024-07-15 08:46:24 +00:00
|
|
|
explicit ResolveProxyHelper(ElectronBrowserContext* browser_context);
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2019-05-01 20:45:08 +00:00
|
|
|
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
ResolveProxyHelper(const ResolveProxyHelper&) = delete;
|
|
|
|
ResolveProxyHelper& operator=(const ResolveProxyHelper&) = delete;
|
|
|
|
|
2018-10-29 13:15:52 +00:00
|
|
|
protected:
|
|
|
|
~ResolveProxyHelper() override;
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
private:
|
|
|
|
friend class base::RefCountedThreadSafe<ResolveProxyHelper>;
|
|
|
|
// A PendingRequest is a resolve request that is in progress, or queued.
|
|
|
|
struct PendingRequest {
|
|
|
|
public:
|
2019-05-01 20:45:08 +00:00
|
|
|
PendingRequest(const GURL& url, ResolveProxyCallback callback);
|
2018-10-04 18:08:56 +00:00
|
|
|
PendingRequest(PendingRequest&& pending_request) noexcept;
|
|
|
|
~PendingRequest();
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
PendingRequest(const PendingRequest&) = delete;
|
|
|
|
PendingRequest& operator=(const PendingRequest&) = delete;
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
PendingRequest& operator=(PendingRequest&& pending_request) noexcept;
|
|
|
|
|
|
|
|
GURL url;
|
|
|
|
ResolveProxyCallback callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Starts the first pending request.
|
|
|
|
void StartPendingRequest();
|
|
|
|
|
2018-10-29 13:15:52 +00:00
|
|
|
// network::mojom::ProxyLookupClient implementation.
|
|
|
|
void OnProxyLookupComplete(
|
2019-01-24 14:57:08 +00:00
|
|
|
int32_t net_error,
|
2024-01-10 22:23:35 +00:00
|
|
|
const std::optional<net::ProxyInfo>& proxy_info) override;
|
2018-10-29 13:15:52 +00:00
|
|
|
|
|
|
|
// Self-reference. Owned as long as there's an outstanding proxy lookup.
|
|
|
|
scoped_refptr<ResolveProxyHelper> owned_self_;
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
std::deque<PendingRequest> pending_requests_;
|
2019-10-28 22:12:35 +00:00
|
|
|
// Receiver for the currently in-progress request, if any.
|
|
|
|
mojo::Receiver<network::mojom::ProxyLookupClient> receiver_{this};
|
2018-10-29 13:15:52 +00:00
|
|
|
|
|
|
|
// Weak Ref
|
2024-07-15 08:46:24 +00:00
|
|
|
raw_ptr<ElectronBrowserContext> browser_context_;
|
2018-10-04 18:08:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
|