focus_mode: Parse playbackReportingToken
from queue.prepare/queue.next requests
This parses `playbackReportingToken` from queue.prepare/queue.next requests so that the player can report the playback when needed later. Bug: b/348698192 Test: Manual Change-Id: I50f1b9662d6a6661f16b4dd5d75826aae385a2a4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5646176 Reviewed-by: Richard Chui <richui@chromium.org> Commit-Queue: Yongshun Liu <yongshun@chromium.org> Cr-Commit-Position: refs/heads/main@{#1319213}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
5a7edd3a15
commit
bf768f460d
ash/system/focus_mode/sounds/youtube_music
google_apis/youtube_music
@ -54,12 +54,14 @@ PlaybackContext::PlaybackContext(const std::string& track_name,
|
||||
const std::string& track_explicit_type,
|
||||
const Image& track_image,
|
||||
const GURL& stream_url,
|
||||
const std::string& playback_reporting_token,
|
||||
const std::string& queue_name)
|
||||
: track_name(track_name),
|
||||
track_title(track_title),
|
||||
track_explicit_type_(track_explicit_type),
|
||||
track_image(track_image),
|
||||
stream_url(stream_url),
|
||||
playback_reporting_token(playback_reporting_token),
|
||||
queue_name(queue_name) {}
|
||||
|
||||
PlaybackContext::PlaybackContext(const PlaybackContext& other) = default;
|
||||
@ -70,10 +72,10 @@ std::string PlaybackContext::ToString() const {
|
||||
return base::StringPrintf(
|
||||
"PlaybackContext(track_name=\"%s\", track_title=\"%s\", "
|
||||
"track_explicit_type=\"%s\", track_image=%s, stream_url=\"%s\", "
|
||||
"queue_name=\"%s\")",
|
||||
"playback_reporting_token=\"%s\", queue_name=\"%s\")",
|
||||
track_name.c_str(), track_title.c_str(), track_explicit_type_.c_str(),
|
||||
track_image.ToString().c_str(), stream_url.spec().c_str(),
|
||||
queue_name.c_str());
|
||||
playback_reporting_token.c_str(), queue_name.c_str());
|
||||
}
|
||||
|
||||
} // namespace ash::youtube_music
|
||||
|
@ -92,6 +92,7 @@ struct ASH_EXPORT PlaybackContext {
|
||||
const std::string& track_explicit_type,
|
||||
const Image& track_image,
|
||||
const GURL& stream_url,
|
||||
const std::string& playback_reporting_token,
|
||||
const std::string& queue_name);
|
||||
PlaybackContext(const PlaybackContext& other);
|
||||
~PlaybackContext();
|
||||
@ -108,6 +109,8 @@ struct ASH_EXPORT PlaybackContext {
|
||||
|
||||
GURL stream_url;
|
||||
|
||||
std::string playback_reporting_token;
|
||||
|
||||
std::string queue_name;
|
||||
};
|
||||
|
||||
|
@ -75,13 +75,16 @@ std::optional<PlaybackContext> GetPlaybackContextFromApiQueue(
|
||||
// TODO(yongshun): Consider to add retry when there is no stream in the
|
||||
// response.
|
||||
GURL stream_url = GURL();
|
||||
std::string playback_reporting_token;
|
||||
if (auto& streams = playback_context.playback_manifest().streams();
|
||||
!streams.empty()) {
|
||||
stream_url = streams.begin()->get()->url();
|
||||
const auto* stream = streams.begin()->get();
|
||||
stream_url = stream->url();
|
||||
playback_reporting_token = stream->playback_reporting_token();
|
||||
}
|
||||
return PlaybackContext(track.name(), track.title(), track.explicit_type(),
|
||||
FindBestImage(GetImagesFromApiImages(track.images())),
|
||||
stream_url, queue->name());
|
||||
stream_url, playback_reporting_token, queue->name());
|
||||
}
|
||||
|
||||
Image FindBestImage(const std::vector<Image>& images) {
|
||||
|
@ -21,6 +21,8 @@ constexpr char kApiResponseMusicSectionKey[] = "musicSection";
|
||||
constexpr char kApiResponseWidthKey[] = "widthPixels";
|
||||
constexpr char kApiResponseHeightKey[] = "heightPixels";
|
||||
constexpr char kApiResponseUriKey[] = "uri";
|
||||
constexpr char kApiResponsePlaybackReportingTokenKey[] =
|
||||
"playbackReportingToken";
|
||||
constexpr char kApiResponseDescriptionKey[] = "description";
|
||||
constexpr char kApiResponseItemCountKey[] = "itemCount";
|
||||
constexpr char kApiResponseImagesKey[] = "images";
|
||||
@ -292,6 +294,8 @@ Stream::~Stream() = default;
|
||||
void Stream::RegisterJSONConverter(JSONValueConverter<Stream>* converter) {
|
||||
converter->RegisterCustomField<GURL>(kApiResponseUriKey, &Stream::url_,
|
||||
&ConvertToGurl);
|
||||
converter->RegisterStringField(kApiResponsePlaybackReportingTokenKey,
|
||||
&Stream::playback_reporting_token_);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -306,7 +310,9 @@ std::unique_ptr<Stream> Stream::CreateFrom(const base::Value& value) {
|
||||
}
|
||||
|
||||
std::string Stream::ToString() const {
|
||||
return base::StringPrintf("Stream(url=\"%s\")", url_.spec().c_str());
|
||||
return base::StringPrintf(
|
||||
"Stream(url=\"%s\", playback_reporting_token=\"%s\")",
|
||||
url_.spec().c_str(), playback_reporting_token_.c_str());
|
||||
}
|
||||
|
||||
PlaybackManifest::PlaybackManifest() = default;
|
||||
|
@ -272,12 +272,16 @@ class Stream {
|
||||
|
||||
static std::unique_ptr<Stream> CreateFrom(const base::Value& value);
|
||||
|
||||
const std::string& playback_reporting_token() const {
|
||||
return playback_reporting_token_;
|
||||
}
|
||||
const GURL& url() const { return url_; }
|
||||
|
||||
std::string ToString() const;
|
||||
|
||||
private:
|
||||
GURL url_;
|
||||
std::string playback_reporting_token_;
|
||||
};
|
||||
|
||||
// Playback manifest object from the API response. For object details, check
|
||||
|
Reference in New Issue
Block a user