chore: replace absl::optional<T> with std::optional<T> (#40928)

* chore: replace absl::optional<T> with std::optional<T>

* IWYU
This commit is contained in:
Milan Burda
2024-01-10 23:23:35 +01:00
committed by GitHub
parent fac964ac0d
commit 892c9d78a3
129 changed files with 419 additions and 397 deletions

View File

@@ -7,12 +7,12 @@
#include <algorithm>
#include <memory>
#include <optional>
#include "crypto/secure_hash.h"
#include "mojo/public/cpp/system/file_data_source.h"
#include "mojo/public/cpp/system/filtered_data_source.h"
#include "shell/common/asar/archive.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace asar {

View File

@@ -78,7 +78,7 @@ class AsarURLLoader : public network::mojom::URLLoader {
const std::vector<std::string>& removed_headers,
const net::HttpRequestHeaders& modified_headers,
const net::HttpRequestHeaders& modified_cors_exempt_headers,
const absl::optional<GURL>& new_url) override {}
const std::optional<GURL>& new_url) override {}
void SetPriority(net::RequestPriority priority,
int32_t intra_priority_value) override {}
void PauseReadingBodyFromNet() override {}
@@ -270,7 +270,7 @@ class AsarURLLoader : public network::mojom::URLLoader {
head->mime_type.c_str());
}
client_->OnReceiveResponse(std::move(head), std::move(consumer_handle),
absl::nullopt);
std::nullopt);
if (total_bytes_to_send == 0) {
// There's definitely no more data, so we're already done.

View File

@@ -26,7 +26,7 @@ void CertVerifierClient::Verify(
const scoped_refptr<net::X509Certificate>& certificate,
const std::string& hostname,
int flags,
const absl::optional<std::string>& ocsp_response,
const std::optional<std::string>& ocsp_response,
VerifyCallback callback) {
VerifyRequestParams params;
params.hostname = hostname;

View File

@@ -40,7 +40,7 @@ class CertVerifierClient : public network::mojom::CertVerifierClient {
const scoped_refptr<net::X509Certificate>& certificate,
const std::string& hostname,
int flags,
const absl::optional<std::string>& ocsp_response,
const std::optional<std::string>& ocsp_response,
VerifyCallback callback) override;
private:

View File

@@ -211,7 +211,7 @@ void ElectronURLLoaderFactory::RedirectedRequest::FollowRedirect(
const std::vector<std::string>& removed_headers,
const net::HttpRequestHeaders& modified_headers,
const net::HttpRequestHeaders& modified_cors_exempt_headers,
const absl::optional<GURL>& new_url) {
const std::optional<GURL>& new_url) {
// Update |request_| with info from the redirect, so that it's accurate
// The following references code in WorkerScriptLoader::FollowRedirect
bool should_clear_upload = false;
@@ -592,7 +592,7 @@ void ElectronURLLoaderFactory::StartLoadingStream(
// Note that We must submit a empty body otherwise NetworkService would
// crash.
client_remote->OnReceiveResponse(std::move(head), std::move(consumer),
absl::nullopt);
std::nullopt);
producer.reset(); // The data pipe is empty.
client_remote->OnComplete(network::URLLoaderCompletionStatus(net::OK));
return;
@@ -640,7 +640,7 @@ void ElectronURLLoaderFactory::SendContents(
}
client_remote->OnReceiveResponse(std::move(head), std::move(consumer),
absl::nullopt);
std::nullopt);
auto write_data = std::make_unique<WriteData>();
write_data->client = std::move(client_remote);

View File

@@ -6,6 +6,7 @@
#define ELECTRON_SHELL_BROWSER_NET_ELECTRON_URL_LOADER_FACTORY_H_
#include <map>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@@ -21,7 +22,6 @@
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "shell/common/gin_helper/dictionary.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace electron {
@@ -73,7 +73,7 @@ class ElectronURLLoaderFactory : public network::SelfDeletingURLLoaderFactory {
const std::vector<std::string>& removed_headers,
const net::HttpRequestHeaders& modified_headers,
const net::HttpRequestHeaders& modified_cors_exempt_headers,
const absl::optional<GURL>& new_url) override;
const std::optional<GURL>& new_url) override;
void SetPriority(net::RequestPriority priority,
int32_t intra_priority_value) override {}
void PauseReadingBodyFromNet() override {}

View File

@@ -59,7 +59,7 @@ void NodeStreamLoader::Start(network::mojom::URLResponseHeadPtr head) {
producer_ = std::make_unique<mojo::DataPipeProducer>(std::move(producer));
client_->OnReceiveResponse(std::move(head), std::move(consumer),
absl::nullopt);
std::nullopt);
auto weak = weak_factory_.GetWeakPtr();
On("end",

View File

@@ -60,7 +60,7 @@ class NodeStreamLoader : public network::mojom::URLLoader {
const std::vector<std::string>& removed_headers,
const net::HttpRequestHeaders& modified_headers,
const net::HttpRequestHeaders& modified_cors_exempt_headers,
const absl::optional<GURL>& new_url) override {}
const std::optional<GURL>& new_url) override {}
void SetPriority(net::RequestPriority priority,
int32_t intra_priority_value) override {}
void PauseReadingBodyFromNet() override {}

View File

@@ -93,11 +93,11 @@ ProxyingURLLoaderFactory::InProgressRequest::~InProgressRequest() {
}
if (on_before_send_headers_callback_) {
std::move(on_before_send_headers_callback_)
.Run(net::ERR_ABORTED, absl::nullopt);
.Run(net::ERR_ABORTED, std::nullopt);
}
if (on_headers_received_callback_) {
std::move(on_headers_received_callback_)
.Run(net::ERR_ABORTED, absl::nullopt, absl::nullopt);
.Run(net::ERR_ABORTED, std::nullopt, std::nullopt);
}
}
@@ -182,7 +182,7 @@ void ProxyingURLLoaderFactory::InProgressRequest::FollowRedirect(
const std::vector<std::string>& removed_headers,
const net::HttpRequestHeaders& modified_headers,
const net::HttpRequestHeaders& modified_cors_exempt_headers,
const absl::optional<GURL>& new_url) {
const std::optional<GURL>& new_url) {
if (new_url)
request_.url = new_url.value();
@@ -241,7 +241,7 @@ void ProxyingURLLoaderFactory::InProgressRequest::OnReceiveEarlyHints(
void ProxyingURLLoaderFactory::InProgressRequest::OnReceiveResponse(
network::mojom::URLResponseHeadPtr head,
mojo::ScopedDataPipeConsumerHandle body,
absl::optional<mojo_base::BigBuffer> cached_metadata) {
std::optional<mojo_base::BigBuffer> cached_metadata) {
current_body_ = std::move(body);
current_cached_metadata_ = std::move(cached_metadata);
if (current_request_uses_header_client_) {
@@ -342,7 +342,7 @@ void ProxyingURLLoaderFactory::InProgressRequest::OnBeforeSendHeaders(
const net::HttpRequestHeaders& headers,
OnBeforeSendHeadersCallback callback) {
if (!current_request_uses_header_client_) {
std::move(callback).Run(net::OK, absl::nullopt);
std::move(callback).Run(net::OK, std::nullopt);
return;
}
@@ -356,7 +356,7 @@ void ProxyingURLLoaderFactory::InProgressRequest::OnHeadersReceived(
const net::IPEndPoint& remote_endpoint,
OnHeadersReceivedCallback callback) {
if (!current_request_uses_header_client_) {
std::move(callback).Run(net::OK, absl::nullopt, GURL());
std::move(callback).Run(net::OK, std::nullopt, GURL());
if (for_cors_preflight_) {
// CORS preflight is supported only when "extraHeaders" is specified.
@@ -581,7 +581,7 @@ void ProxyingURLLoaderFactory::InProgressRequest::
}
DCHECK(on_headers_received_callback_);
absl::optional<std::string> headers;
std::optional<std::string> headers;
if (override_headers_) {
headers = override_headers_->raw_headers();
if (current_request_uses_header_client_) {
@@ -749,7 +749,7 @@ ProxyingURLLoaderFactory::ProxyingURLLoaderFactory(
int frame_routing_id,
uint64_t* request_id_generator,
std::unique_ptr<extensions::ExtensionNavigationUIData> navigation_ui_data,
absl::optional<int64_t> navigation_id,
std::optional<int64_t> navigation_id,
mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader_request,
mojo::PendingRemote<network::mojom::URLLoaderFactory> target_factory_remote,
mojo::PendingReceiver<network::mojom::TrustedURLLoaderHeaderClient>

View File

@@ -7,6 +7,7 @@
#include <cstdint>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>
@@ -33,7 +34,6 @@
#include "services/network/url_loader_factory.h"
#include "shell/browser/net/electron_url_loader_factory.h"
#include "shell/browser/net/web_request_api_interface.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
namespace electron {
@@ -83,7 +83,7 @@ class ProxyingURLLoaderFactory
const std::vector<std::string>& removed_headers,
const net::HttpRequestHeaders& modified_headers,
const net::HttpRequestHeaders& modified_cors_exempt_headers,
const absl::optional<GURL>& new_url) override;
const std::optional<GURL>& new_url) override;
void SetPriority(net::RequestPriority priority,
int32_t intra_priority_value) override;
void PauseReadingBodyFromNet() override;
@@ -95,7 +95,7 @@ class ProxyingURLLoaderFactory
void OnReceiveResponse(
network::mojom::URLResponseHeadPtr head,
mojo::ScopedDataPipeConsumerHandle body,
absl::optional<mojo_base::BigBuffer> cached_metadata) override;
std::optional<mojo_base::BigBuffer> cached_metadata) override;
void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
network::mojom::URLResponseHeadPtr head) override;
void OnUploadProgress(int64_t current_position,
@@ -135,7 +135,7 @@ class ProxyingURLLoaderFactory
raw_ptr<ProxyingURLLoaderFactory> const factory_;
network::ResourceRequest request_;
const absl::optional<url::Origin> original_initiator_;
const std::optional<url::Origin> original_initiator_;
const uint64_t request_id_ = 0;
const int32_t network_service_request_id_ = 0;
const int32_t frame_routing_id_ = MSG_ROUTING_NONE;
@@ -144,7 +144,7 @@ class ProxyingURLLoaderFactory
mojo::Receiver<network::mojom::URLLoader> proxied_loader_receiver_;
mojo::Remote<network::mojom::URLLoaderClient> target_client_;
absl::optional<extensions::WebRequestInfo> info_;
std::optional<extensions::WebRequestInfo> info_;
mojo::Receiver<network::mojom::URLLoaderClient> proxied_client_receiver_{
this};
@@ -180,7 +180,7 @@ class ProxyingURLLoaderFactory
std::vector<std::string> removed_headers;
net::HttpRequestHeaders modified_headers;
net::HttpRequestHeaders modified_cors_exempt_headers;
absl::optional<GURL> new_url;
std::optional<GURL> new_url;
// disable copy
FollowRedirectParams(const FollowRedirectParams&) = delete;
@@ -188,7 +188,7 @@ class ProxyingURLLoaderFactory
};
std::unique_ptr<FollowRedirectParams> pending_follow_redirect_params_;
absl::optional<mojo_base::BigBuffer> current_cached_metadata_;
std::optional<mojo_base::BigBuffer> current_cached_metadata_;
base::WeakPtrFactory<InProgressRequest> weak_factory_{this};
};
@@ -200,7 +200,7 @@ class ProxyingURLLoaderFactory
int frame_routing_id,
uint64_t* request_id_generator,
std::unique_ptr<extensions::ExtensionNavigationUIData> navigation_ui_data,
absl::optional<int64_t> navigation_id,
std::optional<int64_t> navigation_id,
mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader_request,
mojo::PendingRemote<network::mojom::URLLoaderFactory>
target_factory_remote,
@@ -264,7 +264,7 @@ class ProxyingURLLoaderFactory
const int frame_routing_id_;
raw_ptr<uint64_t> request_id_generator_; // managed by ElectronBrowserClient
std::unique_ptr<extensions::ExtensionNavigationUIData> navigation_ui_data_;
absl::optional<int64_t> navigation_id_;
std::optional<int64_t> navigation_id_;
mojo::ReceiverSet<network::mojom::URLLoaderFactory> proxy_receivers_;
mojo::Remote<network::mojom::URLLoaderFactory> target_factory_;
mojo::Receiver<network::mojom::TrustedURLLoaderHeaderClient>

View File

@@ -44,16 +44,16 @@ ProxyingWebSocket::ProxyingWebSocket(
/*is_download=*/false,
/*is_async=*/true,
/*is_service_worker_script=*/false,
/*navigation_id=*/absl::nullopt)) {}
/*navigation_id=*/std::nullopt)) {}
ProxyingWebSocket::~ProxyingWebSocket() {
if (on_before_send_headers_callback_) {
std::move(on_before_send_headers_callback_)
.Run(net::ERR_ABORTED, absl::nullopt);
.Run(net::ERR_ABORTED, std::nullopt);
}
if (on_headers_received_callback_) {
std::move(on_headers_received_callback_)
.Run(net::ERR_ABORTED, absl::nullopt, GURL());
.Run(net::ERR_ABORTED, std::nullopt, GURL());
}
}
@@ -229,7 +229,7 @@ void ProxyingWebSocket::StartProxying(
WebSocketFactory factory,
const GURL& url,
const net::SiteForCookies& site_for_cookies,
const absl::optional<std::string>& user_agent,
const std::optional<std::string>& user_agent,
mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
handshake_client,
bool has_extra_headers,
@@ -358,11 +358,11 @@ void ProxyingWebSocket::OnHeadersReceivedComplete(int error_code) {
}
if (on_headers_received_callback_) {
absl::optional<std::string> headers;
std::optional<std::string> headers;
if (override_headers_)
headers = override_headers_->raw_headers();
std::move(on_headers_received_callback_)
.Run(net::OK, headers, absl::nullopt);
.Run(net::OK, headers, std::nullopt);
}
if (override_headers_) {
@@ -384,7 +384,7 @@ void ProxyingWebSocket::OnAuthRequiredComplete(AuthRequiredResponse rv) {
switch (rv) {
case AuthRequiredResponse::kNoAction:
case AuthRequiredResponse::kCancelAuth:
std::move(auth_required_callback_).Run(absl::nullopt);
std::move(auth_required_callback_).Run(std::nullopt);
break;
case AuthRequiredResponse::kSetAuth:

View File

@@ -5,6 +5,7 @@
#ifndef ELECTRON_SHELL_BROWSER_NET_PROXYING_WEBSOCKET_H_
#define ELECTRON_SHELL_BROWSER_NET_PROXYING_WEBSOCKET_H_
#include <optional>
#include <set>
#include <string>
#include <vector>
@@ -19,7 +20,6 @@
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/websocket.mojom.h"
#include "shell/browser/net/web_request_api_interface.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
#include "url/origin.h"
@@ -101,7 +101,7 @@ class ProxyingWebSocket : public network::mojom::WebSocketHandshakeClient,
WebSocketFactory factory,
const GURL& url,
const net::SiteForCookies& site_for_cookies,
const absl::optional<std::string>& user_agent,
const std::optional<std::string>& user_agent,
mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
handshake_client,
bool has_extra_headers,

View File

@@ -53,8 +53,8 @@ void ResolveHostFunction::Run() {
receiver_.set_disconnect_handler(base::BindOnce(
&ResolveHostFunction::OnComplete, this, net::ERR_NAME_NOT_RESOLVED,
net::ResolveErrorInfo(net::ERR_FAILED),
/*resolved_addresses=*/absl::nullopt,
/*endpoint_results_with_metadata=*/absl::nullopt));
/*resolved_addresses=*/std::nullopt,
/*endpoint_results_with_metadata=*/std::nullopt));
if (electron::IsUtilityProcess()) {
URLLoaderBundle::GetInstance()->GetHostResolver()->ResolveHost(
network::mojom::HostResolverHost::NewHostPortPair(
@@ -75,8 +75,8 @@ void ResolveHostFunction::Run() {
void ResolveHostFunction::OnComplete(
int result,
const net::ResolveErrorInfo& resolve_error_info,
const absl::optional<net::AddressList>& resolved_addresses,
const absl::optional<net::HostResolverEndpointResults>&
const std::optional<net::AddressList>& resolved_addresses,
const std::optional<net::HostResolverEndpointResults>&
endpoint_results_with_metadata) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

View File

@@ -5,6 +5,7 @@
#ifndef ELECTRON_SHELL_BROWSER_NET_RESOLVE_HOST_FUNCTION_H_
#define ELECTRON_SHELL_BROWSER_NET_RESOLVE_HOST_FUNCTION_H_
#include <optional>
#include <string>
#include "base/memory/raw_ptr.h"
@@ -16,7 +17,6 @@
#include "services/network/public/cpp/resolve_host_client_base.h"
#include "services/network/public/mojom/host_resolver.mojom.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace electron {
@@ -26,9 +26,8 @@ class ResolveHostFunction
: public base::RefCountedThreadSafe<ResolveHostFunction>,
network::ResolveHostClientBase {
public:
using ResolveHostCallback = base::OnceCallback<void(
int64_t,
const absl::optional<net::AddressList>& resolved_addresses)>;
using ResolveHostCallback = base::OnceCallback<
void(int64_t, const std::optional<net::AddressList>& resolved_addresses)>;
explicit ResolveHostFunction(ElectronBrowserContext* browser_context,
std::string host,
@@ -50,8 +49,8 @@ class ResolveHostFunction
// network::mojom::ResolveHostClient implementation
void OnComplete(int result,
const net::ResolveErrorInfo& resolve_error_info,
const absl::optional<net::AddressList>& resolved_addresses,
const absl::optional<net::HostResolverEndpointResults>&
const std::optional<net::AddressList>& resolved_addresses,
const std::optional<net::HostResolverEndpointResults>&
endpoint_results_with_metadata) override;
SEQUENCE_CHECKER(sequence_checker_);

View File

@@ -53,7 +53,7 @@ void ResolveProxyHelper::StartPendingRequest() {
receiver_.BindNewPipeAndPassRemote();
receiver_.set_disconnect_handler(
base::BindOnce(&ResolveProxyHelper::OnProxyLookupComplete,
base::Unretained(this), net::ERR_ABORTED, absl::nullopt));
base::Unretained(this), net::ERR_ABORTED, std::nullopt));
browser_context_->GetDefaultStoragePartition()
->GetNetworkContext()
->LookUpProxyForURL(pending_requests_.front().url,
@@ -63,7 +63,7 @@ void ResolveProxyHelper::StartPendingRequest() {
void ResolveProxyHelper::OnProxyLookupComplete(
int32_t net_error,
const absl::optional<net::ProxyInfo>& proxy_info) {
const std::optional<net::ProxyInfo>& proxy_info) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!pending_requests_.empty());

View File

@@ -6,13 +6,13 @@
#define ELECTRON_SHELL_BROWSER_NET_RESOLVE_PROXY_HELPER_H_
#include <deque>
#include <optional>
#include <string>
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/network/public/mojom/proxy_lookup_client.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
namespace electron {
@@ -61,7 +61,7 @@ class ResolveProxyHelper
// network::mojom::ProxyLookupClient implementation.
void OnProxyLookupComplete(
int32_t net_error,
const absl::optional<net::ProxyInfo>& proxy_info) override;
const std::optional<net::ProxyInfo>& proxy_info) override;
// Self-reference. Owned as long as there's an outstanding proxy lookup.
scoped_refptr<ResolveProxyHelper> owned_self_;

View File

@@ -5,6 +5,8 @@
#ifndef ELECTRON_SHELL_BROWSER_NET_SYSTEM_NETWORK_CONTEXT_MANAGER_H_
#define ELECTRON_SHELL_BROWSER_NET_SYSTEM_NETWORK_CONTEXT_MANAGER_H_
#include <optional>
#include "base/memory/ref_counted.h"
#include "chrome/browser/net/proxy_config_monitor.h"
#include "mojo/public/cpp/bindings/remote.h"
@@ -14,7 +16,6 @@
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace electron {
network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams();

View File

@@ -72,7 +72,7 @@ void URLPipeLoader::OnResponseStarted(
producer_ = std::make_unique<mojo::DataPipeProducer>(std::move(producer));
client_->OnReceiveResponse(response_head.Clone(), std::move(consumer),
absl::nullopt);
std::nullopt);
}
void URLPipeLoader::OnWrite(base::OnceClosure resume, MojoResult result) {

View File

@@ -68,7 +68,7 @@ class URLPipeLoader : public network::mojom::URLLoader,
const std::vector<std::string>& removed_headers,
const net::HttpRequestHeaders& modified_headers,
const net::HttpRequestHeaders& modified_cors_exempt_headers,
const absl::optional<GURL>& new_url) override {}
const std::optional<GURL>& new_url) override {}
void SetPriority(net::RequestPriority priority,
int32_t intra_priority_value) override {}
void PauseReadingBodyFromNet() override {}