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