OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_EXTENSIONS_ZIPFILE_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ZIPFILE_INSTALLER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_ZIPFILE_INSTALLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ZIPFILE_INSTALLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | |
12 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
13 #include "base/macros.h" | 12 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
16 #include "content/public/browser/utility_process_host_client.h" | 15 #include "content/public/browser/utility_process_mojo_client.h" |
| 16 #include "extensions/common/extension_unpacker.mojom.h" |
17 | 17 |
18 class ExtensionService; | 18 class ExtensionService; |
19 | 19 |
20 namespace IPC { | |
21 class Message; | |
22 } | |
23 | |
24 namespace extensions { | 20 namespace extensions { |
25 | 21 |
26 // ZipFileInstaller unzips an extension that is zipped up via a utility process. | 22 // ZipFileInstaller unzips an extension in a utility process. On success, the |
27 // The contents are then loaded via UnpackedInstaller. | 23 // extension content is loaded by an extensions::UnpackedInstaller. |
28 class ZipFileInstaller : public content::UtilityProcessHostClient { | 24 class ZipFileInstaller : public base::RefCountedThreadSafe<ZipFileInstaller> { |
29 public: | 25 public: |
30 static scoped_refptr<ZipFileInstaller> Create( | 26 static scoped_refptr<ZipFileInstaller> Create(ExtensionService* service); |
31 ExtensionService* extension_service); | |
32 | 27 |
33 void LoadFromZipFile(const base::FilePath& path); | 28 void LoadFromZipFile(const base::FilePath& zip_file); |
34 | 29 |
35 void set_be_noisy_on_failure(bool value) { be_noisy_on_failure_ = value; } | 30 void set_be_noisy_on_failure(bool value) { be_noisy_on_failure_ = value; } |
36 | 31 |
37 // UtilityProcessHostClient | 32 private: |
38 bool OnMessageReceived(const IPC::Message& message) override; | 33 friend class base::RefCountedThreadSafe<ZipFileInstaller>; |
39 | 34 |
40 private: | 35 explicit ZipFileInstaller(ExtensionService* service); |
41 explicit ZipFileInstaller(ExtensionService* extension_service); | 36 ~ZipFileInstaller(); |
42 ~ZipFileInstaller() override; | |
43 | 37 |
44 void PrepareTempDir(); | 38 void PrepareTempDir(const base::FilePath& zip_file); |
45 void StartWorkOnIOThread(const base::FilePath& temp_dir); | 39 void UnzipOnUIThread(const base::FilePath& unzip_dir); |
46 void ReportSuccessOnUIThread(const base::FilePath& unzipped_path); | 40 void UnzipDone(bool success); |
47 void ReportErrorOnUIThread(const std::string& error); | 41 void ReportErrorOnUIThread(const std::string& error); |
48 | 42 |
49 void OnUnzipSucceeded(const base::FilePath& unzipped_path); | |
50 void OnUnzipFailed(const std::string& error); | |
51 | |
52 bool be_noisy_on_failure_; | 43 bool be_noisy_on_failure_; |
53 base::WeakPtr<ExtensionService> extension_service_weak_; | 44 base::WeakPtr<ExtensionService> extension_service_weak_; |
54 base::FilePath zip_path_; | 45 |
| 46 // File containing the extension to unzip. |
| 47 base::FilePath zip_file_; |
| 48 |
| 49 // Temporary directory where |zip_file_| is unzipped. |
| 50 base::FilePath temp_dir_; |
| 51 |
| 52 // Utility process used to perform the unzip operation. |
| 53 std::unique_ptr< |
| 54 content::UtilityProcessMojoClient<extensions::mojom::ExtensionUnpacker>> |
| 55 utility_process_mojo_client_; |
55 | 56 |
56 DISALLOW_COPY_AND_ASSIGN(ZipFileInstaller); | 57 DISALLOW_COPY_AND_ASSIGN(ZipFileInstaller); |
57 }; | 58 }; |
58 | 59 |
59 } // namespace extensions | 60 } // namespace extensions |
60 | 61 |
61 #endif // CHROME_BROWSER_EXTENSIONS_ZIPFILE_INSTALLER_H_ | 62 #endif // CHROME_BROWSER_EXTENSIONS_ZIPFILE_INSTALLER_H_ |
OLD | NEW |