| 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_ZIP_ANALYZER_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_ZIP_ANALYZER_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_ZIP_ANALYZER_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_ZIP_ANALYZER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "chrome/common/safe_archive_analyzer.mojom.h" | 13 #include "chrome/common/safe_archive_analyzer.mojom.h" |
| 14 #include "chrome/common/safe_browsing/archive_analyzer_results.h" |
| 14 #include "content/public/browser/utility_process_mojo_client.h" | 15 #include "content/public/browser/utility_process_mojo_client.h" |
| 15 | 16 |
| 16 namespace safe_browsing { | 17 namespace safe_browsing { |
| 17 | 18 |
| 18 // This class is used to analyze zip files in a sandboxed utility process | 19 // This class is used to analyze zip files in a sandboxed utility process |
| 19 // for file download protection. This class lives on the UI thread, which | 20 // for file download protection. This class lives on the UI thread, which |
| 20 // is where the result callback will be invoked. | 21 // is where the result callback will be invoked. |
| 21 class SandboxedZipAnalyzer | 22 class SandboxedZipAnalyzer |
| 22 : public base::RefCountedThreadSafe<SandboxedZipAnalyzer> { | 23 : public base::RefCountedThreadSafe<SandboxedZipAnalyzer> { |
| 23 public: | 24 public: |
| 24 using Results = zip_analyzer::Results; | 25 using ResultCallback = base::Callback<void(const ArchiveAnalyzerResults&)>; |
| 25 | |
| 26 using ResultCallback = base::Callback<void(const Results&)>; | |
| 27 | 26 |
| 28 SandboxedZipAnalyzer(const base::FilePath& zip_file, | 27 SandboxedZipAnalyzer(const base::FilePath& zip_file, |
| 29 const ResultCallback& callback); | 28 const ResultCallback& callback); |
| 30 | 29 |
| 31 // Starts the analysis. Must be called on the UI thread. | 30 // Starts the analysis. Must be called on the UI thread. |
| 32 void Start(); | 31 void Start(); |
| 33 | 32 |
| 34 private: | 33 private: |
| 35 friend class base::RefCountedThreadSafe<SandboxedZipAnalyzer>; | 34 friend class base::RefCountedThreadSafe<SandboxedZipAnalyzer>; |
| 36 | 35 |
| 37 ~SandboxedZipAnalyzer(); | 36 ~SandboxedZipAnalyzer(); |
| 38 | 37 |
| 39 // Prepare the file for analysis. | 38 // Prepare the file for analysis. |
| 40 void PrepareFileToAnalyze(); | 39 void PrepareFileToAnalyze(); |
| 41 | 40 |
| 42 // If file preparation failed, analysis has failed: report failure. | 41 // If file preparation failed, analysis has failed: report failure. |
| 43 void ReportFileFailure(); | 42 void ReportFileFailure(); |
| 44 | 43 |
| 45 // Starts the utility process and sends it a file analyze request. | 44 // Starts the utility process and sends it a file analyze request. |
| 46 void AnalyzeFile(base::File file, base::File temp); | 45 void AnalyzeFile(base::File file, base::File temp); |
| 47 | 46 |
| 48 // The response containing the file analyze results. | 47 // The response containing the file analyze results. |
| 49 void AnalyzeFileDone(const Results& results); | 48 void AnalyzeFileDone(const ArchiveAnalyzerResults& results); |
| 50 | 49 |
| 51 // The file path of the file to analyze. | 50 // The file path of the file to analyze. |
| 52 const base::FilePath file_path_; | 51 const base::FilePath file_path_; |
| 53 | 52 |
| 54 // Utility client used to send analyze tasks to the utility process. | 53 // Utility client used to send analyze tasks to the utility process. |
| 55 std::unique_ptr< | 54 std::unique_ptr< |
| 56 content::UtilityProcessMojoClient<chrome::mojom::SafeArchiveAnalyzer>> | 55 content::UtilityProcessMojoClient<chrome::mojom::SafeArchiveAnalyzer>> |
| 57 utility_process_mojo_client_; | 56 utility_process_mojo_client_; |
| 58 | 57 |
| 59 // Callback invoked on the UI thread with the file analyze results. | 58 // Callback invoked on the UI thread with the file analyze results. |
| 60 const ResultCallback callback_; | 59 const ResultCallback callback_; |
| 61 | 60 |
| 62 DISALLOW_COPY_AND_ASSIGN(SandboxedZipAnalyzer); | 61 DISALLOW_COPY_AND_ASSIGN(SandboxedZipAnalyzer); |
| 63 }; | 62 }; |
| 64 | 63 |
| 65 } // namespace safe_browsing | 64 } // namespace safe_browsing |
| 66 | 65 |
| 67 #endif // CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_ZIP_ANALYZER_H_ | 66 #endif // CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_ZIP_ANALYZER_H_ |
| OLD | NEW |