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.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
|
|
|
|
#define 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"
|
2018-10-29 13:15:52 +00:00
|
|
|
#include "base/optional.h"
|
|
|
|
#include "mojo/public/cpp/bindings/binding.h"
|
|
|
|
#include "services/network/public/mojom/proxy_lookup_client.mojom.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "url/gurl.h"
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
class AtomBrowserContext;
|
|
|
|
|
|
|
|
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(AtomBrowserContext* 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
|
|
|
|
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();
|
|
|
|
|
|
|
|
PendingRequest& operator=(PendingRequest&& pending_request) noexcept;
|
|
|
|
|
|
|
|
GURL url;
|
|
|
|
ResolveProxyCallback callback;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(PendingRequest);
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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,
|
2018-10-29 13:15:52 +00:00
|
|
|
const base::Optional<net::ProxyInfo>& proxy_info) override;
|
|
|
|
|
|
|
|
// 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_;
|
2018-10-29 13:15:52 +00:00
|
|
|
// Binding for the currently in-progress request, if any.
|
|
|
|
mojo::Binding<network::mojom::ProxyLookupClient> binding_;
|
|
|
|
|
|
|
|
// Weak Ref
|
|
|
|
AtomBrowserContext* browser_context_;
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ResolveProxyHelper);
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
|