pnacl_component_installer.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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 19class CommandLine; 20 21namespace base { 22class 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. 28class 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& current_version) { 67 current_version_ = current_version; 68 } 69 70 std::string current_fingerprint() const { return current_fingerprint_; } 71 72 void set_current_fingerprint(const std::string& current_fingerprint) { 73 current_fingerprint_ = current_fingerprint; 74 } 75 76 ComponentUpdateService* cus() const { return cus_; } 77 78 typedef base::Callback<void(bool)> InstallCallback; 79 80 // Ask the component updater service to do a first-install for PNaCl. 81 // The |installed| callback will be run with |true| on success, 82 // or run with |false| on an error. The callback is called on the UI thread. 83 void RequestFirstInstall(const InstallCallback& installed); 84 85 private: 86 friend class PnaclUpdaterObserver; 87 88 // Called when a RequestFirstInstall completed successfully. 89 void NotifyInstallSuccess(); 90 91 // Called when a RequestFirstInstall will not happen, or an error occurred. 92 void NotifyInstallError(); 93 94 bool per_user_; 95 bool updates_disabled_; 96 scoped_ptr<PnaclProfileObserver> profile_observer_; 97 base::FilePath current_profile_path_; 98 base::Version current_version_; 99 std::string current_fingerprint_; 100 ComponentUpdateService* cus_; 101 // The one callback to call when there is a RequestFirstInstall. 102 InstallCallback install_callback_; 103 // Component updater service observer, to determine when an on-demand 104 // install request failed. 105 scoped_ptr<PnaclUpdaterObserver> updater_observer_; 106 DISALLOW_COPY_AND_ASSIGN(PnaclComponentInstaller); 107}; 108 109#endif // CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_ 110