Index: chrome/browser/media_galleries/fileapi/scanning_file_validator.cc |
diff --git a/chrome/browser/media_galleries/fileapi/scanning_file_validator.cc b/chrome/browser/media_galleries/fileapi/scanning_file_validator.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6272922a3307450b2d6c142ea0f2f672e71bacb0 |
--- /dev/null |
+++ b/chrome/browser/media_galleries/fileapi/scanning_file_validator.cc |
@@ -0,0 +1,87 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// 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/scanning_file_validator.h" |
+ |
+#if defined(OS_WIN) |
+#include <objbase.h> |
vandebo (ex-Chrome)
2013/08/07 16:13:14
Are these needed?
Greg Billock
2013/08/07 17:00:56
yes
|
+#include <windows.h> |
+#endif |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/files/scoped_platform_file_closer.h" |
vandebo (ex-Chrome)
2013/08/07 16:13:14
Lots of unused headers. At least:
scoped_platfor
Greg Billock
2013/08/07 17:00:56
Done.
|
+#include "base/guid.h" |
+#include "base/location.h" |
+#include "base/logging.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/stl_util.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "base/threading/thread_restrictions.h" |
+#include "chrome/common/chrome_constants.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+#if defined(OS_WIN) |
+#include "base/file_util.h" |
+#endif |
+ |
+using content::BrowserThread; |
+ |
+namespace chrome { |
+ |
+namespace { |
+ |
+#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; |
vandebo (ex-Chrome)
2013/08/07 16:13:14
I don't think you need this.
Greg Billock
2013/08/07 17:00:56
Moved lower
|
+ |
+ std::string client_guid(chrome::kApplicationClientIDStringForAVScanning); |
+ |
+ GUID guid = GUID_NULL; |
+ if (!client_guid.empty() && base::IsValidGUID(client_guid)) { |
Lei Zhang
2013/08/07 01:03:05
I don't think you need this, the constant should a
Greg Billock
2013/08/07 17:00:56
Done.
|
+ HRESULT hr = CLSIDFromString(base::UTF8ToUTF16(client_guid).c_str(), &guid); |
+ if (FAILED(hr)) |
+ guid = GUID_NULL; |
+ } |
+ |
+ // 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::AVScanFile(dest_platform_path, std::string(), |
Lei Zhang
2013/08/07 01:03:05
nit: I'd prefer to wrap after the equal sign.
HRES
Greg Billock
2013/08/07 17:00:56
Done.
|
+ guid); |
+ if (scan_result != S_OK) |
+ result = base::PLATFORM_FILE_ERROR_SECURITY; |
vandebo (ex-Chrome)
2013/08/07 16:13:14
Just return here.
Greg Billock
2013/08/07 17:00:56
Done.
|
+ |
+ return result; |
+} |
+#endif |
+ |
+} // namespace |
+ |
+ScanningFileValidator::~ScanningFileValidator() {} |
+ |
+void ScanningFileValidator::StartPostWriteValidation( |
+ const base::FilePath& dest_platform_path, |
+ const ResultCallback& result_callback) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ |
+#if defined(OS_WIN) |
+ BrowserThread::PostTaskAndReplyWithResult( |
+ BrowserThread::FILE, |
+ FROM_HERE, |
+ base::Bind(&ScanFile, dest_platform_path), |
+ result_callback); |
+#else |
+ result_callback.Run(base::PLATFORM_FILE_OK); |
+#endif |
+} |
+ |
+ScanningFileValidator::ScanningFileValidator() { |
+} |
+ |
+} // namespace chrome |