Chromium is now migrating to `std::variant`, and this change does the
same in Brave.
This change was done with a script:
```sh
function delete_line_with {
echo "Deleting lines with $1"
git grep -l "$1" \
| grep -E "\.(h|cc|mm|py)$" \
| sort \
| uniq \
| xargs sed -e "/$(echo "$1" | sed -e 's/[\/&]/\\&/g')/d"
}
function add_header {
echo "Adding header $1"
git diff --name-only \
| xargs ../tools/add_header.py --header "$1"
git grep -l "std::variant" \
| xargs ../tools/add_header.py --header "$1"
}
delete_line_with "\"third_party/abseil-cpp/absl/types/variant.h\""
add_header "<variant>"
git cl format
```
Chromium change:
https://chromium.googlesource.com/chromium/src/+/c01ae649582b75bce39769132a5a41bec8e2d3e4
commit c01ae649582b75bce39769132a5a41bec8e2d3e4
Author: Victor Hugo Vianna Silva <victorvianna@google.com>
Date: Mon Mar 10 19:15:52 2025 -0700
Make absl::variant a typedef for std::variant
This is a re-upload of https://crrev.com/c/5469234, see original
description below. Differences from the original CL:
- Windows symbol definition files were regenerated with
generate_def_files.py.
- New build fixes in password_store_consumer.h,
plus_address_jit_allocator_unittest.cc and mojo_proxy_test.cc.
- Revert change in enclave_protocol_utils.cc, it doesn't seem needed
anymore.
We estimate that ~75% of the regression shown by the
android-binary-size bot will recover after PGO profiles are updated.
See comments 34 to 42 in the linked bug for some numbers.
Original CL description:
"
Discussion thread: https://groups.google.com/u/1/a/chromium.org/g/cxx/c/0EhbuwD-Dpw/m/lbGjN1sxAgAJ
This commit is an updated/tuned version of
David Benjamin's patches (5313884, 5314107).
This only changes the types around. It doesn't rewrite the existing
uses, which we can do incrementally.
"
Binary-Size: See commit description.
Bug: 40242126
110 lines
3.3 KiB
C++
110 lines
3.3 KiB
C++
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef BRAVE_COMPONENTS_SPEEDREADER_SPEEDREADER_UTIL_H_
|
|
#define BRAVE_COMPONENTS_SPEEDREADER_SPEEDREADER_UTIL_H_
|
|
|
|
#include <string>
|
|
#include <variant>
|
|
|
|
#include "base/functional/callback_forward.h"
|
|
#include "url/gurl.h"
|
|
|
|
namespace speedreader {
|
|
|
|
class SpeedreaderService;
|
|
class SpeedreaderRewriterService;
|
|
|
|
enum class DistillationResult : int {
|
|
kNone,
|
|
kSuccess,
|
|
kFail,
|
|
};
|
|
|
|
namespace DistillStates {
|
|
|
|
using None = std::monostate;
|
|
|
|
struct DistillReverting;
|
|
|
|
struct ViewOriginal {
|
|
enum class Reason {
|
|
kNone, // Original page shown because no action was performed.
|
|
kError, // Original page shown because distillation was failed.
|
|
kUserAction, // Original page shown because toggle is clicked.
|
|
kNotDistillable, // Original page shown because page is not distillable.
|
|
} reason = Reason::kNone;
|
|
|
|
bool was_auto_distilled = false;
|
|
|
|
ViewOriginal();
|
|
ViewOriginal(Reason reason, bool was_auto_distilled);
|
|
explicit ViewOriginal(const DistillReverting& state);
|
|
};
|
|
|
|
struct Distilling {
|
|
enum class Reason {
|
|
kNone,
|
|
kAutomatic, // Speedreader mode.
|
|
kManual, // Reader mode toggle is clicked or settings have been changed.
|
|
} reason = Reason::kNone;
|
|
|
|
explicit Distilling(Reason reason);
|
|
};
|
|
|
|
struct Distilled : Distilling {
|
|
using Reason = Distilling::Reason;
|
|
DistillationResult result = DistillationResult::kNone;
|
|
|
|
explicit Distilled(DistillationResult result);
|
|
Distilled(Reason reason, DistillationResult result);
|
|
Distilled(const Distilling& state, DistillationResult result);
|
|
};
|
|
|
|
struct DistillReverting : ViewOriginal {
|
|
using Reason = ViewOriginal::Reason;
|
|
|
|
using ViewOriginal::ViewOriginal;
|
|
DistillReverting(const Distilling& state, Reason reason);
|
|
DistillReverting(const Distilled& state, Reason reason);
|
|
};
|
|
|
|
using State = std::variant<DistillStates::None,
|
|
DistillStates::ViewOriginal,
|
|
DistillStates::Distilling,
|
|
DistillStates::Distilled,
|
|
DistillStates::DistillReverting>;
|
|
|
|
bool IsViewOriginal(const State& state);
|
|
bool IsDistilling(const State& state);
|
|
bool IsDistilled(const State& state);
|
|
bool IsDistillReverting(const State& state);
|
|
|
|
bool IsNotDistillable(const State& state);
|
|
bool IsDistillable(const State& state);
|
|
bool IsDistilledAutomatically(const State& state);
|
|
|
|
// Performs the transition from |state| to |desired|, returns true if transition
|
|
// requires page reload.
|
|
bool Transit(State& state, const State& desired);
|
|
|
|
} // namespace DistillStates
|
|
|
|
using DistillState = DistillStates::State;
|
|
|
|
using DistillationResultCallback =
|
|
base::OnceCallback<void(DistillationResult result,
|
|
std::string original_data,
|
|
std::string transformed)>;
|
|
void DistillPage(const GURL& url,
|
|
std::string body,
|
|
SpeedreaderService* speedreader_service,
|
|
SpeedreaderRewriterService* rewriter_service,
|
|
DistillationResultCallback callback);
|
|
|
|
} // namespace speedreader
|
|
|
|
#endif // BRAVE_COMPONENTS_SPEEDREADER_SPEEDREADER_UTIL_H_
|