Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Unified Diff: chrome/browser/chromeos/arc/arc_wallpaper_handler.cc

Issue 2175213002: arc: Do not keep track of in-flight decode requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/arc/arc_wallpaper_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
diff --git a/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc b/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
index 6f93b1346a6ae9711677feb9230d1e0569b9d78f..740eb054797fa0d6b5cf40ae4bc68da99db822c8 100644
--- a/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
+++ b/chrome/browser/chromeos/arc/arc_wallpaper_handler.cc
@@ -10,7 +10,6 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
-#include "chrome/browser/image_decoder.h"
#include "components/signin/core/account_id/account_id.h"
#include "components/user_manager/user_manager.h"
#include "components/wallpaper/wallpaper_files_id.h"
@@ -58,58 +57,34 @@ void SetBitmapAsWallpaper(const SkBitmap& bitmap) {
} // namespace
-// An implementation of ImageDecoder::ImageRequest that just calls back
-// ArcWallpaperHandler.
-class ArcWallpaperHandler::ImageRequestImpl
- : public ImageDecoder::ImageRequest {
- public:
- // |handler| outlives this instance.
- explicit ImageRequestImpl(ArcWallpaperHandler* handler) : handler_(handler) {}
-
- // ImageDecoder::ImageRequest implementation.
- void OnImageDecoded(const SkBitmap& bitmap) override {
- handler_->OnImageDecoded(this, bitmap);
- }
- void OnDecodeImageFailed() override { handler_->OnDecodeImageFailed(this); }
-
- private:
- ArcWallpaperHandler* const handler_;
-
- DISALLOW_COPY_AND_ASSIGN(ImageRequestImpl);
-};
-
ArcWallpaperHandler::ArcWallpaperHandler() = default;
ArcWallpaperHandler::~ArcWallpaperHandler() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- // Cancel in-flight requests.
- for (auto& request : inflight_requests_)
- ImageDecoder::Cancel(request.get());
- inflight_requests_.clear();
+ // Make sure the callback is never called after destruction. It is safe to
+ // call Cancel() even when there is no in-flight request.
+ ImageDecoder::Cancel(this);
}
void ArcWallpaperHandler::SetWallpaper(const std::vector<uint8_t>& jpeg_data) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- std::unique_ptr<ImageRequestImpl> request =
- base::MakeUnique<ImageRequestImpl>(this);
+ // If there is an in-flight request, cancel it. It is safe to call Cancel()
+ // even when there is no in-flight request.
+ ImageDecoder::Cancel(this);
// TODO(nya): Improve ImageDecoder to minimize copy.
std::string jpeg_data_as_string(
reinterpret_cast<const char*>(jpeg_data.data()), jpeg_data.size());
- ImageDecoder::StartWithOptions(request.get(), jpeg_data_as_string,
+ ImageDecoder::StartWithOptions(this, jpeg_data_as_string,
ImageDecoder::ROBUST_JPEG_CODEC, true);
- inflight_requests_.insert(std::move(request));
}
-void ArcWallpaperHandler::OnImageDecoded(ImageRequestImpl* request,
- const SkBitmap& bitmap) {
+void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- inflight_requests_.erase(base::WrapUnique(request));
SetBitmapAsWallpaper(bitmap);
}
-void ArcWallpaperHandler::OnDecodeImageFailed(ImageRequestImpl* request) {
+void ArcWallpaperHandler::OnDecodeImageFailed() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- inflight_requests_.erase(base::WrapUnique(request));
LOG(ERROR) << "Failed to decode wallpaper image.";
}
« no previous file with comments | « chrome/browser/chromeos/arc/arc_wallpaper_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698