Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / safe_browsing / sandboxed_zip_analyzer.h
blobbb08f3e9e4f76797020b13c19a273fe4ef1f4591
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
3 // found in the LICENSE file.
4 //
5 // Browser-side interface to analyze zip files for SafeBrowsing download
6 // protection. The actual zip decoding is performed in a sandboxed utility
7 // process.
8 //
9 // This class lives on the UI thread.
11 #ifndef CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_ZIP_ANALYZER_H_
12 #define CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_ZIP_ANALYZER_H_
14 #include "base/basictypes.h"
15 #include "base/callback.h"
16 #include "base/files/file.h"
17 #include "base/files/file_path.h"
18 #include "base/memory/weak_ptr.h"
19 #include "content/public/browser/utility_process_host.h"
20 #include "content/public/browser/utility_process_host_client.h"
22 namespace IPC {
23 class Message;
26 namespace safe_browsing {
27 namespace zip_analyzer {
28 struct Results;
31 class SandboxedZipAnalyzer : public content::UtilityProcessHostClient {
32 public:
33 // Callback that is invoked when the analysis results are ready.
34 typedef base::Callback<void(const zip_analyzer::Results&)> ResultCallback;
36 SandboxedZipAnalyzer(const base::FilePath& zip_file,
37 const ResultCallback& result_callback);
39 // Posts a task to start the zip analysis in the utility process.
40 void Start();
42 private:
43 ~SandboxedZipAnalyzer() override;
45 // Posts a fire-and-forget task to close the temporary file in the blocking
46 // pool.
47 void CloseTemporaryFile();
49 // Creates the sandboxed utility process and tells it to start analysis.
50 // Runs on a worker thread.
51 void AnalyzeInSandbox();
53 // content::UtilityProcessHostClient implementation.
54 // These notifications run on the IO thread.
55 bool OnMessageReceived(const IPC::Message& message) override;
57 // Launches the utility process. Must run on the IO thread.
58 void StartProcessOnIOThread();
60 // Notification that the utility process is running, and we can now get its
61 // process handle.
62 void OnUtilityProcessStarted();
64 // Notification from the utility process that the zip file has been analyzed,
65 // with the given results. Runs on the IO thread.
66 void OnAnalyzeZipFileFinished(const zip_analyzer::Results& results);
68 const base::FilePath zip_file_name_;
69 // Once we have opened the file, we store the handle so that we can use it
70 // once the utility process has launched.
71 base::File zip_file_;
73 // A temporary file to be used by the utility process for extracting files
74 // from the archive.
75 base::File temp_file_;
76 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
77 const ResultCallback callback_;
78 // Initialized on the UI thread, but only accessed on the IO thread.
79 bool callback_called_;
81 DISALLOW_COPY_AND_ASSIGN(SandboxedZipAnalyzer);
84 } // namespace safe_browsing
86 #endif // CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_ZIP_ANALYZER_H_