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>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#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"
|
2021-06-03 08:05:04 +00:00
|
|
|
#include "third_party/abseil-cpp/absl/types/optional.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "url/gurl.h"
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class ElectronBrowserContext;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
explicit ResolveProxyHelper(ElectronBrowserContext* browser_context);
|
|
|
|
|
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,
|
2021-06-03 08:05:04 +00:00
|
|
|
const absl::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
|
|
|
|
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_
|