Bug 1647434 - P3: Set mThumbnailUrl in {Clear, Set}Thumbnail r=alwu

`mThumbnailUrl` is always reset after `ClearThubnamil` or `SetThumbnail`
is called. Setting `mThumbnailUrl` in these functions makes sure it
always has the correct value.

Differential Revision: https://phabricator.services.mozilla.com/D81572
This commit is contained in:
Chun-Min Chang 2020-06-29 22:55:15 +00:00
Родитель 6286dbf8d2
Коммит 676a1ab647
2 изменённых файлов: 24 добавлений и 7 удалений

Просмотреть файл

@ -22,6 +22,7 @@
# include "mozilla/Maybe.h" # include "mozilla/Maybe.h"
# include "mozilla/WidgetUtils.h" # include "mozilla/WidgetUtils.h"
# include "mozilla/WindowsVersion.h" # include "mozilla/WindowsVersion.h"
# include "mozilla/ScopeExit.h"
# include "mozilla/media/MediaUtils.h" # include "mozilla/media/MediaUtils.h"
# include "nsThreadUtils.h" # include "nsThreadUtils.h"
@ -455,7 +456,6 @@ void WindowsSMTCProvider::LoadThumbnail(
CancelPendingStoreAsyncOperation(); CancelPendingStoreAsyncOperation();
// Remove the current thumbnail on the interface // Remove the current thumbnail on the interface
ClearThumbnail(); ClearThumbnail();
mThumbnailUrl = EmptyString();
// Then load the new thumbnail asynchronously // Then load the new thumbnail asynchronously
LoadImageAtIndex(0); LoadImageAtIndex(0);
} }
@ -620,9 +620,10 @@ void WindowsSMTCProvider::LoadImage(const char* aImageData,
} }
} }
bool WindowsSMTCProvider::SetThumbnail() { bool WindowsSMTCProvider::SetThumbnail(const nsAString& aUrl) {
MOZ_ASSERT(mDisplay); MOZ_ASSERT(mDisplay);
MOZ_ASSERT(mImageStream); MOZ_ASSERT(mImageStream);
MOZ_ASSERT(!aUrl.IsEmpty());
ComPtr<IRandomAccessStreamReferenceStatics> streamRefFactory; ComPtr<IRandomAccessStreamReferenceStatics> streamRefFactory;
@ -631,6 +632,12 @@ bool WindowsSMTCProvider::SetThumbnail() {
RuntimeClass_Windows_Storage_Streams_RandomAccessStreamReference) RuntimeClass_Windows_Storage_Streams_RandomAccessStreamReference)
.Get(), .Get(),
streamRefFactory.GetAddressOf()); streamRefFactory.GetAddressOf());
auto cleanup =
MakeScopeExit([this, self = RefPtr<WindowsSMTCProvider>(this)] {
LOG("Clean mThumbnailUrl");
mThumbnailUrl = EmptyString();
});
if (FAILED(hr)) { if (FAILED(hr)) {
LOG("Failed to get an activation factory for " LOG("Failed to get an activation factory for "
"IRandomAccessStreamReferenceStatics type"); "IRandomAccessStreamReferenceStatics type");
@ -650,7 +657,17 @@ bool WindowsSMTCProvider::SetThumbnail() {
return false; return false;
} }
return SUCCEEDED(mDisplay->Update()); hr = mDisplay->Update();
if (FAILED(hr)) {
LOG("Failed to refresh display");
return false;
}
// No need to clean mThumbnailUrl since thumbnail is set successfully
cleanup.release();
mThumbnailUrl = aUrl;
return true;
} }
void WindowsSMTCProvider::ClearThumbnail() { void WindowsSMTCProvider::ClearThumbnail() {
@ -660,6 +677,7 @@ void WindowsSMTCProvider::ClearThumbnail() {
hr = mDisplay->Update(); hr = mDisplay->Update();
MOZ_ASSERT(SUCCEEDED(hr)); MOZ_ASSERT(SUCCEEDED(hr));
Unused << hr; Unused << hr;
mThumbnailUrl = EmptyString();
} }
nsresult WindowsSMTCProvider::UpdateThumbnailOnMainThread( nsresult WindowsSMTCProvider::UpdateThumbnailOnMainThread(
@ -680,13 +698,12 @@ nsresult WindowsSMTCProvider::UpdateThumbnailOnMainThread(
mProcessingUrl = EmptyString(); mProcessingUrl = EmptyString();
if (!SetThumbnail()) { if (!SetThumbnail(aImageUrl)) {
LOG("Failed to update thumbnail"); LOG("Failed to update thumbnail");
mThumbnailUrl = EmptyString();
return NS_OK; return NS_OK;
} }
mThumbnailUrl = aImageUrl; MOZ_ASSERT(mThumbnailUrl == aImageUrl);
LOG("The thumbnail is updated to the image from: %s", LOG("The thumbnail is updated to the image from: %s",
NS_ConvertUTF16toUTF8(mThumbnailUrl).get()); NS_ConvertUTF16toUTF8(mThumbnailUrl).get());
return NS_OK; return NS_OK;

Просмотреть файл

@ -87,7 +87,7 @@ class WindowsSMTCProvider final : public mozilla::dom::MediaControlKeySource {
// Thumbnail asynchronously // Thumbnail asynchronously
void LoadImage(const char* aImageData, uint32_t aDataSize); void LoadImage(const char* aImageData, uint32_t aDataSize);
// Sets the Thumbnail to the image stored in mImageStream // Sets the Thumbnail to the image stored in mImageStream
bool SetThumbnail(); bool SetThumbnail(const nsAString& aUrl);
void ClearThumbnail(); void ClearThumbnail();
nsresult UpdateThumbnailOnMainThread(const nsAString& aUrl); nsresult UpdateThumbnailOnMainThread(const nsAString& aUrl);