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

Side by Side Diff: chrome/browser/chromeos/login/users/avatar/user_image_manager_test_util.cc

Issue 931993002: Make image_decoder a Leaky LazyInstance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a few comments 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/login/users/avatar/user_image_manager_test_uti l.h" 5 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_test_uti l.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 26 matching lines...) Expand all
37 SkAutoLockPixels second_pixel_lock(*second_bitmap); 37 SkAutoLockPixels second_pixel_lock(*second_bitmap);
38 uint8_t* first_data = reinterpret_cast<uint8_t*>(first_bitmap->getPixels()); 38 uint8_t* first_data = reinterpret_cast<uint8_t*>(first_bitmap->getPixels());
39 uint8_t* second_data = reinterpret_cast<uint8_t*>(second_bitmap->getPixels()); 39 uint8_t* second_data = reinterpret_cast<uint8_t*>(second_bitmap->getPixels());
40 for (size_t i = 0; i < size; ++i) { 40 for (size_t i = 0; i < size; ++i) {
41 if (first_data[i] != second_data[i]) 41 if (first_data[i] != second_data[i])
42 return false; 42 return false;
43 } 43 }
44 return true; 44 return true;
45 } 45 }
46 46
47 ImageLoader::ImageLoader(const base::FilePath& path) : path_(path) { 47 ImageLoader::ImageLoader(const base::FilePath& path)
48 : ImageRequest(base::MessageLoopProxy::current()), path_(path) {
48 } 49 }
49 50
50 ImageLoader::~ImageLoader() { 51 ImageLoader::~ImageLoader() {
51 } 52 }
52 53
53 scoped_ptr<gfx::ImageSkia> ImageLoader::Load() { 54 scoped_ptr<gfx::ImageSkia> ImageLoader::Load() {
54 std::string image_data; 55 std::string image_data;
55 ReadFileToString(path_, &image_data); 56 ReadFileToString(path_, &image_data);
56 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( 57 ImageDecoder::StartWithOptions(this, image_data,
57 this, 58 ImageDecoder::ROBUST_JPEG_CODEC, false);
58 image_data,
59 ImageDecoder::ROBUST_JPEG_CODEC);
60 image_decoder->Start(base::MessageLoopProxy::current());
61 run_loop_.Run(); 59 run_loop_.Run();
62 return decoded_image_.Pass(); 60 return decoded_image_.Pass();
63 } 61 }
64 62
65 void ImageLoader::OnImageDecoded(const ImageDecoder* decoder, 63 void ImageLoader::OnImageDecoded(const SkBitmap& decoded_image) {
66 const SkBitmap& decoded_image) {
67 decoded_image_.reset( 64 decoded_image_.reset(
68 new gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image, 1.0f))); 65 new gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image, 1.0f)));
69 run_loop_.Quit(); 66 run_loop_.Quit();
70 } 67 }
71 68
72 void ImageLoader::OnDecodeImageFailed(const ImageDecoder* decoder) { 69 void ImageLoader::OnDecodeImageFailed() {
73 run_loop_.Quit(); 70 run_loop_.Quit();
74 } 71 }
75 72
76 } // namespace test 73 } // namespace test
77 } // namespace chromeos 74 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698