pnacl_component_installer.h revision 010d83a9304c5a91596085d917d248abff47903a
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#include <string>
10
11#include "base/callback.h"
12#include "base/compiler_specific.h"
13#include "base/files/file_path.h"
14#include "base/memory/scoped_ptr.h"
15#include "base/version.h"
16#include "chrome/browser/component_updater/component_updater_service.h"
17#include "chrome/browser/component_updater/pnacl/pnacl_profile_observer.h"
18
19namespace base {
20class CommandLine;
21class DictionaryValue;
22}
23
24namespace pnacl {
25// Returns true if PNaCl actually needs an on-demand component update.
26// E.g., if PNaCl is not yet installed and the user is loading a PNaCl app,
27// or the current version is behind chrome's version, and is ABI incompatible
28// with chrome. If not necessary, returns false.
29// May conservatively return false before PNaCl is registered, but
30// should return the right answer after it is registered.
31bool NeedsOnDemandUpdate();
32}
33
34namespace component_updater {
35
36// Component installer responsible for Portable Native Client files.
37// Files can be installed to a shared location, or be installed to
38// a per-user location.
39class PnaclComponentInstaller : public ComponentInstaller {
40 public:
41  PnaclComponentInstaller();
42
43  virtual ~PnaclComponentInstaller();
44
45  virtual void OnUpdateError(int error) OVERRIDE;
46
47  virtual bool Install(const base::DictionaryValue& manifest,
48                       const base::FilePath& unpack_path) OVERRIDE;
49
50  virtual bool GetInstalledFile(const std::string& file,
51                                base::FilePath* installed_file) OVERRIDE;
52
53  // Register a PNaCl component for the first time.
54  void RegisterPnaclComponent(ComponentUpdateService* cus,
55                              const base::CommandLine& command_line);
56
57  // Check the PNaCl version again and re-register with the component
58  // updater service.
59  void ReRegisterPnacl();
60
61  CrxComponent GetCrxComponent();
62
63  // Return true if PNaCl installs are separated by user.
64  bool per_user() const { return per_user_; }
65
66  // If per_user, function to call when profile is changed.
67  void OnProfileChange();
68
69  // Return true if PNaCl updates are disabled.
70  bool updates_disabled() const { return updates_disabled_; }
71
72  // Determine the base directory for storing each version of PNaCl.
73  base::FilePath GetPnaclBaseDirectory();
74
75  base::Version current_version() const { return current_version_; }
76
77  void set_current_version(const base::Version& current_version) {
78    current_version_ = current_version;
79  }
80
81  std::string current_fingerprint() const { return current_fingerprint_; }
82
83  void set_current_fingerprint(const std::string& current_fingerprint) {
84    current_fingerprint_ = current_fingerprint;
85  }
86
87  ComponentUpdateService* cus() const { return cus_; }
88
89 private:
90  bool per_user_;
91  bool updates_disabled_;
92  scoped_ptr<PnaclProfileObserver> profile_observer_;
93  base::FilePath current_profile_path_;
94  base::Version current_version_;
95  std::string current_fingerprint_;
96  ComponentUpdateService* cus_;
97  DISALLOW_COPY_AND_ASSIGN(PnaclComponentInstaller);
98};
99
100}  // namespace component_updater
101
102#endif  // CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_
103