* Add error details struct
* Parse streaming error body in APIRequestHelper, extract status/error codes, display to user
* Add tests, v2 client fixups
* Add comment
* Rename error_code to error_type, use string as type
* Only parse error body if content type is application/json
* Address PR feedback
* Address PR feedback
Currently ParseSSE splits each incoming chunk into lines independently,
but network chunks don't always align with SSE line boundaries. When a
line is split across chunks, usually happens when the event is large,
the first fragment produces invalid JSON and later fragments are dropped
due to not starting with "data: {" prefix.
This commit replaces base::SplitStringPiece with incremental line
scanning, each complete line is handed to the new ProcessSSELine helper
and processed the same as before. Partial lines missing line breaks are
buffered in |sse_line_buffer_| until a line ending completes them in the
next chunk.
Also clears |sse_line_buffer_| on retry and completion.
SimpleURLLoader still includes the BodyAsStringCallbackDeprecated
callback that uses std::unique_ptr<std::string> to represent an optional
response body. This approach forces every caller to deal with dynamic
allocation even though the pointer is only used as a nullable indicator.
A newer BodyAsStringCallback already exists using std::optional<std::string>,
which is a clearer and more appropriate way without heap allocation.
This macro is now under `url/gurl_debug.h`.
Chromium changes:
https://chromium.googlesource.com/chromium/src/+/b570a3f1f6bcfa2d958226d37856c2af50ffee1b
commit b570a3f1f6bcfa2d958226d37856c2af50ffee1b
Author: Lei Zhang <thestig@chromium.org>
Date: Tue Jun 17 13:19:22 2025 -0700
Split debugging code out of url/gurl.h and url/origin.h
In gurl.h and origin.h, there exists ScopedUrlCrashKey and
ScopedOriginCrashKey, respectively. These debugging support classes are
not commonly used, but they force the headers they live in to pull in a
bunch of //base debugging headers, which then transitively get included
all over the place.
Split the debug code out into url/gurl_debug.h and url/origin_debug.h.
For now, let gurl.h and origin.h include the new _debug headers, so this
CL can land safely without having to deal with random missing IWYU
issues.
Change-Id: I760723ddb34729a4d4ef0a97a0ecaac97855b66c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6653147
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1475181}
This PR is the run of `gn format` on all `gn` files. This is a
mechanical change done with:
```sh
git ls-files -- "*.gn" | xargs gn format
git ls-files -- "*.gni" | xargs gn format
```
This change has been motivated primarily by an improvement to the
formatters privided by `gn` correcting cases of redundant target naming,
i.e cases where `//foo:foo` is used, and should just be `//foo`.
For this particular `gn` change, see:
https://chromium.googlesource.com/chromium/src/+/c822490a82cdb6ad479159683a92858f7c6f0a58
Resolves https://github.com/brave/brave-browser/issues/48161
Now that the transition to the Rust implementation of `JSONReader` is complete,
`base::JSONReader::UsingRust` has been removed.
Chromium change:
https://source.chromium.org/chromium/chromium/src/+/5077893a42eebf665680b8fbe8731be3e686eab8
commit 5077893a42eebf665680b8fbe8731be3e686eab8
Author: Daniel Cheng <dcheng@chromium.org>
Date: Fri May 2 14:34:10 2025 -0700
Reland "Clean up kUseRustJsonParser"
This is a reland of commit fc3436425ec94c94052e1449dda2061beab23785
The original CL was reverted due to a cast-specific shared library
depending on //base and inadvertently introducing two copies of //base
when loaded into another process that already had symbols for //base.
That shared library no longer depends on //base.
Original change's description:
> Clean up kUseRustJsonParser
>
> Bug: 404881580
> Change-Id: I9e3533b3fdbf436ab37917efbe3cbaf9e7091f67
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6492579
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Owners-Override: Lei Zhang <thestig@chromium.org>
> Reviewed-by: Lei Zhang <thestig@chromium.org>
> Commit-Queue: Daniel Cheng <dcheng@chromium.org>
> Reviewed-by: Maks Orlovich <morlovich@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1454226}
Bug: 404881580
Files that use functions from `string_util.h` should include that header
directly instead of relying on transient inclusions.
This is a mechanical change using this script:
```sh
remove_header_if_unused() {
files=$(git grep -l "base/strings/string_util.h")
for file in $files; do
if ! git grep -qE "base::MakeStringPiece|base::MakeWStringView|base::ToLowerASCII|base::ToUpperASCII|base::CompareCaseInsensitiveASCII|base::EqualsCaseInsensitiveASCII|base::EmptyString|base::RemoveChars|base::ReplaceChars|base::TrimPositions|base::TrimString|base::TruncateUTF8ToByteSize|base::TrimWhitespace|base::CollapseWhitespace|base::ContainsOnlyChars|base::IsStringUTF8|base::IsStringASCII|base::EqualsASCII|base::CompareCase|base::StartsWith|base::EndsWith|base::RemovePrefix|base::RemoveSuffix|base::IsAscii|base::IsUnicodeControl|base::IsHexDigit|base::IsUnicodeWhitespace|base::FormatBytesUnlocalized|base::ReplaceFirstSubstringAfterOffset|base::ReplaceSubstringsAfterOffset|base::WriteInto|base::JoinString|base::ReplaceStringPlaceholders|base::MakeStringViewWithNulChars" "$file"; then
sed -i '/base\/strings\/string_util.h/d' "$file"
echo "Removed 'base/strings/string_util.h' from $file"
fi
done
}
add_header_if_needed() {
files=$(git grep -lE "base::MakeStringPiece|base::MakeWStringView|base::ToLowerASCII|base::ToUpperASCII|base::CompareCaseInsensitiveASCII|base::EqualsCaseInsensitiveASCII|base::EmptyString|base::RemoveChars|base::ReplaceChars|base::TrimPositions|base::TrimString|base::TruncateUTF8ToByteSize|base::TrimWhitespace|base::CollapseWhitespace|base::ContainsOnlyChars|base::IsStringUTF8|base::IsStringASCII|base::EqualsASCII|base::CompareCase|base::StartsWith|base::EndsWith|base::RemovePrefix|base::RemoveSuffix|base::IsAscii|base::IsUnicodeControl|base::IsHexDigit|base::IsUnicodeWhitespace|base::FormatBytesUnlocalized|base::ReplaceFirstSubstringAfterOffset|base::ReplaceSubstringsAfterOffset|base::WriteInto|base::JoinString|base::ReplaceStringPlaceholders|base::MakeStringViewWithNulChars")
for file in $files; do
../tools/add_header.py --header '"base/strings/string_util.h"' "$file"
done
}
remove_header_if_unused
add_header_if_needed
```
Resolves https://github.com/brave/brave-browser/issues/46559
This improvement to this function allows us to make the moving of the
value explicit. It also allows us to remove the flag indicating the
value has been moved, and actually move this validation to profiling
tools, also known as poison-after-use.
This change also removes the unnecessary uses of `TakeBody` for cases
where a const reference were enough.
There were some overrides in place to enforce the use of the rust parser
for `APIRequestHelper` and similar APIs. However, the rust parser is now
switched by default in upstream. This change does away with the
overrides that were added, and uses the regular `JSONReader` interface.
Chromium change:
https://chromium.googlesource.com/chromium/src/+/9ddc1624637c8cfa8ef50a95abd779e0ba4d67f6
commit 9ddc1624637c8cfa8ef50a95abd779e0ba4d67f6
Author: danakj <danakj@chromium.org>
Date: Thu Nov 7 22:14:14 2024 +0000
Make rust toolchain non-optional in chromium and move flags out of build
The //build dir should contain things that apply to all projects using
the directly. Moving the gn args for specific chromium projects out of
//build/config/rust.gni into the Chromium tree next to the features they
are flags for.
Removed the flags that now default to on. They were gated on enable_rust
but enable_rust is always true in Chromium, so in Chromium code we can
just assume it's true. Thus the features are always enabled. Removed
buildflags etc for these removed GN args.
Gating Rust in //base on IS_NACL rather than rust-specific toolchain
flags, as Rust is always available in Chromium in all of our build
configurations except NaCl (and it will be going away in under a year
now).
* AI Chat: use ConversationTurnPtr instead of ConversationTurn to clarify ownership and prevent copy
* AI Chat gets multiple events within a single conversation entry object. This accounts for structured iterative response events such as search progress, text annotations, source links
This change removes the unused inclusion of stragling headers for the
old `base::Erase/EraseIf`
Chromium change:
https://chromium.googlesource.com/chromium/src/+/fcb1dcc7fc7b7de16a27399f8ef7373dda9463cf
commit fcb1dcc7fc7b7de16a27399f8ef7373dda9463cf
Author: Andrew Rayskiy <greengrape@google.com>
Date: Wed Mar 6 13:24:21 2024 +0000
[base] Remove Erase()/EraseIf() overloads for std::vector<>
All call sites have been updated to std::erase()/std::erase_if().
Bug: 40256229
* Update onboarding
Add exoplayer hls dependency
Add HLS support
Make changes for events
Refactor PlaylistOptionsEnum
Refactor logs
Remove unused imports
* Update playlist event behaviour
Remove unused imports after refactor
Address PR comments
* Add message for already added content in default playlist
* Add to playlist menu
Add to playlist prefrence
* Move first kotlin class for onboarding to brave core
Add whole kotlin module into brave core
Add required changes for custom datasource
* Add native worker changes for stream
Add initial work for bytes transfer
Changes to play from saved byte array
* Add HLS parsing
Update datasource
* Add playlist streaming mojom implementation
Add observer for playlist streaming
Add playlist streaming observer
Stream from downloading file
Remove test video activity
Remove custom datasource
Remove kotlin files
Initial work for partial download play
* Update soilution for downloading HLS content
* Add download service with progress notification
Add DownloadUtils functions for mp4
Add function for HLS downloading in DownloadUtils
Add changes for hls download in downloadutils
Update changes to file location for playlist item
Add download queue for HLS
Add hlsMediaPath field for android
Update hlsMediaPath after download
Update existing changes with hls file
add changes to donwload multiple HLS items
* Update changes to multiple downloads
Resolve rebase errors
Download progress update after rebase error resolution
Update streaming observer
Add new event callbacks in mojom
Update existing observer logic
* Migrate exoplayer deps with chromium
* Update UI changes to represent download state
Refactor to remove unused import and implementation
Remove auto save settings option
Update move/delete/share icons
Update filesize update
Hide cast button
Remove unused resources in kotlin module
Add patch to suppress lint for unstable api
Remove indirect deps
Remove unrelated code changes
Resolve presubmit errors
* Refactor HLS content generation
* Remove cast dependency
Refactor logs
* Update add media icons resource
Update player bottom sheet behaviour
Address PR comments
* Remove playlist warning dialog as it's irrelavent
Remove unnecessary flag check
* Add playlist stremaing class details
Reformat existing changes
Add mock data for hls file path
* Resolve rebase errors
Resolve presubmit checks
* Update player items on delete/reorder
* Allow delete while in progress
Made changes to delete while playing
* Add prefs to BravePreferencekeys
* Update string resources
Remove debug messages
Resolve presubmit error
This change replaces all uses of `absl::optional` with `std::*` variants
for optional. This is in line with upstream recent changes making
`absl::optional` a `typedef` to the `std` type.
This change has been done using an automated script:
#!/bin/bash
function replace {
echo "Replacing $1 by $2"
git grep -l "$1" \
| cut -f1 -d: \
| sort \
| uniq \
| grep \
-e "\.h" \
-e "\.cc" \
-e "\.mm" \
-e "\.py" \
| xargs sed -i "s/$1/$2/g"
}
function delete_line_with {
echo "Deleting lines with $1"
git grep -l "$1" \
| cut -f1 -d: \
| sort \
| uniq \
| grep \
-e "\.h" \
-e "\.cc" \
-e "\.mm" \
-e "\.py" \
| xargs sed -i "/$1/d"
}
function add_header {
echo "Adding header $1"
git diff --name-only HEAD \
| xargs ../tools/add_header.py --header "$1"
}
replace "absl::make_optional" "std::make_optional"
replace "absl::optional" "std::optional"
replace "absl::nullopt" "std::nullopt"
replace "absl::in_place" "std::in_place"
replace "absl::in_place_t" "std::in_place_t"
add_header "<optional>"
delete_line_with "\"third_party\/abseil-cpp\/absl\/types\/optional.h\""
git cl format
Chromium change:
https://chromium.googlesource.com/chromium/src/+/d9d21aa16829a7d471a4f3b3a493a31170ed8271
commit d9d21aa16829a7d471a4f3b3a493a31170ed8271
Author: David Benjamin <davidben@chromium.org>
Date: Mon Oct 2 23:29:57 2023 +0000
Make absl::optional a typedef for std::optional
This only changes the types around. It doesn't rewrite existing uses
to std::optional, which we can do incrementally.
absl::optional to std::optional seems to have two visible impacts.
First, the field order is different (bool first vs bool last).
std::optional's order (bool last) seems to be better overall, decreasing
binary size. Second, absl::optional's assertions crash with
__builtin_trap, while std::optional calls __libcpp_verbose_abort which
calls base::ImmediateCrash. __builtin_trap permits the compiler to
combine crash sites within a function but leads to worse crash
debugging. In base::ImmediateCrash, we'd made a conscious decision to
prefer debuggability and pay some binary size for it. The net size
increase brings our optional type in line with that preference.
For more details see the discussion and document below:
https://groups.google.com/a/chromium.org/g/cxx/c/XG3G85_ZF1k/m/_QN8adIJBQAJhttps://docs.google.com/document/d/1AW7q9HCLOk738OCj8Z2U_AKVUC0YIFZWuyRvv09XTHk/edit
Binary-Size: See discussion above.
Fuchsia-Binary-Size: See discussion above.
Bug: 1373619
These functions have now been replaced by the `std::` equivalents.
Chromium change:
https://chromium.googlesource.com/chromium/src/+/fb46735ba84cfa0d3649a8e90e8cd8297ea8e821
commit fb46735ba84cfa0d3649a8e90e8cd8297ea8e821
Author: Andrew Rayskiy <greengrape@google.com>
Date: Thu Nov 16 12:15:25 2023 +0000
[base] Remove base::EraseIf() overloads for std::deque/std::forward_list
They're now replaced with C++20 std::erase_if().
Bug: 1414639
Upstream is set to deprecated, and delete all occurrences of
`base::StringPiece`, and replace it with `std::string_view`, and
according correspondent types.
This change removes the use of `base::StringPiece`, and of the headers
as well across the Brave codebase.
* Sanitize thumbnail for Playlist contents
We didn't sanitize thumbnail as we use untrusted frame.
But we need to sanitize the image as
* we are planing to change the top-most frame to normal chrome://frame
* This is needed as per a spec for showing playlist web ui on tabs
* We have a UI which shows thumbnails of detected media, which is not
yet stored.
So we need to facility to sanitize thumbnail from arbitrary sources.
And ensure DataDecoder doesn't get deleted before it's finished all its decoding operations
Also don't manually bind json parser to DataDecoder instance, doesn't seem neccessary
Then APIRequestHelper-using unittests don't need InProcessDataDecoder as it's not created at construction
* Add enable_cache parameter to APIRequestHelper
Passing this parameter will not add the BYPASS_CACHE and DISABLE_CACHE
load flags to the request which were previously set for all requests.
* Add testcase for when enable_cache is set and not set
* Remove enable_cache option from Request method that does not use APIRequestOptions
* Add comment explaining APIRequestHelper::Request method will be deprecated
* Remove enable_cache parameter from Download method
Instead, we will create a new Download method that accepts an
APIRequestOptions parameter when there is a caller for it
https://github.com/brave/brave-browser/issues/29625.
Chromium change:
https://source.chromium.org/chromium/chromium/src/+/cd23b8b9d212daf06dde638488dbaa355d6651fa
commit cd23b8b9d212daf06dde638488dbaa355d6651fa
Author: Daniel Cheng <dcheng@chromium.org>
Date: Fri Sep 16 17:16:24 2022 +0000
Move bind.h, callback{,_forward,_helpers}.h into //base/functional
Forwarding headers remain in the old locations to ease migration.
Include paths for files in //base/functional/ are also fixed up to the
new canonical path; remaining fixups are deferred until followups to
minimize the risk of conflicts.
Bug: 1364441