pnacl_component_installer.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <list>
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/callback.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/compiler_specific.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/files/file_path.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/version.h"
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/component_updater/component_updater_service.h"
16c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "chrome/browser/component_updater/pnacl/pnacl_profile_observer.h"
17c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class CommandLine;
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace base {
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class DictionaryValue;
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace pnacl {
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Returns true if PNaCl actually needs an on-demand component update.
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// E.g., if PNaCl is not yet installed and the user is loading a PNaCl app,
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// or the current version is behind chrome's version, and is ABI incompatible
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// with chrome. If not necessary, returns false.
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// May conservatively return false before PNaCl is registered, but
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// should return the right answer after it is registered.
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool NeedsOnDemandUpdate();
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Component installer responsible for Portable Native Client files.
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Files can be installed to a shared location, or be installed to
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// a per-user location.
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class PnaclComponentInstaller : public ComponentInstaller {
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PnaclComponentInstaller();
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~PnaclComponentInstaller();
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnUpdateError(int error) OVERRIDE;
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool Install(const base::DictionaryValue& manifest,
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       const base::FilePath& unpack_path) OVERRIDE;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool GetInstalledFile(const std::string& file,
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                base::FilePath* installed_file) OVERRIDE;
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
51c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Register a PNaCl component for the first time.
52c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  void RegisterPnaclComponent(ComponentUpdateService* cus,
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                              const CommandLine& command_line);
54
55  // Check the PNaCl version again and re-register with the component
56  // updater service.
57  void ReRegisterPnacl();
58
59  CrxComponent GetCrxComponent();
60
61  // Return true if PNaCl installs are separated by user.
62  bool per_user() const { return per_user_; }
63
64  // If per_user, function to call when profile is changed.
65  void OnProfileChange();
66
67  // Return true if PNaCl updates are disabled.
68  bool updates_disabled() const { return updates_disabled_; }
69
70  // Determine the base directory for storing each version of PNaCl.
71  base::FilePath GetPnaclBaseDirectory();
72
73  base::Version current_version() const { return current_version_; }
74
75  void set_current_version(const base::Version& current_version) {
76    current_version_ = current_version;
77  }
78
79  std::string current_fingerprint() const { return current_fingerprint_; }
80
81  void set_current_fingerprint(const std::string& current_fingerprint) {
82    current_fingerprint_ = current_fingerprint;
83  }
84
85  ComponentUpdateService* cus() const { return cus_; }
86
87 private:
88  bool per_user_;
89  bool updates_disabled_;
90  scoped_ptr<PnaclProfileObserver> profile_observer_;
91  base::FilePath current_profile_path_;
92  base::Version current_version_;
93  std::string current_fingerprint_;
94  ComponentUpdateService* cus_;
95  DISALLOW_COPY_AND_ASSIGN(PnaclComponentInstaller);
96};
97
98#endif  // CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_
99