| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/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/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" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 base::Bind(&UserImageLoader::DecodeImage, | 60 base::Bind(&UserImageLoader::DecodeImage, |
| 61 this, | 61 this, |
| 62 base::Passed(&data), | 62 base::Passed(&data), |
| 63 ImageInfo(std::string(), pixels_per_side, loaded_cb))); | 63 ImageInfo(std::string(), pixels_per_side, loaded_cb))); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void UserImageLoader::ReadAndDecodeImage(const ImageInfo& image_info) { | 66 void UserImageLoader::ReadAndDecodeImage(const ImageInfo& image_info) { |
| 67 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | 67 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); |
| 68 | 68 |
| 69 scoped_ptr<std::string> data(new std::string); | 69 scoped_ptr<std::string> data(new std::string); |
| 70 const bool success = | 70 if (!base::ReadFileToString(base::FilePath(image_info.file_path), data.get())) |
| 71 base::ReadFileToString(base::FilePath(image_info.file_path), data.get()); | 71 LOG(ERROR) << "Failed to read image " << image_info.file_path; |
| 72 DCHECK(success); | |
| 73 | 72 |
| 73 // In case ReadFileToString() fails, |data| is empty and DecodeImage() calls |
| 74 // back to OnDecodeImageFailed(). |
| 74 DecodeImage(data.Pass(), image_info); | 75 DecodeImage(data.Pass(), image_info); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void UserImageLoader::DecodeImage(const scoped_ptr<std::string> data, | 78 void UserImageLoader::DecodeImage(const scoped_ptr<std::string> data, |
| 78 const ImageInfo& image_info) { | 79 const ImageInfo& image_info) { |
| 79 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | 80 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); |
| 80 | 81 |
| 81 scoped_refptr<ImageDecoder> image_decoder = | 82 scoped_refptr<ImageDecoder> image_decoder = |
| 82 new ImageDecoder(this, *data, image_codec_); | 83 new ImageDecoder(this, *data, image_codec_); |
| 83 image_info_map_.insert(std::make_pair(image_decoder.get(), image_info)); | 84 image_info_map_.insert(std::make_pair(image_decoder.get(), image_info)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 return; | 143 return; |
| 143 } | 144 } |
| 144 const LoadedCallback loaded_cb = it->second.loaded_cb; | 145 const LoadedCallback loaded_cb = it->second.loaded_cb; |
| 145 image_info_map_.erase(it); | 146 image_info_map_.erase(it); |
| 146 | 147 |
| 147 foreground_task_runner_->PostTask(FROM_HERE, | 148 foreground_task_runner_->PostTask(FROM_HERE, |
| 148 base::Bind(loaded_cb, UserImage())); | 149 base::Bind(loaded_cb, UserImage())); |
| 149 } | 150 } |
| 150 | 151 |
| 151 } // namespace chromeos | 152 } // namespace chromeos |
| OLD | NEW |