Chromium Code Reviews| Index: chrome/browser/media_galleries/fileapi/av_scanning_file_validator.cc |
| diff --git a/chrome/browser/media_galleries/fileapi/av_scanning_file_validator.cc b/chrome/browser/media_galleries/fileapi/av_scanning_file_validator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d2349667fb67ad187a57ad3f1599d06e5b533fa1 |
| --- /dev/null |
| +++ b/chrome/browser/media_galleries/fileapi/av_scanning_file_validator.cc |
| @@ -0,0 +1,80 @@ |
| +// 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/av_scanning_file_validator.h" |
| + |
| +#if defined(OS_WIN) |
| +#include <windows.h> |
| +#endif |
| + |
| +#include "base/bind.h" |
| +#include "base/callback.h" |
| +#include "base/location.h" |
| +#include "base/logging.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/common/chrome_constants.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +#if defined(OS_WIN) |
| +#include "base/win/scoped_comptr.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)); |
| + |
| + win::ScopedComPtr<IAttachmentExecute> attachment_services; |
| + HRESULT hr = attachment_services.CreateInstance(CLSID_AttachmentServices); |
| + |
| + if (FAILED(hr)) { |
| + // The thread must have COM initialized. |
| + DCHECK_NE(CO_E_NOTINITIALIZED, hr); |
| + return hr; |
|
vandebo (ex-Chrome)
2013/08/07 18:36:01
We don't want to return hr here.
Greg Billock
2013/08/07 18:41:32
Done.
|
| + } |
| + |
| + hr = attachment_services->SetLocalPath(full_path.value().c_str()); |
| + if (FAILED(hr)) |
| + return hr; |
|
vandebo (ex-Chrome)
2013/08/07 18:36:01
or here
Greg Billock
2013/08/07 18:41:32
Done.
|
| + |
| + // A failure in the Save() call below could result in the downloaded file |
| + // being deleted. |
| + HRESULT scan_result = attachment_services->Save(); |
| + if (scan_result == S_OK) |
| + return base::PLATFORM_FILE_OK; |
| + |
| + return base::PLATFORM_FILE_ERROR_SECURITY; |
| +} |
| +#endif |
| + |
| +} // namespace |
| + |
| +AVScanningFileValidator::~AVScanningFileValidator() {} |
| + |
| +void AVScanningFileValidator::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 |
| +} |
| + |
| +AVScanningFileValidator::AVScanningFileValidator() { |
| +} |
| + |
| +} // namespace chrome |