1 // Copyright (c) 2011 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_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_ 6 #define CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_ 7 8 #include <list> 9 10 #include "base/callback.h" 11 #include "base/compiler_specific.h" 12 #include "base/files/file_path.h" 13 #include "base/memory/scoped_ptr.h" 14 #include "base/version.h" 15 #include "chrome/browser/component_updater/component_updater_service.h" 16 #include "chrome/browser/component_updater/pnacl/pnacl_profile_observer.h" 17 #include "chrome/browser/component_updater/pnacl/pnacl_updater_observer.h" 18 19 class CommandLine; 20 21 namespace base { 22 class DictionaryValue; 23 } 24 25 // Component installer responsible for Portable Native Client files. 26 // Files can be installed to a shared location, or be installed to 27 // a per-user location. 28 class PnaclComponentInstaller : public ComponentInstaller { 29 public: 30 PnaclComponentInstaller(); 31 32 virtual ~PnaclComponentInstaller(); 33 34 virtual void OnUpdateError(int error) OVERRIDE; 35 36 virtual bool Install(const base::DictionaryValue& manifest, 37 const base::FilePath& unpack_path) OVERRIDE; 38 39 virtual bool GetInstalledFile(const std::string& file, 40 base::FilePath* installed_file) OVERRIDE; 41 42 // Register a PNaCl component for the first time. 43 void RegisterPnaclComponent(ComponentUpdateService* cus, 44 const CommandLine& command_line); 45 46 // Check the PNaCl version again and re-register with the component 47 // updater service. 48 void ReRegisterPnacl(); 49 50 CrxComponent GetCrxComponent(); 51 52 // Return true if PNaCl installs are separated by user. 53 bool per_user() const { return per_user_; } 54 55 // If per_user, function to call when profile is changed. 56 void OnProfileChange(); 57 58 // Return true if PNaCl updates are disabled. 59 bool updates_disabled() const { return updates_disabled_; } 60 61 // Determine the base directory for storing each version of PNaCl. 62 base::FilePath GetPnaclBaseDirectory(); 63 64 base::Version current_version() const { return current_version_; } 65 66 void set_current_version(const base::Version& v) { current_version_ = v; } 67 68 ComponentUpdateService* cus() const { return cus_; } 69 70 typedef base::Callback<void(bool)> InstallCallback; 71 72 // Ask the component updater service to do a first-install for PNaCl. 73 // The |installed| callback will be run with |true| on success, 74 // or run with |false| on an error. The callback is called on the UI thread. 75 void RequestFirstInstall(const InstallCallback& installed); 76 77 private: 78 friend class PnaclUpdaterObserver; 79 80 // Called when a RequestFirstInstall completed successfully. 81 void NotifyInstallSuccess(); 82 83 // Called when a RequestFirstInstall will not happen, or an error occurred. 84 void NotifyInstallError(); 85 86 bool per_user_; 87 bool updates_disabled_; 88 scoped_ptr<PnaclProfileObserver> profile_observer_; 89 base::FilePath current_profile_path_; 90 base::Version current_version_; 91 ComponentUpdateService* cus_; 92 // The one callback to call when there is a RequestFirstInstall. 93 InstallCallback install_callback_; 94 // Component updater service observer, to determine when an on-demand 95 // install request failed. 96 scoped_ptr<PnaclUpdaterObserver> updater_observer_; 97 DISALLOW_COPY_AND_ASSIGN(PnaclComponentInstaller); 98 }; 99 100 #endif // CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_ 101