Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / av_scanning_file_validator.cc
blob8df32b639c21a3f6af6fc557932d242d1d4f1d18
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"
7 #if defined(OS_WIN)
8 #include <windows.h>
9 #include <shlobj.h>
10 #endif
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"
20 #if defined(OS_WIN)
21 #include "base/win/scoped_comptr.h"
22 #endif
24 using content::BrowserThread;
26 namespace {
28 #if defined(OS_WIN)
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);
35 if (FAILED(hr)) {
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());
42 if (FAILED(hr))
43 return base::File::FILE_ERROR_SECURITY;
45 // A failure in the Save() call below could result in the downloaded file
46 // being deleted.
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;
53 #endif
55 } // namespace
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);
64 #if defined(OS_WIN)
65 BrowserThread::PostTaskAndReplyWithResult(
66 BrowserThread::FILE,
67 FROM_HERE,
68 base::Bind(&ScanFile, dest_platform_path),
69 result_callback);
70 #else
71 result_callback.Run(base::File::FILE_OK);
72 #endif
75 AVScanningFileValidator::AVScanningFileValidator() {