pnacl_component_installer.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include <list> 9eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/callback_forward.h" 11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/compiler_specific.h" 12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/files/file_path.h" 13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/version.h" 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/component_updater/component_updater_service.h" 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/component_updater/pnacl/pnacl_profile_observer.h" 17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/component_updater/pnacl/pnacl_updater_observer.h" 18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class CommandLine; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DictionaryValue; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Component installer responsible for Portable Native Client files. 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Files can be installed to a shared location, or be installed to 27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// a per-user location. 28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class PnaclComponentInstaller : public ComponentInstaller { 29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) PnaclComponentInstaller(); 31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ~PnaclComponentInstaller(); 33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnUpdateError(int error) OVERRIDE; 35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool Install(const base::DictionaryValue& manifest, 37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const base::FilePath& unpack_path) OVERRIDE; 38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual bool GetInstalledFile(const std::string& file, 40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::FilePath* installed_file) OVERRIDE; 41eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Register a PNaCl component for the first time. 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void RegisterPnaclComponent(ComponentUpdateService* cus, 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const CommandLine& command_line); 45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Check the PNaCl version again and re-register with the component 47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // updater service. 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void ReRegisterPnacl(); 49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 50eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Return true if PNaCl installs are separated by user. 51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool per_user() const { return per_user_; } 52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // If per_user, function to call when profile is changed. 54c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void OnProfileChange(); 55c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Return true if PNaCl updates are disabled. 57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool updates_disabled() const { return updates_disabled_; } 58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Determine the base directory for storing each version of PNaCl. 60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::FilePath GetPnaclBaseDirectory(); 61c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Version current_version() const { return current_version_; } 63c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void set_current_version(const base::Version& v) { current_version_ = v; } 65c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 66c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ComponentUpdateService* cus() const { return cus_; } 67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch typedef base::Callback<void(bool)> InstallCallback; 69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void AddInstallCallback(const InstallCallback& cb); 70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void NotifyInstallError(); 72eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void NotifyInstallSuccess(); 74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 76eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Cancel a particular callback after a timeout. 77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void CancelCallback(int callback_num); 78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 79eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void NotifyAllWithResult(bool status); 80eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool per_user_; 82eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool updates_disabled_; 83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<PnaclProfileObserver> profile_observer_; 84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::FilePath current_profile_path_; 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Version current_version_; 86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ComponentUpdateService* cus_; 87eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Counter to issue identifiers to each callback. 88eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch int callback_nums_; 89eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // List of callbacks to issue when an install completes successfully. 90eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::list<std::pair<InstallCallback, int> > install_callbacks_; 91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Component updater service observer, to determine when an on-demand 92eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // install request failed. 93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<PnaclUpdaterObserver> updater_observer_; 94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(PnaclComponentInstaller); 95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns true if this browser is compatible with the given Pnacl component 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// manifest, with the version specified in the manifest in |version_out|. 99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool CheckPnaclComponentManifest(const base::DictionaryValue& manifest, 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::Version* version_out); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Ask the given component updater service to do a first-install for PNaCl. 103eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// The |installed| callback will be run with |true| on success, 104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// or run with |false| on an error. The callback is called on the UI thread. 105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid RequestFirstInstall(ComponentUpdateService* cus, 106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch PnaclComponentInstaller* pci, 107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::Callback<void(bool)>& installed); 108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_ 110