Skip to content

Commit

Permalink
Add android exception for hls file path (uplift to 1.64.x) (#22222)
Browse files Browse the repository at this point in the history
Uplift of #22023 (squashed) to beta
  • Loading branch information
brave-builds authored Feb 22, 2024
1 parent f0bec60 commit 23e978d
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions components/playlist/browser/type_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ constexpr char kPlaylistItemMediaSrcKey[] = "mediaSrc";
constexpr char kPlaylistItemThumbnailSrcKey[] = "thumbnailSrc";
constexpr char kPlaylistItemThumbnailPathKey[] = "thumbnailPath";
constexpr char kPlaylistItemMediaFilePathKey[] = "mediaFilePath";
#if BUILDFLAG(IS_ANDROID)
constexpr char kPlaylistItemHlsMediaFilePathKey[] = "hlsMediaFilePath";
#endif // BUILDFLAG(IS_ANDROID)
constexpr char kPlaylistItemMediaFileCachedKey[] = "mediaCached";
constexpr char kPlaylistItemTitleKey[] = "title";
constexpr char kPlaylistItemAuthorKey[] = "author";
Expand All @@ -49,26 +51,29 @@ constexpr char kPlaylistItemMediaFileBytesKey[] = "mediaFileBytes";
} // namespace

bool IsItemValueMalformed(const base::Value::Dict& dict) {
return !dict.contains(kPlaylistItemIDKey) ||
!dict.contains(kPlaylistItemTitleKey) ||
!dict.contains(kPlaylistItemThumbnailPathKey) ||
!dict.contains(kPlaylistItemMediaFileCachedKey) ||
// Added 2022. Sep
!dict.contains(kPlaylistItemPageSrcKey) ||
!dict.contains(kPlaylistItemMediaSrcKey) ||
!dict.contains(kPlaylistItemThumbnailSrcKey) ||
!dict.contains(kPlaylistItemMediaFilePathKey) ||
// Added 2022. Dec.
!dict.contains(kPlaylistItemDurationKey) ||
!dict.contains(kPlaylistItemAuthorKey) ||
!dict.contains(kPlaylistItemLastPlayedPositionKey) ||
// Added 2023. Jan.
!dict.contains(kPlaylistItemParentKey) ||
// Added 2023. Aug.
!dict.contains(kPlaylistItemMediaFileBytesKey) ||

// NEED TO CHECK BELOW FOR MIGRATION
!dict.contains(kPlaylistItemHlsMediaFilePathKey);
bool isMalformed = !dict.contains(kPlaylistItemIDKey) ||
!dict.contains(kPlaylistItemTitleKey) ||
!dict.contains(kPlaylistItemThumbnailPathKey) ||
!dict.contains(kPlaylistItemMediaFileCachedKey) ||
// Added 2022. Sep
!dict.contains(kPlaylistItemPageSrcKey) ||
!dict.contains(kPlaylistItemMediaSrcKey) ||
!dict.contains(kPlaylistItemThumbnailSrcKey) ||
!dict.contains(kPlaylistItemMediaFilePathKey) ||
// Added 2022. Dec.
!dict.contains(kPlaylistItemDurationKey) ||
!dict.contains(kPlaylistItemAuthorKey) ||
!dict.contains(kPlaylistItemLastPlayedPositionKey) ||
// Added 2023. Jan.
!dict.contains(kPlaylistItemParentKey) ||
// Added 2023. Aug.
!dict.contains(kPlaylistItemMediaFileBytesKey);

#if BUILDFLAG(IS_ANDROID)
// Added 2023 Dec.
isMalformed = isMalformed || !dict.contains(kPlaylistItemHlsMediaFilePathKey);
#endif // BUILDFLAG(IS_ANDROID)
return isMalformed;
// DO NOT ADD MORE
}

Expand Down Expand Up @@ -112,8 +117,10 @@ mojom::PlaylistItemPtr ConvertValueToPlaylistItem(
item->thumbnail_path = GURL(*dict.FindString(kPlaylistItemThumbnailPathKey));
item->media_source = GURL(*dict.FindString(kPlaylistItemMediaSrcKey));
item->media_path = GURL(*dict.FindString(kPlaylistItemMediaFilePathKey));
#if BUILDFLAG(IS_ANDROID)
item->hls_media_path =
GURL(*dict.FindString(kPlaylistItemHlsMediaFilePathKey));
#endif // BUILDFLAG(IS_ANDROID)
item->cached = *dict.FindBool(kPlaylistItemMediaFileCachedKey);
item->duration = *dict.FindString(kPlaylistItemDurationKey);
item->author = *dict.FindString(kPlaylistItemAuthorKey);
Expand Down Expand Up @@ -143,13 +150,16 @@ base::Value::Dict ConvertPlaylistItemToValue(
.Set(kPlaylistItemThumbnailSrcKey, item->thumbnail_source.spec())
.Set(kPlaylistItemThumbnailPathKey, item->thumbnail_path.spec())
.Set(kPlaylistItemMediaFilePathKey, item->media_path.spec())
.Set(kPlaylistItemHlsMediaFilePathKey, item->hls_media_path.spec())
.Set(kPlaylistItemMediaFileCachedKey, item->cached)
.Set(kPlaylistItemAuthorKey, item->author)
.Set(kPlaylistItemDurationKey, item->duration)
.Set(kPlaylistItemLastPlayedPositionKey, item->last_played_position)
.Set(kPlaylistItemMediaFileBytesKey,
static_cast<double>(item->media_file_bytes));
#if BUILDFLAG(IS_ANDROID)
playlist_value.Set(kPlaylistItemHlsMediaFilePathKey,
item->hls_media_path.spec());
#endif // BUILDFLAG(IS_ANDROID)

base::Value::List parent;
for (const auto& parent_playlist_id : item->parents) {
Expand Down

0 comments on commit 23e978d

Please sign in to comment.