OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h" | 5 #include "chrome/browser/safe_browsing/sandboxed_zip_analyzer.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 void SandboxedZipAnalyzer::Start() { | 25 void SandboxedZipAnalyzer::Start() { |
26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
27 | 27 |
28 base::PostTaskWithTraits( | 28 base::PostTaskWithTraits( |
29 FROM_HERE, | 29 FROM_HERE, |
30 base::TaskTraits() | 30 base::TaskTraits() |
31 .MayBlock() | 31 .MayBlock() |
32 .WithPriority(base::TaskPriority::BACKGROUND) | 32 .WithPriority(base::TaskPriority::BACKGROUND) |
33 .WithShutdownBehavior( | 33 .WithShutdownBehavior( |
34 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), | 34 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
35 base::Bind(&SandboxedZipAnalyzer::PrepareFileToAnalyze, this)); | 35 base::BindOnce(&SandboxedZipAnalyzer::PrepareFileToAnalyze, this)); |
36 } | 36 } |
37 | 37 |
38 SandboxedZipAnalyzer::~SandboxedZipAnalyzer() = default; | 38 SandboxedZipAnalyzer::~SandboxedZipAnalyzer() = default; |
39 | 39 |
40 void SandboxedZipAnalyzer::PrepareFileToAnalyze() { | 40 void SandboxedZipAnalyzer::PrepareFileToAnalyze() { |
41 base::File file(file_path_, base::File::FLAG_OPEN | base::File::FLAG_READ); | 41 base::File file(file_path_, base::File::FLAG_OPEN | base::File::FLAG_READ); |
42 | 42 |
43 if (!file.IsValid()) { | 43 if (!file.IsValid()) { |
44 DLOG(ERROR) << "Could not open file: " << file_path_.value(); | 44 DLOG(ERROR) << "Could not open file: " << file_path_.value(); |
45 ReportFileFailure(); | 45 ReportFileFailure(); |
(...skipping 10 matching lines...) Expand all Loading... |
56 } | 56 } |
57 | 57 |
58 if (!temp_file.IsValid()) { | 58 if (!temp_file.IsValid()) { |
59 DLOG(ERROR) << "Could not open temp file: " << temp_path.value(); | 59 DLOG(ERROR) << "Could not open temp file: " << temp_path.value(); |
60 ReportFileFailure(); | 60 ReportFileFailure(); |
61 return; | 61 return; |
62 } | 62 } |
63 | 63 |
64 content::BrowserThread::PostTask( | 64 content::BrowserThread::PostTask( |
65 content::BrowserThread::UI, FROM_HERE, | 65 content::BrowserThread::UI, FROM_HERE, |
66 base::Bind(&SandboxedZipAnalyzer::AnalyzeFile, this, base::Passed(&file), | 66 base::BindOnce(&SandboxedZipAnalyzer::AnalyzeFile, this, |
67 base::Passed(&temp_file))); | 67 base::Passed(&file), base::Passed(&temp_file))); |
68 } | 68 } |
69 | 69 |
70 void SandboxedZipAnalyzer::ReportFileFailure() { | 70 void SandboxedZipAnalyzer::ReportFileFailure() { |
71 DCHECK(!utility_process_mojo_client_); | 71 DCHECK(!utility_process_mojo_client_); |
72 | 72 |
73 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 73 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
74 base::Bind(callback_, Results())); | 74 base::BindOnce(callback_, Results())); |
75 } | 75 } |
76 | 76 |
77 void SandboxedZipAnalyzer::AnalyzeFile(base::File file, base::File temp_file) { | 77 void SandboxedZipAnalyzer::AnalyzeFile(base::File file, base::File temp_file) { |
78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
79 DCHECK(!utility_process_mojo_client_); | 79 DCHECK(!utility_process_mojo_client_); |
80 | 80 |
81 utility_process_mojo_client_ = base::MakeUnique< | 81 utility_process_mojo_client_ = base::MakeUnique< |
82 content::UtilityProcessMojoClient<chrome::mojom::SafeArchiveAnalyzer>>( | 82 content::UtilityProcessMojoClient<chrome::mojom::SafeArchiveAnalyzer>>( |
83 l10n_util::GetStringUTF16( | 83 l10n_util::GetStringUTF16( |
84 IDS_UTILITY_PROCESS_SAFE_BROWSING_ZIP_FILE_ANALYZER_NAME)); | 84 IDS_UTILITY_PROCESS_SAFE_BROWSING_ZIP_FILE_ANALYZER_NAME)); |
85 utility_process_mojo_client_->set_error_callback( | 85 utility_process_mojo_client_->set_error_callback( |
86 base::Bind(&SandboxedZipAnalyzer::AnalyzeFileDone, this, Results())); | 86 base::Bind(&SandboxedZipAnalyzer::AnalyzeFileDone, this, Results())); |
87 | 87 |
88 utility_process_mojo_client_->Start(); | 88 utility_process_mojo_client_->Start(); |
89 | 89 |
90 utility_process_mojo_client_->service()->AnalyzeZipFile( | 90 utility_process_mojo_client_->service()->AnalyzeZipFile( |
91 std::move(file), std::move(temp_file), | 91 std::move(file), std::move(temp_file), |
92 base::Bind(&SandboxedZipAnalyzer::AnalyzeFileDone, this)); | 92 base::Bind(&SandboxedZipAnalyzer::AnalyzeFileDone, this)); |
93 } | 93 } |
94 | 94 |
95 void SandboxedZipAnalyzer::AnalyzeFileDone(const Results& results) { | 95 void SandboxedZipAnalyzer::AnalyzeFileDone(const Results& results) { |
96 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 96 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
97 | 97 |
98 utility_process_mojo_client_.reset(); | 98 utility_process_mojo_client_.reset(); |
99 callback_.Run(results); | 99 callback_.Run(results); |
100 } | 100 } |
101 | 101 |
102 } // namespace safe_browsing | 102 } // namespace safe_browsing |
OLD | NEW |