OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/user_image_loader.h" | 5 #include "chrome/browser/chromeos/login/user_image_loader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
11 #include "chrome/browser/chromeos/login/helper.h" | 12 #include "chrome/browser/chromeos/login/helper.h" |
| 13 #include "chrome/browser/chromeos/login/user_image.h" |
12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
13 #include "skia/ext/image_operations.h" | 15 #include "skia/ext/image_operations.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
15 #include "ui/gfx/codec/png_codec.h" | 17 #include "ui/gfx/codec/png_codec.h" |
16 #include "ui/gfx/skbitmap_operations.h" | 18 #include "ui/gfx/skbitmap_operations.h" |
17 | 19 |
18 using content::BrowserThread; | 20 using content::BrowserThread; |
19 | 21 |
20 namespace chromeos { | 22 namespace chromeos { |
21 | 23 |
22 UserImageLoader::ImageInfo::ImageInfo(int size, const LoadedCallback& loaded_cb) | 24 UserImageLoader::ImageInfo::ImageInfo(int size, |
| 25 bool load_raw_image, |
| 26 const LoadedCallback& loaded_cb) |
23 : size(size), | 27 : size(size), |
| 28 load_raw_image(load_raw_image), |
24 loaded_cb(loaded_cb) { | 29 loaded_cb(loaded_cb) { |
25 } | 30 } |
26 | 31 |
27 UserImageLoader::ImageInfo::~ImageInfo() { | 32 UserImageLoader::ImageInfo::~ImageInfo() { |
28 } | 33 } |
29 | 34 |
30 UserImageLoader::UserImageLoader() | 35 UserImageLoader::UserImageLoader() |
31 : target_message_loop_(NULL) { | 36 : target_message_loop_(NULL) { |
32 } | 37 } |
33 | 38 |
34 UserImageLoader::~UserImageLoader() { | 39 UserImageLoader::~UserImageLoader() { |
35 } | 40 } |
36 | 41 |
37 void UserImageLoader::Start(const std::string& filepath, | 42 void UserImageLoader::Start(const std::string& filepath, |
38 int size, | 43 int size, |
| 44 bool load_raw_image, |
39 const LoadedCallback& loaded_cb) { | 45 const LoadedCallback& loaded_cb) { |
40 target_message_loop_ = MessageLoop::current(); | 46 target_message_loop_ = MessageLoop::current(); |
41 | 47 |
42 ImageInfo image_info(size, loaded_cb); | 48 ImageInfo image_info(size, load_raw_image, loaded_cb); |
43 BrowserThread::PostTask( | 49 BrowserThread::PostTask( |
44 BrowserThread::FILE, FROM_HERE, | 50 BrowserThread::FILE, FROM_HERE, |
45 base::Bind(&UserImageLoader::LoadImage, this, filepath, image_info)); | 51 base::Bind(&UserImageLoader::LoadImage, this, filepath, image_info)); |
46 } | 52 } |
47 | 53 |
48 void UserImageLoader::LoadImage(const std::string& filepath, | 54 void UserImageLoader::LoadImage(const std::string& filepath, |
49 const ImageInfo& image_info) { | 55 const ImageInfo& image_info) { |
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
51 | 57 |
52 std::string image_data; | 58 std::string image_data; |
(...skipping 26 matching lines...) Expand all Loading... |
79 int y = (decoded_image.height() - size) / 2; | 85 int y = (decoded_image.height() - size) / 2; |
80 SkBitmap cropped_image = | 86 SkBitmap cropped_image = |
81 SkBitmapOperations::CreateTiledBitmap(decoded_image, x, y, size, size); | 87 SkBitmapOperations::CreateTiledBitmap(decoded_image, x, y, size, size); |
82 final_image = | 88 final_image = |
83 skia::ImageOperations::Resize(cropped_image, | 89 skia::ImageOperations::Resize(cropped_image, |
84 skia::ImageOperations::RESIZE_LANCZOS3, | 90 skia::ImageOperations::RESIZE_LANCZOS3, |
85 image_info.size, | 91 image_info.size, |
86 image_info.size); | 92 image_info.size); |
87 } | 93 } |
88 | 94 |
| 95 scoped_ptr<UserImage> user_image; |
| 96 if (image_info.load_raw_image) |
| 97 user_image.reset(new UserImage(final_image, decoder->get_image_data())); |
| 98 else |
| 99 user_image.reset(new UserImage(final_image)); |
| 100 |
89 target_message_loop_->PostTask( | 101 target_message_loop_->PostTask( |
90 FROM_HERE, | 102 FROM_HERE, |
91 base::Bind(image_info.loaded_cb, final_image)); | 103 base::Bind(image_info.loaded_cb, *user_image)); |
92 | 104 |
93 image_info_map_.erase(info_it); | 105 image_info_map_.erase(info_it); |
94 } | 106 } |
95 | 107 |
96 void UserImageLoader::OnDecodeImageFailed(const ImageDecoder* decoder) { | 108 void UserImageLoader::OnDecodeImageFailed(const ImageDecoder* decoder) { |
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
98 image_info_map_.erase(decoder); | 110 image_info_map_.erase(decoder); |
99 } | 111 } |
100 | 112 |
101 } // namespace chromeos | 113 } // namespace chromeos |
OLD | NEW |