Chromium Code Reviews| Index: chrome/browser/media_galleries/fileapi/scanning_file_validator.cc |
| diff --git a/chrome/browser/media_galleries/fileapi/supported_image_type_validator.cc b/chrome/browser/media_galleries/fileapi/scanning_file_validator.cc |
| similarity index 67% |
| copy from chrome/browser/media_galleries/fileapi/supported_image_type_validator.cc |
| copy to chrome/browser/media_galleries/fileapi/scanning_file_validator.cc |
| index 9ae76253c3bb4db6d4584970202449ed06684405..a2f63fd5b276b3fdec4d26388c46f83a5e7909ec 100644 |
| --- a/chrome/browser/media_galleries/fileapi/supported_image_type_validator.cc |
| +++ b/chrome/browser/media_galleries/fileapi/scanning_file_validator.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/media_galleries/fileapi/supported_image_type_validator.h" |
| +#include "chrome/browser/media_galleries/fileapi/scanning_file_validator.h" |
| #include "base/bind.h" |
| #include "base/callback.h" |
| @@ -13,9 +13,12 @@ |
| #include "base/memory/weak_ptr.h" |
| #include "base/stl_util.h" |
| #include "base/threading/thread_restrictions.h" |
| -#include "chrome/browser/image_decoder.h" |
| #include "content/public/browser/browser_thread.h" |
| +#if defined(OS_WIN) |
| +#include "base/file_util.h" |
| +#endif |
| + |
| using content::BrowserThread; |
| namespace chrome { |
| @@ -51,38 +54,25 @@ scoped_ptr<std::string> ReadOnFileThread(const base::FilePath& path) { |
| return result.Pass(); |
| } |
| -class ImageDecoderDelegateAdapter : public ImageDecoder::Delegate { |
| - public: |
| - ImageDecoderDelegateAdapter( |
| - scoped_ptr<std::string> data, |
| - const fileapi::CopyOrMoveFileValidator::ResultCallback& callback) |
| - : data_(data.Pass()), |
| - callback_(callback) { |
| - DCHECK(data_); |
| - } |
| - |
| - const std::string& data() { |
| - return *data_; |
| - } |
| - |
| - // ImageDecoder::Delegate methods. |
| - virtual void OnImageDecoded(const ImageDecoder* /*decoder*/, |
| - const SkBitmap& /*decoded_image*/) OVERRIDE { |
| - callback_.Run(base::PLATFORM_FILE_OK); |
| - delete this; |
| - } |
| - |
| - virtual void OnDecodeImageFailed(const ImageDecoder* /*decoder*/) OVERRIDE { |
| - callback_.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
| - delete this; |
| - } |
| - |
| - private: |
| - scoped_ptr<std::string> data_; |
| - fileapi::CopyOrMoveFileValidator::ResultCallback callback_; |
| +#if defined(OS_WIN) |
| +base::PlatformFileError ScanFile( |
| + const base::FilePath& dest_platform_path) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + base::PlatformFileError result = base::PLATFORM_FILE_OK; |
| + |
| + // Execute an AV check of the transferred file. S_OK means |
| + // the file was OK. Other results may indicate the file was |
| + // deleted. Any other results, including E_FAIL and |
| + // INET_E_SECURITY_PROBLEM, are notified as security errors. |
| + HRESULT scan_result = |
| + base::ScanAndSaveDownloadedFile(dest_platform_path, std::string()); |
| + if (scan_result != S_OK) |
| + result = base::PLATFORM_FILE_ERROR_SECURITY; |
| + |
| + return result; |
| +} |
| +#endif |
| - DISALLOW_COPY_AND_ASSIGN(ImageDecoderDelegateAdapter); |
| -}; |
| } // namespace |
| @@ -120,13 +110,19 @@ void SupportedImageTypeValidator::StartPostWriteValidation( |
| const base::FilePath& dest_platform_path, |
| const ResultCallback& result_callback) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - post_write_callback_ = result_callback; |
| - // TODO(gbillock): Insert AV call here in the right validator. |
| +#if defined(OS_WIN) |
| + BrowserThread::PostTaskAndReplyWithResult( |
| + BrowserThread::FILE, |
| + FROM_HERE, |
| + base::Bind(&ScanFile, dest_platform_path), |
| + result_callback); |
| +#else |
| BrowserThread::PostTask( |
|
vandebo (ex-Chrome)
2013/08/05 18:05:30
no need to post task here, just run the callback.
Greg Billock
2013/08/05 21:42:30
Done.
|
| BrowserThread::IO, |
| FROM_HERE, |
| - base::Bind(post_write_callback_, base::PLATFORM_FILE_OK)); |
| + base::Bind(result_callback, base::PLATFORM_FILE_OK)); |
| +#endif |
| } |
| SupportedImageTypeValidator::SupportedImageTypeValidator( |
| @@ -142,13 +138,10 @@ void SupportedImageTypeValidator::OnFileOpen(scoped_ptr<std::string> data) { |
| return; |
| } |
| - // |adapter| will delete itself after a completion message is received. |
| - ImageDecoderDelegateAdapter* adapter = |
| - new ImageDecoderDelegateAdapter(data.Pass(), callback_); |
| - decoder_ = new ImageDecoder(adapter, adapter->data(), |
| - ImageDecoder::DEFAULT_CODEC); |
| - decoder_->Start(content::BrowserThread::GetMessageLoopProxyForThread( |
| - BrowserThread::IO)); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(callback_, base::PLATFORM_FILE_OK)); |
| } |
| } // namespace chrome |