| OLD | NEW |
| 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/media_galleries/fileapi/supported_image_type_validator.
h" | 5 #include "chrome/browser/media_galleries/fileapi/supported_image_type_validator.
h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 result.reset(new std::string); | 40 result.reset(new std::string); |
| 41 result->resize(file_info.size); | 41 result->resize(file_info.size); |
| 42 if (file.Read(0, string_as_array(result.get()), file_info.size) != | 42 if (file.Read(0, string_as_array(result.get()), file_info.size) != |
| 43 file_info.size) { | 43 file_info.size) { |
| 44 result.reset(); | 44 result.reset(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 return result.Pass(); | 47 return result.Pass(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 class ImageDecoderDelegateAdapter : public ImageDecoder::Delegate { | 50 class ImageDecoderDelegateAdapter : public ImageDecoder::ImageRequest { |
| 51 public: | 51 public: |
| 52 ImageDecoderDelegateAdapter( | 52 ImageDecoderDelegateAdapter( |
| 53 scoped_ptr<std::string> data, | 53 scoped_ptr<std::string> data, |
| 54 const storage::CopyOrMoveFileValidator::ResultCallback& callback) | 54 const storage::CopyOrMoveFileValidator::ResultCallback& callback) |
| 55 : data_(data.Pass()), callback_(callback) { | 55 : ImageRequest(content::BrowserThread::GetMessageLoopProxyForThread( |
| 56 BrowserThread::IO)), |
| 57 data_(data.Pass()), |
| 58 callback_(callback) { |
| 56 DCHECK(data_); | 59 DCHECK(data_); |
| 57 } | 60 } |
| 58 | 61 |
| 59 const std::string& data() { | 62 const std::string& data() { |
| 60 return *data_; | 63 return *data_; |
| 61 } | 64 } |
| 62 | 65 |
| 63 // ImageDecoder::Delegate methods. | 66 // ImageDecoder::ImageRequest methods. |
| 64 void OnImageDecoded(const ImageDecoder* /*decoder*/, | 67 void OnImageDecoded(const SkBitmap& /*decoded_image*/) override { |
| 65 const SkBitmap& /*decoded_image*/) override { | |
| 66 callback_.Run(base::File::FILE_OK); | 68 callback_.Run(base::File::FILE_OK); |
| 67 delete this; | 69 delete this; |
| 68 } | 70 } |
| 69 | 71 |
| 70 void OnDecodeImageFailed(const ImageDecoder* /*decoder*/) override { | 72 void OnDecodeImageFailed() override { |
| 71 callback_.Run(base::File::FILE_ERROR_SECURITY); | 73 callback_.Run(base::File::FILE_ERROR_SECURITY); |
| 72 delete this; | 74 delete this; |
| 73 } | 75 } |
| 74 | 76 |
| 75 private: | 77 private: |
| 76 scoped_ptr<std::string> data_; | 78 scoped_ptr<std::string> data_; |
| 77 storage::CopyOrMoveFileValidator::ResultCallback callback_; | 79 storage::CopyOrMoveFileValidator::ResultCallback callback_; |
| 78 | 80 |
| 79 DISALLOW_COPY_AND_ASSIGN(ImageDecoderDelegateAdapter); | 81 DISALLOW_COPY_AND_ASSIGN(ImageDecoderDelegateAdapter); |
| 80 }; | 82 }; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 void SupportedImageTypeValidator::OnFileOpen(scoped_ptr<std::string> data) { | 122 void SupportedImageTypeValidator::OnFileOpen(scoped_ptr<std::string> data) { |
| 121 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 123 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 122 if (!data.get()) { | 124 if (!data.get()) { |
| 123 callback_.Run(base::File::FILE_ERROR_SECURITY); | 125 callback_.Run(base::File::FILE_ERROR_SECURITY); |
| 124 return; | 126 return; |
| 125 } | 127 } |
| 126 | 128 |
| 127 // |adapter| will delete itself after a completion message is received. | 129 // |adapter| will delete itself after a completion message is received. |
| 128 ImageDecoderDelegateAdapter* adapter = | 130 ImageDecoderDelegateAdapter* adapter = |
| 129 new ImageDecoderDelegateAdapter(data.Pass(), callback_); | 131 new ImageDecoderDelegateAdapter(data.Pass(), callback_); |
| 130 decoder_ = new ImageDecoder(adapter, adapter->data(), | 132 ImageDecoder::Start(adapter, adapter->data()); |
| 131 ImageDecoder::DEFAULT_CODEC); | |
| 132 decoder_->Start(content::BrowserThread::GetMessageLoopProxyForThread( | |
| 133 BrowserThread::IO)); | |
| 134 } | 133 } |
| OLD | NEW |