1 // Copyright 2015 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_DMG_ANALYZER_MAC_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_DMG_ANALYZER_MAC_H_
8 #include "base/callback.h"
9 #include "base/files/file.h"
10 #include "base/files/file_path.h"
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/browser/utility_process_host.h"
14 #include "content/public/browser/utility_process_host_client.h"
16 namespace safe_browsing
{
18 namespace zip_analyzer
{
22 // This class is used to analyze DMG files in a sandboxed utility process for
23 // file download protection. This class must be created on the UI thread, and
24 // which is where the result callback will be invoked.
25 class SandboxedDMGAnalyzer
: public content::UtilityProcessHostClient
{
27 // Callback that is invoked when the analysis results are ready.
28 using ResultsCallback
= base::Callback
<void(const zip_analyzer::Results
&)>;
30 SandboxedDMGAnalyzer(const base::FilePath
& dmg_file
,
31 const ResultsCallback
& callback
);
33 // Begins the analysis. This must be called on the UI thread.
37 ~SandboxedDMGAnalyzer() override
;
39 // Called on the blocking pool, this opens the DMG file, in preparation for
40 // sending the FD to the utility process.
43 // Called on the IO thread, this starts the utility process.
46 // content::UtilityProcessHostClient:
47 bool OnMessageReceived(const IPC::Message
& message
) override
;
49 // Message handler for reply ping when the utility process has started.
50 void OnUtilityProcessStarted();
52 // Message handler to receive the results of the analysis. Invokes the
54 void OnAnalysisFinished(const zip_analyzer::Results
& results
);
56 const base::FilePath file_path_
; // The path of the DMG file.
57 base::File file_
; // The opened file handle for |file_path_|.
59 // Weak reference to the utility process, which owns this.
60 base::WeakPtr
<content::UtilityProcessHost
> utility_process_host_
;
62 const ResultsCallback callback_
; // Result callback.
63 bool callback_called_
; // Whether |callback_| has already been invoked.
65 DISALLOW_COPY_AND_ASSIGN(SandboxedDMGAnalyzer
);
68 } // namespace safe_browsing
70 #endif // CHROME_BROWSER_SAFE_BROWSING_SANDBOXED_DMG_ANALYZER_MAC_H_