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