Commit a59f7b28 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Media Session: do not notify image observers for no-op image clearing.

It avoids triggering callbacks that end up being no-ops and limit it to
situations where the observer would actually do something about it.

Bug: 1028822
Change-Id: I7982f74d5791277e181e63e91c0f9f076586717a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1949561Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721711}
parent cebe33f2
...@@ -63,11 +63,15 @@ class MediaController::ImageObserverHolder { ...@@ -63,11 +63,15 @@ class MediaController::ImageObserverHolder {
} }
void ClearImage() { void ClearImage() {
if (!did_send_image_last_)
return;
did_send_image_last_ = false;
observer_->MediaControllerImageChanged(type_, SkBitmap()); observer_->MediaControllerImageChanged(type_, SkBitmap());
} }
private: private:
void OnImage(const SkBitmap& image) { void OnImage(const SkBitmap& image) {
did_send_image_last_ = true;
observer_->MediaControllerImageChanged(type_, image); observer_->MediaControllerImageChanged(type_, image);
} }
...@@ -83,6 +87,9 @@ class MediaController::ImageObserverHolder { ...@@ -83,6 +87,9 @@ class MediaController::ImageObserverHolder {
mojo::Remote<mojom::MediaControllerImageObserver> observer_; mojo::Remote<mojom::MediaControllerImageObserver> observer_;
// Whether the last information sent to the observer was an image.
bool did_send_image_last_ = false;
base::WeakPtrFactory<ImageObserverHolder> weak_ptr_factory_{this}; base::WeakPtrFactory<ImageObserverHolder> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ImageObserverHolder); DISALLOW_COPY_AND_ASSIGN(ImageObserverHolder);
......
...@@ -1091,9 +1091,7 @@ TEST_F(MediaControllerTest, ActiveController_SimulateImagesChanged) { ...@@ -1091,9 +1091,7 @@ TEST_F(MediaControllerTest, ActiveController_SimulateImagesChanged) {
{ {
test::TestMediaControllerImageObserver observer(controller(), 0, 0); test::TestMediaControllerImageObserver observer(controller(), 0, 0);
// By default, we should receive an empty image. // By default, the image is empty but no notification should be received.
observer.WaitForExpectedImageOfType(mojom::MediaSessionImageType::kArtwork,
true);
EXPECT_TRUE(media_session.last_image_src().is_empty()); EXPECT_TRUE(media_session.last_image_src().is_empty());
// Check that we receive the correct image and that it was requested from // Check that we receive the correct image and that it was requested from
...@@ -1201,31 +1199,37 @@ TEST_F(MediaControllerTest, ...@@ -1201,31 +1199,37 @@ TEST_F(MediaControllerTest,
MediaImage image1; MediaImage image1;
image1.src = GURL("https://www.google.com"); image1.src = GURL("https://www.google.com");
image1.sizes.push_back(gfx::Size(1, 1)); image1.sizes.push_back(gfx::Size(1, 1));
images.push_back(image1);
media_session.SetImagesOfType(mojom::MediaSessionImageType::kArtwork, images); media_session.SetImagesOfType(mojom::MediaSessionImageType::kArtwork,
{image1});
{ {
test::TestMediaControllerImageObserver observer(controller(), 5, 10); test::TestMediaControllerImageObserver observer(controller(), 5, 10);
// The observer requires an image that is at least 5px but the only image // The observer requires an image that is at least 5px but the only image
// we have is 1px so the observer will receive a null image. // we have is 1px so the observer will not be notified.
observer.WaitForExpectedImageOfType(mojom::MediaSessionImageType::kArtwork,
true);
EXPECT_TRUE(media_session.last_image_src().is_empty()); EXPECT_TRUE(media_session.last_image_src().is_empty());
MediaImage image2; MediaImage image2;
image2.src = GURL("https://www.example.com"); image2.src = GURL("https://www.example.com");
image2.sizes.push_back(gfx::Size(10, 10)); image2.sizes.push_back(gfx::Size(10, 10));
images.push_back(image2);
// Update the media session with two images, one that is too small and one // Update the media session with two images, one that is too small and one
// that is the right size. We should receive the second image through the // that is the right size. We should receive the second image through the
// observer. // observer.
media_session.SetImagesOfType(mojom::MediaSessionImageType::kArtwork, media_session.SetImagesOfType(mojom::MediaSessionImageType::kArtwork,
images); {image1, image2});
observer.WaitForExpectedImageOfType(mojom::MediaSessionImageType::kArtwork, observer.WaitForExpectedImageOfType(mojom::MediaSessionImageType::kArtwork,
false); false);
EXPECT_EQ(image2.src, media_session.last_image_src()); EXPECT_EQ(image2.src, media_session.last_image_src());
// Use the first set of images again.
media_session.SetImagesOfType(mojom::MediaSessionImageType::kArtwork,
{image1});
// The observer requires as image that is at least 5px and should now be
// notified that the image was cleared.
observer.WaitForExpectedImageOfType(mojom::MediaSessionImageType::kArtwork,
true);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment