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

Side by Side 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, 4 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/arc/arc_wallpaper_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/arc/arc_wallpaper_handler.h" 5 #include "chrome/browser/chromeos/arc/arc_wallpaper_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // TODO(crbug.com/618922): Register the wallpaper to Chrome OS wallpaper 53 // TODO(crbug.com/618922): Register the wallpaper to Chrome OS wallpaper
54 // picker. Currently the new wallpaper does not appear there. The best way to 54 // picker. Currently the new wallpaper does not appear there. The best way to
55 // make this happen seems to do the same things as wallpaper_api.cc and 55 // make this happen seems to do the same things as wallpaper_api.cc and
56 // wallpaper_private_api.cc. 56 // wallpaper_private_api.cc.
57 } 57 }
58 58
59 } // namespace 59 } // namespace
60 60
61 // An implementation of ImageDecoder::ImageRequest that just calls back 61 // An implementation of ImageDecoder::ImageRequest that just calls back
62 // ArcWallpaperHandler. 62 // ArcWallpaperHandler.
63 class ArcWallpaperHandler::ImageRequestImpl 63 class ArcWallpaperHandler::ImageRequestImpl
hidehiko 2016/07/25 19:17:20 Optional: Now this class looks not having any impo
Shuhei Takahashi 2016/07/26 05:41:43 Thanks, now I can implement ImageRequest in ArcWal
64 : public ImageDecoder::ImageRequest { 64 : public ImageDecoder::ImageRequest {
65 public: 65 public:
66 // |handler| outlives this instance. 66 // |handler| outlives this instance.
67 explicit ImageRequestImpl(ArcWallpaperHandler* handler) : handler_(handler) {} 67 explicit ImageRequestImpl(ArcWallpaperHandler* handler) : handler_(handler) {}
68 68
69 // ImageDecoder::ImageRequest implementation. 69 // ImageDecoder::ImageRequest implementation.
70 void OnImageDecoded(const SkBitmap& bitmap) override { 70 void OnImageDecoded(const SkBitmap& bitmap) override {
71 handler_->OnImageDecoded(this, bitmap); 71 handler_->OnImageDecoded(bitmap);
72 } 72 }
73 void OnDecodeImageFailed() override { handler_->OnDecodeImageFailed(this); } 73 void OnDecodeImageFailed() override { handler_->OnDecodeImageFailed(); }
74 74
75 private: 75 private:
76 ArcWallpaperHandler* const handler_; 76 ArcWallpaperHandler* const handler_;
77 77
78 DISALLOW_COPY_AND_ASSIGN(ImageRequestImpl); 78 DISALLOW_COPY_AND_ASSIGN(ImageRequestImpl);
79 }; 79 };
80 80
81 ArcWallpaperHandler::ArcWallpaperHandler() = default; 81 ArcWallpaperHandler::ArcWallpaperHandler() = default;
82 82
83 ArcWallpaperHandler::~ArcWallpaperHandler() { 83 ArcWallpaperHandler::~ArcWallpaperHandler() {
84 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 84 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
85 // Cancel in-flight requests. 85 CancelInflightRequest();
86 for (auto& request : inflight_requests_)
87 ImageDecoder::Cancel(request.get());
88 inflight_requests_.clear();
89 } 86 }
90 87
91 void ArcWallpaperHandler::SetWallpaper(const std::vector<uint8_t>& jpeg_data) { 88 void ArcWallpaperHandler::SetWallpaper(const std::vector<uint8_t>& jpeg_data) {
92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
93 std::unique_ptr<ImageRequestImpl> request = 90 std::unique_ptr<ImageRequestImpl> request =
94 base::MakeUnique<ImageRequestImpl>(this); 91 base::MakeUnique<ImageRequestImpl>(this);
95 // TODO(nya): Improve ImageDecoder to minimize copy. 92 // TODO(nya): Improve ImageDecoder to minimize copy.
96 std::string jpeg_data_as_string( 93 std::string jpeg_data_as_string(
97 reinterpret_cast<const char*>(jpeg_data.data()), jpeg_data.size()); 94 reinterpret_cast<const char*>(jpeg_data.data()), jpeg_data.size());
98 ImageDecoder::StartWithOptions(request.get(), jpeg_data_as_string, 95 ImageDecoder::StartWithOptions(request.get(), jpeg_data_as_string,
99 ImageDecoder::ROBUST_JPEG_CODEC, true); 96 ImageDecoder::ROBUST_JPEG_CODEC, true);
100 inflight_requests_.insert(std::move(request)); 97 CancelInflightRequest();
98 inflight_request_ = std::move(request);
101 } 99 }
102 100
103 void ArcWallpaperHandler::OnImageDecoded(ImageRequestImpl* request, 101 void ArcWallpaperHandler::OnImageDecoded(const SkBitmap& bitmap) {
104 const SkBitmap& bitmap) {
105 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 102 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
106 inflight_requests_.erase(base::WrapUnique(request)); 103 inflight_request_.reset();
107 SetBitmapAsWallpaper(bitmap); 104 SetBitmapAsWallpaper(bitmap);
108 } 105 }
109 106
110 void ArcWallpaperHandler::OnDecodeImageFailed(ImageRequestImpl* request) { 107 void ArcWallpaperHandler::OnDecodeImageFailed() {
111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
112 inflight_requests_.erase(base::WrapUnique(request)); 109 inflight_request_.reset();
113 LOG(ERROR) << "Failed to decode wallpaper image."; 110 LOG(ERROR) << "Failed to decode wallpaper image.";
114 } 111 }
115 112
113 void ArcWallpaperHandler::CancelInflightRequest() {
114 if (inflight_request_.get()) {
hidehiko 2016/07/25 19:17:20 DCHECK_CURRENTLY_ON(UI); here, too?
Shuhei Takahashi 2016/07/26 05:41:43 This function was removed.
115 ImageDecoder::Cancel(inflight_request_.get());
116 inflight_request_.reset();
117 }
118 }
119
116 } // namespace arc 120 } // namespace arc
OLDNEW
« 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