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

Side by Side Diff: chrome/browser/chromeos/app_mode/kiosk_app_data.cc

Issue 931993002: Make image_decoder a Leaky LazyInstance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename instance_ to image_decoder_instance_ for mac linker Created 5 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/app_mode/kiosk_app_data.h" 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 void LoadOnBlockingPool() { 225 void LoadOnBlockingPool() {
226 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 226 DCHECK(task_runner_->RunsTasksOnCurrentThread());
227 227
228 std::string data; 228 std::string data;
229 if (!base::ReadFileToString(base::FilePath(icon_path_), &data)) { 229 if (!base::ReadFileToString(base::FilePath(icon_path_), &data)) {
230 ReportResultOnBlockingPool(FAILED_TO_LOAD); 230 ReportResultOnBlockingPool(FAILED_TO_LOAD);
231 return; 231 return;
232 } 232 }
233 raw_icon_ = base::RefCountedString::TakeString(&data); 233 raw_icon_ = base::RefCountedString::TakeString(&data);
234 234
235 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( 235 ImageDecoder::GetInstance()->Start(
236 this, raw_icon_->data(), ImageDecoder::DEFAULT_CODEC); 236 this, raw_icon_->data(), ImageDecoder::DEFAULT_CODEC, task_runner_);
237 image_decoder->Start(task_runner_);
238 } 237 }
239 238
240 void ReportResultOnBlockingPool(LoadResult result) { 239 void ReportResultOnBlockingPool(LoadResult result) {
241 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 240 DCHECK(task_runner_->RunsTasksOnCurrentThread());
242 241
243 load_result_ = result; 242 load_result_ = result;
244 BrowserThread::PostTask( 243 BrowserThread::PostTask(
245 BrowserThread::UI, 244 BrowserThread::UI,
246 FROM_HERE, 245 FROM_HERE,
247 base::Bind(&IconLoader::ReportResultOnUIThread, 246 base::Bind(&IconLoader::ReportResultOnUIThread,
(...skipping 11 matching lines...) Expand all
259 } 258 }
260 259
261 void ReportResultOnUIThread() { 260 void ReportResultOnUIThread() {
262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
263 262
264 NotifyClient(); 263 NotifyClient();
265 delete this; 264 delete this;
266 } 265 }
267 266
268 // ImageDecoder::Delegate overrides: 267 // ImageDecoder::Delegate overrides:
269 void OnImageDecoded(const ImageDecoder* decoder, 268 void OnImageDecoded(const SkBitmap& decoded_image) override {
270 const SkBitmap& decoded_image) override {
271 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); 269 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image);
272 icon_.MakeThreadSafe(); 270 icon_.MakeThreadSafe();
273 ReportResultOnBlockingPool(SUCCESS); 271 ReportResultOnBlockingPool(SUCCESS);
274 } 272 }
275 273
276 void OnDecodeImageFailed(const ImageDecoder* decoder) override { 274 void OnDecodeImageFailed() override {
277 ReportResultOnBlockingPool(FAILED_TO_DECODE); 275 ReportResultOnBlockingPool(FAILED_TO_DECODE);
278 } 276 }
279 277
280 base::WeakPtr<KioskAppData> client_; 278 base::WeakPtr<KioskAppData> client_;
281 base::FilePath icon_path_; 279 base::FilePath icon_path_;
282 280
283 LoadResult load_result_; 281 LoadResult load_result_;
284 scoped_refptr<base::SequencedTaskRunner> task_runner_; 282 scoped_refptr<base::SequencedTaskRunner> task_runner_;
285 283
286 gfx::ImageSkia icon_; 284 gfx::ImageSkia icon_;
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 642
645 SkBitmap icon = crx_loader->icon(); 643 SkBitmap icon = crx_loader->icon();
646 if (icon.empty()) 644 if (icon.empty())
647 icon = *extensions::util::GetDefaultAppIcon().bitmap(); 645 icon = *extensions::util::GetDefaultAppIcon().bitmap();
648 SetCache(crx_loader->name(), icon); 646 SetCache(crx_loader->name(), icon);
649 647
650 SetStatus(STATUS_LOADED); 648 SetStatus(STATUS_LOADED);
651 } 649 }
652 650
653 } // namespace chromeos 651 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698