Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / media_galleries / fileapi / av_scanning_file_validator.cc
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 {
27
28 #if defined(OS_WIN)
29 base::File::Error ScanFile(const base::FilePath& dest_platform_path) {
30   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
31
32   base::win::ScopedComPtr<IAttachmentExecute> attachment_services;
33   HRESULT hr = attachment_services.CreateInstance(CLSID_AttachmentServices);
34
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;
39   }
40
41   hr = attachment_services->SetLocalPath(dest_platform_path.value().c_str());
42   if (FAILED(hr))
43     return base::File::FILE_ERROR_SECURITY;
44
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;
50
51   return base::File::FILE_ERROR_SECURITY;
52 }
53 #endif
54
55 }  // namespace
56
57 AVScanningFileValidator::~AVScanningFileValidator() {}
58
59 void AVScanningFileValidator::StartPostWriteValidation(
60     const base::FilePath& dest_platform_path,
61     const ResultCallback& result_callback) {
62   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
63
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
73 }
74
75 AVScanningFileValidator::AVScanningFileValidator() {
76 }