| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::Delegate { |
| 51 public: | 51 public: |
| 52 ImageDecoderDelegateAdapter( | 52 ImageDecoderDelegateAdapter( |
| 53 scoped_ptr<std::string> data, | 53 scoped_ptr<std::string> data, |
| 54 const fileapi::CopyOrMoveFileValidator::ResultCallback& callback) | 54 const storage::CopyOrMoveFileValidator::ResultCallback& callback) |
| 55 : data_(data.Pass()), | 55 : data_(data.Pass()), callback_(callback) { |
| 56 callback_(callback) { | |
| 57 DCHECK(data_); | 56 DCHECK(data_); |
| 58 } | 57 } |
| 59 | 58 |
| 60 const std::string& data() { | 59 const std::string& data() { |
| 61 return *data_; | 60 return *data_; |
| 62 } | 61 } |
| 63 | 62 |
| 64 // ImageDecoder::Delegate methods. | 63 // ImageDecoder::Delegate methods. |
| 65 virtual void OnImageDecoded(const ImageDecoder* /*decoder*/, | 64 virtual void OnImageDecoded(const ImageDecoder* /*decoder*/, |
| 66 const SkBitmap& /*decoded_image*/) OVERRIDE { | 65 const SkBitmap& /*decoded_image*/) OVERRIDE { |
| 67 callback_.Run(base::File::FILE_OK); | 66 callback_.Run(base::File::FILE_OK); |
| 68 delete this; | 67 delete this; |
| 69 } | 68 } |
| 70 | 69 |
| 71 virtual void OnDecodeImageFailed(const ImageDecoder* /*decoder*/) OVERRIDE { | 70 virtual void OnDecodeImageFailed(const ImageDecoder* /*decoder*/) OVERRIDE { |
| 72 callback_.Run(base::File::FILE_ERROR_SECURITY); | 71 callback_.Run(base::File::FILE_ERROR_SECURITY); |
| 73 delete this; | 72 delete this; |
| 74 } | 73 } |
| 75 | 74 |
| 76 private: | 75 private: |
| 77 scoped_ptr<std::string> data_; | 76 scoped_ptr<std::string> data_; |
| 78 fileapi::CopyOrMoveFileValidator::ResultCallback callback_; | 77 storage::CopyOrMoveFileValidator::ResultCallback callback_; |
| 79 | 78 |
| 80 DISALLOW_COPY_AND_ASSIGN(ImageDecoderDelegateAdapter); | 79 DISALLOW_COPY_AND_ASSIGN(ImageDecoderDelegateAdapter); |
| 81 }; | 80 }; |
| 82 | 81 |
| 83 } // namespace | 82 } // namespace |
| 84 | 83 |
| 85 SupportedImageTypeValidator::~SupportedImageTypeValidator() {} | 84 SupportedImageTypeValidator::~SupportedImageTypeValidator() {} |
| 86 | 85 |
| 87 // static | 86 // static |
| 88 bool SupportedImageTypeValidator::SupportsFileType(const base::FilePath& path) { | 87 bool SupportedImageTypeValidator::SupportsFileType(const base::FilePath& path) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 125 } |
| 127 | 126 |
| 128 // |adapter| will delete itself after a completion message is received. | 127 // |adapter| will delete itself after a completion message is received. |
| 129 ImageDecoderDelegateAdapter* adapter = | 128 ImageDecoderDelegateAdapter* adapter = |
| 130 new ImageDecoderDelegateAdapter(data.Pass(), callback_); | 129 new ImageDecoderDelegateAdapter(data.Pass(), callback_); |
| 131 decoder_ = new ImageDecoder(adapter, adapter->data(), | 130 decoder_ = new ImageDecoder(adapter, adapter->data(), |
| 132 ImageDecoder::DEFAULT_CODEC); | 131 ImageDecoder::DEFAULT_CODEC); |
| 133 decoder_->Start(content::BrowserThread::GetMessageLoopProxyForThread( | 132 decoder_->Start(content::BrowserThread::GetMessageLoopProxyForThread( |
| 134 BrowserThread::IO)); | 133 BrowserThread::IO)); |
| 135 } | 134 } |
| OLD | NEW |