Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / safe_browsing / sandboxed_dmg_analyzer_mac.h
blobc9510e5f97531690598bab8c28cbf4f0fd3423da
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 {
19 struct Results;
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 {
26 public:
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.
34 void Start();
36 private:
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.
41 void OpenDMGFile();
43 // Called on the IO thread, this starts the utility process.
44 void StartAnalysis();
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
53 // |callback_|.
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_