OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/file_path.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "base/ref_counted.h" |
| 13 #include "chrome/browser/extensions/extensions_service.h" |
| 14 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
| 15 #include "chrome/common/extensions/extension.h" |
| 16 |
| 17 // This class installs a crx file into a profile. |
| 18 // |
| 19 // Installing a CRX is a multi-step process, including unpacking the crx, |
| 20 // validating it, prompting the user, and installing. Since many of these |
| 21 // steps must occur on the file thread, this class contains a copy of all data |
| 22 // necessary to do its job. (This also minimizes external dependencies for |
| 23 // easier testing). |
| 24 // |
| 25 // |
| 26 // Lifetime management: |
| 27 // |
| 28 // This class is ref-counted by each call it makes to itself on another thread, |
| 29 // and by UtilityProcessHost. |
| 30 // |
| 31 // Additionally, we hold a reference to our own client so that it lives at least |
| 32 // long enough to receive the result of unpacking. |
| 33 // |
| 34 // |
| 35 // NOTE: This class is rather huge at the moment because it is handling all |
| 36 // types of installation (external, autoupdate, and manual). In the future, |
| 37 // manual installation will probably pulled out of it. |
| 38 // |
| 39 // TODO(aa): Pull out the manual installation bits. |
| 40 // TODO(aa): Pull out a frontend interface for testing? |
| 41 class CrxInstaller : public SandboxedExtensionUnpackerClient { |
| 42 public: |
| 43 CrxInstaller(const FilePath& crx_path, |
| 44 const FilePath& install_directory, |
| 45 Extension::Location install_source, |
| 46 const std::string& expected_id, |
| 47 bool extensions_enabled, |
| 48 bool is_from_gallery, |
| 49 bool show_prompts, |
| 50 bool delete_crx, |
| 51 MessageLoop* file_loop, |
| 52 ExtensionsService* frontend); |
| 53 ~CrxInstaller() { |
| 54 // This is only here for debugging purposes, as a convenient place to set |
| 55 // breakpoints. |
| 56 } |
| 57 |
| 58 private: |
| 59 // SandboxedExtensionUnpackerClient |
| 60 virtual void OnUnpackFailure(const std::string& error_message); |
| 61 virtual void OnUnpackSuccess(const FilePath& temp_dir, |
| 62 const FilePath& extension_dir, |
| 63 Extension* extension); |
| 64 |
| 65 // Confirm with the user that it is OK to install this extension. |
| 66 // |
| 67 // Note that this runs on the file thread. It happens to be OK to do this on |
| 68 // Windows and Mac, and although ugly, we leave it because this is all getting |
| 69 // pulled out soon, anyway. |
| 70 // |
| 71 // TODO(aa): Pull this up, closer to the UI layer. |
| 72 bool ConfirmInstall(); |
| 73 |
| 74 // Runs on File thread. Install the unpacked extension into the profile and |
| 75 // notify the frontend. |
| 76 void CompleteInstall(); |
| 77 |
| 78 // Result reporting. |
| 79 void ReportFailureFromFileThread(const std::string& error); |
| 80 void ReportFailureFromUIThread(const std::string& error); |
| 81 void ReportOverinstallFromFileThread(); |
| 82 void ReportSuccessFromFileThread(); |
| 83 |
| 84 // The crx file we're installing. |
| 85 FilePath crx_path_; |
| 86 |
| 87 // The directory extensions are installed to. |
| 88 FilePath install_directory_; |
| 89 |
| 90 // The location the installation came from (bundled with Chromium, registry, |
| 91 // manual install, etc). This metadata is saved with the installation if |
| 92 // successful. |
| 93 Extension::Location install_source_; |
| 94 |
| 95 // For updates and external installs we have an ID we're expecting the |
| 96 // extension to contain. |
| 97 std::string expected_id_; |
| 98 |
| 99 // Whether extension installation is set. We can't just check this before |
| 100 // trying to install because themes are special-cased to always be allowed. |
| 101 bool extensions_enabled_; |
| 102 |
| 103 // Whether this installation was initiated from the gallery. We trust it more |
| 104 // and have special UI if it was. |
| 105 bool is_from_gallery_; |
| 106 |
| 107 // Whether we shoud should show prompts. This is sometimes false for testing |
| 108 // and autoupdate. |
| 109 bool show_prompts_; |
| 110 |
| 111 // Whether we're supposed to delete the source crx file on destruction. |
| 112 bool delete_crx_; |
| 113 |
| 114 // The message loop to use for file IO. |
| 115 MessageLoop* file_loop_; |
| 116 |
| 117 // The message loop the UI is running on. |
| 118 MessageLoop* ui_loop_; |
| 119 |
| 120 // The extension we're installing. We own this and either pass it off to |
| 121 // ExtensionsService on success, or delete it on failure. |
| 122 scoped_ptr<Extension> extension_; |
| 123 |
| 124 // The temp directory extension resources were unpacked to. We own this and |
| 125 // must delete it when we are done with it. |
| 126 FilePath temp_dir_; |
| 127 |
| 128 // The frontend we will report results back to. |
| 129 scoped_refptr<ExtensionsService> frontend_; |
| 130 |
| 131 // The root of the unpacked extension directory. This is a subdirectory of |
| 132 // temp_dir_, so we don't have to delete it explicitly. |
| 133 FilePath unpacked_extension_root_; |
| 134 |
| 135 // The unpacker we will use to unpack the extension. |
| 136 SandboxedExtensionUnpacker* unpacker_; |
| 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(CrxInstaller); |
| 139 }; |
| 140 |
| 141 #endif // CHROME_BROWSER_EXTENSIONS_CRX_INSTALLER_H_ |
OLD | NEW |