Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: chrome/browser/media_galleries/fileapi/scanning_file_validator.cc

Issue 21355004: [Downloads] Move client guid for AV scanning of downloaded files to chrome/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 55%
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..e37c751b64210e54f5c8e71eb3503e83907a6369 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,57 +54,30 @@ 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
SupportedImageTypeValidator::~SupportedImageTypeValidator() {}
Lei Zhang 2013/08/05 22:42:40 This isn't right. Shouldn't it be ScanningFileVali
Greg Billock 2013/08/05 23:06:12 Yes. I'm updating it in the next patchset. This wa
-// static
-bool SupportedImageTypeValidator::SupportsFileType(const base::FilePath& path) {
- base::FilePath::StringType extension = path.Extension();
- return extension == FILE_PATH_LITERAL(".bmp") ||
- extension == FILE_PATH_LITERAL(".gif") ||
- extension == FILE_PATH_LITERAL(".jfif") ||
- extension == FILE_PATH_LITERAL(".jpeg") ||
- extension == FILE_PATH_LITERAL(".jpg") ||
- extension == FILE_PATH_LITERAL(".pjp") ||
- extension == FILE_PATH_LITERAL(".pjpeg") ||
- extension == FILE_PATH_LITERAL(".png") ||
- extension == FILE_PATH_LITERAL(".webp");
-}
-
void SupportedImageTypeValidator::StartPreWriteValidation(
const ResultCallback& result_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
@@ -120,13 +96,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(
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 +124,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

Powered by Google App Engine
This is Rietveld 408576698