OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media_galleries/fileapi/av_scanning_file_validator.h" |
| 6 |
| 7 #if defined(OS_WIN) |
| 8 #include <windows.h> |
| 9 #include <shlobj.h> |
| 10 #endif |
| 11 |
| 12 #include "base/bind.h" |
| 13 #include "base/callback.h" |
| 14 #include "base/location.h" |
| 15 #include "base/logging.h" |
| 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/common/chrome_constants.h" |
| 18 #include "content/public/browser/browser_thread.h" |
| 19 |
| 20 #if defined(OS_WIN) |
| 21 #include "base/win/scoped_comptr.h" |
| 22 #endif |
| 23 |
| 24 using content::BrowserThread; |
| 25 |
| 26 namespace chrome { |
| 27 |
| 28 namespace { |
| 29 |
| 30 #if defined(OS_WIN) |
| 31 base::PlatformFileError ScanFile( |
| 32 const base::FilePath& dest_platform_path) { |
| 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 34 |
| 35 base::win::ScopedComPtr<IAttachmentExecute> attachment_services; |
| 36 HRESULT hr = attachment_services.CreateInstance(CLSID_AttachmentServices); |
| 37 |
| 38 if (FAILED(hr)) { |
| 39 // The thread must have COM initialized. |
| 40 DCHECK_NE(CO_E_NOTINITIALIZED, hr); |
| 41 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 42 } |
| 43 |
| 44 hr = attachment_services->SetLocalPath(dest_platform_path.value().c_str()); |
| 45 if (FAILED(hr)) |
| 46 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 47 |
| 48 // A failure in the Save() call below could result in the downloaded file |
| 49 // being deleted. |
| 50 HRESULT scan_result = attachment_services->Save(); |
| 51 if (scan_result == S_OK) |
| 52 return base::PLATFORM_FILE_OK; |
| 53 |
| 54 return base::PLATFORM_FILE_ERROR_SECURITY; |
| 55 } |
| 56 #endif |
| 57 |
| 58 } // namespace |
| 59 |
| 60 AVScanningFileValidator::~AVScanningFileValidator() {} |
| 61 |
| 62 void AVScanningFileValidator::StartPostWriteValidation( |
| 63 const base::FilePath& dest_platform_path, |
| 64 const ResultCallback& result_callback) { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 66 |
| 67 #if defined(OS_WIN) |
| 68 BrowserThread::PostTaskAndReplyWithResult( |
| 69 BrowserThread::FILE, |
| 70 FROM_HERE, |
| 71 base::Bind(&ScanFile, dest_platform_path), |
| 72 result_callback); |
| 73 #else |
| 74 result_callback.Run(base::PLATFORM_FILE_OK); |
| 75 #endif |
| 76 } |
| 77 |
| 78 AVScanningFileValidator::AVScanningFileValidator() { |
| 79 } |
| 80 |
| 81 } // namespace chrome |
OLD | NEW |