Skip to content

Commit

Permalink
chore: replace absl::optional<T> with std::optional<T> (electron#40928)
Browse files Browse the repository at this point in the history
* chore: replace absl::optional<T> with std::optional<T>

* IWYU
  • Loading branch information
miniak authored Jan 10, 2024
1 parent fac964a commit 892c9d7
Show file tree
Hide file tree
Showing 129 changed files with 419 additions and 397 deletions.
8 changes: 4 additions & 4 deletions shell/app/electron_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const char* const ElectronMainDelegate::kNonWildcardDomainNonPortSchemes[] = {
const size_t ElectronMainDelegate::kNonWildcardDomainNonPortSchemesSize =
std::size(kNonWildcardDomainNonPortSchemes);

absl::optional<int> ElectronMainDelegate::BasicStartupComplete() {
std::optional<int> ElectronMainDelegate::BasicStartupComplete() {
auto* command_line = base::CommandLine::ForCurrentProcess();

#if BUILDFLAG(IS_WIN)
Expand Down Expand Up @@ -311,7 +311,7 @@ absl::optional<int> ElectronMainDelegate::BasicStartupComplete() {
::switches::kDisableGpuMemoryBufferCompositorResources);
#endif

return absl::nullopt;
return std::nullopt;
}

void ElectronMainDelegate::PreSandboxStartup() {
Expand Down Expand Up @@ -398,7 +398,7 @@ void ElectronMainDelegate::SandboxInitialized(const std::string& process_type) {
#endif
}

absl::optional<int> ElectronMainDelegate::PreBrowserMain() {
std::optional<int> ElectronMainDelegate::PreBrowserMain() {
// This is initialized early because the service manager reads some feature
// flags and we need to make sure the feature list is initialized before the
// service manager reads the features.
Expand All @@ -408,7 +408,7 @@ absl::optional<int> ElectronMainDelegate::PreBrowserMain() {
#if BUILDFLAG(IS_MAC)
RegisterAtomCrApp();
#endif
return absl::nullopt;
return std::nullopt;
}

base::StringPiece ElectronMainDelegate::GetBrowserV8SnapshotFilename() {
Expand Down
4 changes: 2 additions & 2 deletions shell/app/electron_main_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class ElectronMainDelegate : public content::ContentMainDelegate {

protected:
// content::ContentMainDelegate:
absl::optional<int> BasicStartupComplete() override;
std::optional<int> BasicStartupComplete() override;
void PreSandboxStartup() override;
void SandboxInitialized(const std::string& process_type) override;
absl::optional<int> PreBrowserMain() override;
std::optional<int> PreBrowserMain() override;
content::ContentClient* CreateContentClient() override;
content::ContentBrowserClient* CreateContentBrowserClient() override;
content::ContentGpuClient* CreateContentGpuClient() override;
Expand Down
6 changes: 3 additions & 3 deletions shell/browser/api/electron_api_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "shell/browser/api/electron_api_app.h"

#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -75,7 +76,6 @@
#include "shell/common/platform_util.h"
#include "shell/common/thread_restrictions.h"
#include "shell/common/v8_value_serializer.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/image/image.h"

#if BUILDFLAG(IS_WIN)
Expand Down Expand Up @@ -927,7 +927,7 @@ void App::SetAppPath(const base::FilePath& app_path) {

#if !BUILDFLAG(IS_MAC)
void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
absl::optional<base::FilePath> custom_path) {
std::optional<base::FilePath> custom_path) {
if (custom_path.has_value()) {
if (!custom_path->IsAbsolute()) {
thrower.ThrowError("Path must be absolute");
Expand Down Expand Up @@ -1604,7 +1604,7 @@ void ConfigureHostResolver(v8::Isolate* isolate,
// doh_config.
std::vector<net::DnsOverHttpsServerConfig> servers;
for (const std::string& server_template : secure_dns_server_strings) {
absl::optional<net::DnsOverHttpsServerConfig> server_config =
std::optional<net::DnsOverHttpsServerConfig> server_config =
net::DnsOverHttpsServerConfig::FromString(server_template);
if (!server_config.has_value()) {
thrower.ThrowTypeError(std::string("not a valid DoH template: ") +
Expand Down
3 changes: 2 additions & 1 deletion shell/browser/api/electron_api_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_APP_H_

#include <memory>
#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -180,7 +181,7 @@ class App : public ElectronBrowserClient::Delegate,
void ChildProcessDisconnected(int pid);

void SetAppLogsPath(gin_helper::ErrorThrower thrower,
absl::optional<base::FilePath> custom_path);
std::optional<base::FilePath> custom_path);

// Get/Set the pre-defined path in PathService.
base::FilePath GetPath(gin_helper::ErrorThrower thrower,
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_app_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace electron::api {

void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
absl::optional<base::FilePath> custom_path) {
std::optional<base::FilePath> custom_path) {
if (custom_path.has_value()) {
if (!custom_path->IsAbsolute()) {
thrower.ThrowError("Path must be absolute");
Expand Down
4 changes: 2 additions & 2 deletions shell/browser/api/electron_api_base_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,11 @@ bool BaseWindow::GetWindowButtonVisibility() const {
return window_->GetWindowButtonVisibility();
}

void BaseWindow::SetWindowButtonPosition(absl::optional<gfx::Point> position) {
void BaseWindow::SetWindowButtonPosition(std::optional<gfx::Point> position) {
window_->SetWindowButtonPosition(std::move(position));
}

absl::optional<gfx::Point> BaseWindow::GetWindowButtonPosition() const {
std::optional<gfx::Point> BaseWindow::GetWindowButtonPosition() const {
return window_->GetWindowButtonPosition();
}
#endif
Expand Down
5 changes: 3 additions & 2 deletions shell/browser/api/electron_api_base_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -187,8 +188,8 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
std::string GetAlwaysOnTopLevel() const;
void SetWindowButtonVisibility(bool visible);
bool GetWindowButtonVisibility() const;
void SetWindowButtonPosition(absl::optional<gfx::Point> position);
absl::optional<gfx::Point> GetWindowButtonPosition() const;
void SetWindowButtonPosition(std::optional<gfx::Point> position);
std::optional<gfx::Point> GetWindowButtonPosition() const;

bool IsHiddenInMissionControl();
void SetHiddenInMissionControl(bool hidden);
Expand Down
22 changes: 11 additions & 11 deletions shell/browser/api/electron_api_content_tracing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#include <optional>
#include <set>
#include <string>
#include <utility>
Expand All @@ -17,7 +18,6 @@
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/node_includes.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

using content::TracingController;

Expand Down Expand Up @@ -58,18 +58,18 @@ namespace {

using CompletionCallback = base::OnceCallback<void(const base::FilePath&)>;

absl::optional<base::FilePath> CreateTemporaryFileOnIO() {
std::optional<base::FilePath> CreateTemporaryFileOnIO() {
base::FilePath temp_file_path;
if (!base::CreateTemporaryFile(&temp_file_path))
return absl::nullopt;
return absl::make_optional(std::move(temp_file_path));
return std::nullopt;
return std::make_optional(std::move(temp_file_path));
}

void StopTracing(gin_helper::Promise<base::FilePath> promise,
absl::optional<base::FilePath> file_path) {
std::optional<base::FilePath> file_path) {
auto resolve_or_reject = base::BindOnce(
[](gin_helper::Promise<base::FilePath> promise,
const base::FilePath& path, absl::optional<std::string> error) {
const base::FilePath& path, std::optional<std::string> error) {
if (error) {
promise.RejectWithErrorMessage(error.value());
} else {
Expand All @@ -81,20 +81,20 @@ void StopTracing(gin_helper::Promise<base::FilePath> promise,
auto* instance = TracingController::GetInstance();
if (!instance->IsTracing()) {
std::move(resolve_or_reject)
.Run(absl::make_optional(
.Run(std::make_optional(
"Failed to stop tracing - no trace in progress"));
} else if (file_path) {
auto split_callback = base::SplitOnceCallback(std::move(resolve_or_reject));
auto endpoint = TracingController::CreateFileEndpoint(
*file_path,
base::BindOnce(std::move(split_callback.first), absl::nullopt));
base::BindOnce(std::move(split_callback.first), std::nullopt));
if (!instance->StopTracing(endpoint)) {
std::move(split_callback.second)
.Run(absl::make_optional("Failed to stop tracing"));
.Run(std::make_optional("Failed to stop tracing"));
}
} else {
std::move(resolve_or_reject)
.Run(absl::make_optional(
.Run(std::make_optional(
"Failed to create temporary file for trace data"));
}
}
Expand All @@ -105,7 +105,7 @@ v8::Local<v8::Promise> StopRecording(gin_helper::Arguments* args) {

base::FilePath path;
if (args->GetNext(&path) && !path.empty()) {
StopTracing(std::move(promise), absl::make_optional(path));
StopTracing(std::move(promise), std::make_optional(path));
} else {
// use a temporary file.
base::ThreadPool::PostTaskAndReplyWithResult(
Expand Down
10 changes: 5 additions & 5 deletions shell/browser/api/electron_api_cookies.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ bool MatchesCookie(const base::Value::Dict& filter,
if ((str = filter.FindString("domain")) &&
!MatchesDomain(*str, cookie.Domain()))
return false;
absl::optional<bool> secure_filter = filter.FindBool("secure");
std::optional<bool> secure_filter = filter.FindBool("secure");
if (secure_filter && *secure_filter != cookie.IsSecure())
return false;
absl::optional<bool> session_filter = filter.FindBool("session");
std::optional<bool> session_filter = filter.FindBool("session");
if (session_filter && *session_filter == cookie.IsPersistent())
return false;
absl::optional<bool> httpOnly_filter = filter.FindBool("httpOnly");
std::optional<bool> httpOnly_filter = filter.FindBool("httpOnly");
if (httpOnly_filter && *httpOnly_filter != cookie.IsHttpOnly())
return false;
return true;
Expand Down Expand Up @@ -161,7 +161,7 @@ void FilterCookieWithStatuses(
}

// Parse dictionary property to CanonicalCookie time correctly.
base::Time ParseTimeProperty(const absl::optional<double>& value) {
base::Time ParseTimeProperty(const std::optional<double>& value) {
if (!value) // empty time means ignoring the parameter
return base::Time();
if (*value == 0) // FromSecondsSinceUnixEpoch would convert 0 to empty Time
Expand Down Expand Up @@ -321,7 +321,7 @@ v8::Local<v8::Promise> Cookies::Set(v8::Isolate* isolate,
path ? *path : "", ParseTimeProperty(details.FindDouble("creationDate")),
ParseTimeProperty(details.FindDouble("expirationDate")),
ParseTimeProperty(details.FindDouble("lastAccessDate")), secure,
http_only, same_site, net::COOKIE_PRIORITY_DEFAULT, absl::nullopt,
http_only, same_site, net::COOKIE_PRIORITY_DEFAULT, std::nullopt,
&status);

if (!canonical_cookie || !canonical_cookie->IsCanonical()) {
Expand Down
4 changes: 2 additions & 2 deletions shell/browser/api/electron_api_debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,

base::StringPiece message_str(reinterpret_cast<const char*>(message.data()),
message.size());
absl::optional<base::Value> parsed_message = base::JSONReader::Read(
std::optional<base::Value> parsed_message = base::JSONReader::Read(
message_str, base::JSON_REPLACE_INVALID_CHARACTERS);
if (!parsed_message || !parsed_message->is_dict())
return;
base::Value::Dict& dict = parsed_message->GetDict();
absl::optional<int> id = dict.FindInt("id");
std::optional<int> id = dict.FindInt("id");
if (!id) {
std::string* method = dict.FindString("method");
if (!method)
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_menu_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
ui::Accelerator GetAcceleratorFromKeyEquivalentAndModifierMask(
NSString* key_equivalent,
NSUInteger modifier_mask) {
absl::optional<char16_t> shifted_char;
std::optional<char16_t> shifted_char;
ui::KeyboardCode code = electron::KeyboardCodeFromStr(
base::SysNSStringToUTF8(key_equivalent), &shifted_char);
int modifiers = 0;
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_net_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ v8::Local<v8::Promise> NetLog::StartLogging(base::FilePath log_path,
}

pending_start_promise_ =
absl::make_optional<gin_helper::Promise<void>>(args->isolate());
std::make_optional<gin_helper::Promise<void>>(args->isolate());
v8::Local<v8::Promise> handle = pending_start_promise_->GetHandle();

auto command_line_string =
Expand Down
5 changes: 3 additions & 2 deletions shell/browser/api/electron_api_net_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NET_LOG_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NET_LOG_H_

#include <optional>

#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
Expand All @@ -16,7 +18,6 @@
#include "net/log/net_log_capture_mode.h"
#include "services/network/public/mojom/net_log.mojom.h"
#include "shell/common/gin_helper/promise.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace gin {
class Arguments;
Expand Down Expand Up @@ -67,7 +68,7 @@ class NetLog : public gin::Wrappable<NetLog> {

mojo::Remote<network::mojom::NetLogExporter> net_log_exporter_;

absl::optional<gin_helper::Promise<void>> pending_start_promise_;
std::optional<gin_helper::Promise<void>> pending_start_promise_;

scoped_refptr<base::TaskRunner> file_task_runner_;

Expand Down
14 changes: 7 additions & 7 deletions shell/browser/api/electron_api_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void DownloadIdCallback(content::DownloadManager* download_manager,
url_chain, GURL(),
content::StoragePartitionConfig::CreateDefault(
download_manager->GetBrowserContext()),
GURL(), GURL(), absl::nullopt, mime_type, mime_type, start_time,
GURL(), GURL(), std::nullopt, mime_type, mime_type, start_time,
base::Time(), etag, last_modified, offset, length, std::string(),
download::DownloadItem::INTERRUPTED,
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
Expand Down Expand Up @@ -432,7 +432,7 @@ v8::Local<v8::Promise> Session::ResolveProxy(gin::Arguments* args) {

v8::Local<v8::Promise> Session::ResolveHost(
std::string host,
absl::optional<network::mojom::ResolveHostParametersPtr> params) {
std::optional<network::mojom::ResolveHostParametersPtr> params) {
gin_helper::Promise<gin_helper::Dictionary> promise(isolate_);
v8::Local<v8::Promise> handle = promise.GetHandle();

Expand All @@ -441,7 +441,7 @@ v8::Local<v8::Promise> Session::ResolveHost(
params ? std::move(params.value()) : nullptr,
base::BindOnce(
[](gin_helper::Promise<gin_helper::Dictionary> promise,
int64_t net_error, const absl::optional<net::AddressList>& addrs) {
int64_t net_error, const std::optional<net::AddressList>& addrs) {
if (net_error < 0) {
promise.RejectWithErrorMessage(net::ErrorToString(net_error));
} else {
Expand Down Expand Up @@ -1271,7 +1271,7 @@ gin::Handle<Session> Session::FromPartition(v8::Isolate* isolate,
}

// static
absl::optional<gin::Handle<Session>> Session::FromPath(
std::optional<gin::Handle<Session>> Session::FromPath(
v8::Isolate* isolate,
const base::FilePath& path,
base::Value::Dict options) {
Expand All @@ -1280,12 +1280,12 @@ absl::optional<gin::Handle<Session>> Session::FromPath(
if (path.empty()) {
gin_helper::Promise<v8::Local<v8::Value>> promise(isolate);
promise.RejectWithErrorMessage("An empty path was specified");
return absl::nullopt;
return std::nullopt;
}
if (!path.IsAbsolute()) {
gin_helper::Promise<v8::Local<v8::Value>> promise(isolate);
promise.RejectWithErrorMessage("An absolute path was not provided");
return absl::nullopt;
return std::nullopt;
}

browser_context =
Expand Down Expand Up @@ -1410,7 +1410,7 @@ v8::Local<v8::Value> FromPath(const base::FilePath& path,
}
base::Value::Dict options;
args->GetNext(&options);
absl::optional<gin::Handle<Session>> session_handle =
std::optional<gin::Handle<Session>> session_handle =
Session::FromPath(args->isolate(), path, std::move(options));

if (session_handle)
Expand Down
5 changes: 3 additions & 2 deletions shell/browser/api/electron_api_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SESSION_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_SESSION_H_

#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -85,7 +86,7 @@ class Session : public gin::Wrappable<Session>,
base::Value::Dict options = {});

// Gets the Session based on |path|.
static absl::optional<gin::Handle<Session>> FromPath(
static std::optional<gin::Handle<Session>> FromPath(
v8::Isolate* isolate,
const base::FilePath& path,
base::Value::Dict options = {});
Expand All @@ -101,7 +102,7 @@ class Session : public gin::Wrappable<Session>,
// Methods.
v8::Local<v8::Promise> ResolveHost(
std::string host,
absl::optional<network::mojom::ResolveHostParametersPtr> params);
std::optional<network::mojom::ResolveHostParametersPtr> params);
v8::Local<v8::Promise> ResolveProxy(gin::Arguments* args);
v8::Local<v8::Promise> GetCacheSize();
v8::Local<v8::Promise> ClearCache();
Expand Down
Loading

0 comments on commit 892c9d7

Please sign in to comment.