OLD | NEW |
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_loader.h" | 5 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
14 #include "chrome/browser/chromeos/login/helper.h" | 14 #include "chrome/browser/chromeos/login/helper.h" |
15 #include "chrome/browser/chromeos/login/users/avatar/user_image.h" | 15 #include "components/user_manager/user_image/user_image.h" |
16 #include "skia/ext/image_operations.h" | 16 #include "skia/ext/image_operations.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
18 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
19 #include "ui/gfx/skbitmap_operations.h" | 19 #include "ui/gfx/skbitmap_operations.h" |
20 | 20 |
21 namespace chromeos { | 21 namespace chromeos { |
22 | 22 |
23 UserImageLoader::ImageInfo::ImageInfo(const std::string& file_path, | 23 UserImageLoader::ImageInfo::ImageInfo(const std::string& file_path, |
24 int pixels_per_side, | 24 int pixels_per_side, |
25 const LoadedCallback& loaded_cb) | 25 const LoadedCallback& loaded_cb) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } else { | 119 } else { |
120 final_image = cropped_image; | 120 final_image = cropped_image; |
121 } | 121 } |
122 } | 122 } |
123 // Make the SkBitmap immutable as we won't modify it. This is important | 123 // Make the SkBitmap immutable as we won't modify it. This is important |
124 // because otherwise it gets duplicated during painting, wasting memory. | 124 // because otherwise it gets duplicated during painting, wasting memory. |
125 final_image.setImmutable(); | 125 final_image.setImmutable(); |
126 gfx::ImageSkia final_image_skia = | 126 gfx::ImageSkia final_image_skia = |
127 gfx::ImageSkia::CreateFrom1xBitmap(final_image); | 127 gfx::ImageSkia::CreateFrom1xBitmap(final_image); |
128 final_image_skia.MakeThreadSafe(); | 128 final_image_skia.MakeThreadSafe(); |
129 UserImage user_image(final_image_skia, decoder->get_image_data()); | 129 user_manager::UserImage user_image(final_image_skia, |
| 130 decoder->get_image_data()); |
130 user_image.set_file_path(file_path); | 131 user_image.set_file_path(file_path); |
131 if (image_codec_ == ImageDecoder::ROBUST_JPEG_CODEC) | 132 if (image_codec_ == ImageDecoder::ROBUST_JPEG_CODEC) |
132 user_image.MarkAsSafe(); | 133 user_image.MarkAsSafe(); |
133 foreground_task_runner_->PostTask(FROM_HERE, | 134 foreground_task_runner_->PostTask(FROM_HERE, |
134 base::Bind(loaded_cb, user_image)); | 135 base::Bind(loaded_cb, user_image)); |
135 } | 136 } |
136 | 137 |
137 void UserImageLoader::OnDecodeImageFailed(const ImageDecoder* decoder) { | 138 void UserImageLoader::OnDecodeImageFailed(const ImageDecoder* decoder) { |
138 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | 139 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); |
139 | 140 |
140 ImageInfoMap::iterator it = image_info_map_.find(decoder); | 141 ImageInfoMap::iterator it = image_info_map_.find(decoder); |
141 if (it == image_info_map_.end()) { | 142 if (it == image_info_map_.end()) { |
142 NOTREACHED(); | 143 NOTREACHED(); |
143 return; | 144 return; |
144 } | 145 } |
145 const LoadedCallback loaded_cb = it->second.loaded_cb; | 146 const LoadedCallback loaded_cb = it->second.loaded_cb; |
146 image_info_map_.erase(it); | 147 image_info_map_.erase(it); |
147 | 148 |
148 foreground_task_runner_->PostTask(FROM_HERE, | 149 foreground_task_runner_->PostTask( |
149 base::Bind(loaded_cb, UserImage())); | 150 FROM_HERE, base::Bind(loaded_cb, user_manager::UserImage())); |
150 } | 151 } |
151 | 152 |
152 } // namespace chromeos | 153 } // namespace chromeos |
OLD | NEW |