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.
5 #include "chrome/browser/media_galleries/fileapi/av_scanning_file_validator.h"
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"
21 #include "base/win/scoped_comptr.h"
24 using content::BrowserThread
;
29 base::File::Error
ScanFile(const base::FilePath
& dest_platform_path
) {
30 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
32 base::win::ScopedComPtr
<IAttachmentExecute
> attachment_services
;
33 HRESULT hr
= attachment_services
.CreateInstance(CLSID_AttachmentServices
);
36 // The thread must have COM initialized.
37 DCHECK_NE(CO_E_NOTINITIALIZED
, hr
);
38 return base::File::FILE_ERROR_SECURITY
;
41 hr
= attachment_services
->SetLocalPath(dest_platform_path
.value().c_str());
43 return base::File::FILE_ERROR_SECURITY
;
45 // A failure in the Save() call below could result in the downloaded file
47 HRESULT scan_result
= attachment_services
->Save();
48 if (scan_result
== S_OK
)
49 return base::File::FILE_OK
;
51 return base::File::FILE_ERROR_SECURITY
;
57 AVScanningFileValidator::~AVScanningFileValidator() {}
59 void AVScanningFileValidator::StartPostWriteValidation(
60 const base::FilePath
& dest_platform_path
,
61 const ResultCallback
& result_callback
) {
62 DCHECK_CURRENTLY_ON(BrowserThread::IO
);
65 BrowserThread::PostTaskAndReplyWithResult(
68 base::Bind(&ScanFile
, dest_platform_path
),
71 result_callback
.Run(base::File::FILE_OK
);
75 AVScanningFileValidator::AVScanningFileValidator() {