blob: f6ea3869957c63cfa3b88d80c15413368cef2bd6 [file] [log] [blame]
// Copyright 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.
#include <memory>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/sequence_checker.h"
#include "content/common/content_export.h"
#include "services/network/public/mojom/proxy_lookup_client.mojom.h"
class GURL;
namespace net {
class ProxyInfo;
namespace content {
// Class that runs a single proxy resolution on the UI thread. Lives on the
// thread its created on, and uses a helper to run tasks off-thread. Can be
// destroyed at any time.
class CONTENT_EXPORT PepperProxyLookupHelper {
// Callback to call LookUpProxyForURL. Called on the UI thread. Needed for
// testing. Returns false if unable to make the call, for whatever reason.
using LookUpProxyForURLCallback = base::OnceCallback<bool(
const GURL& url,
network::mojom::ProxyLookupClientPtr proxy_lookup_client)>;
// Callback to invoke when complete. Invoked on thread the
// PepperProxyLookupHelper was created on.
using LookUpCompleteCallback =
base::OnceCallback<void(base::Optional<net::ProxyInfo> proxy_info)>;
// Starts a lookup for |url| on the UI thread. Invokes
// |look_up_proxy_for_url_callback| on the UI thread to start the lookup, and
// calls |look_up_complete_callback| on the thread Start() was called on when
// complete. May only be invoked once.
void Start(const GURL& url,
LookUpProxyForURLCallback look_up_proxy_for_url_callback,
LookUpCompleteCallback look_up_complete_callback);
class UIThreadHelper;
void OnProxyLookupComplete(base::Optional<net::ProxyInfo> proxy_info);
LookUpCompleteCallback look_up_complete_callback_;
std::unique_ptr<UIThreadHelper> ui_thread_helper_;
base::WeakPtrFactory<PepperProxyLookupHelper> weak_factory_;
} // namespace content