pnacl_component_installer.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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_forward.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  // Return true if PNaCl installs are separated by user.
51  bool per_user() const { return per_user_; }
52
53  // If per_user, function to call when profile is changed.
54  void OnProfileChange();
55
56  // Return true if PNaCl updates are disabled.
57  bool updates_disabled() const { return updates_disabled_; }
58
59  // Determine the base directory for storing each version of PNaCl.
60  base::FilePath GetPnaclBaseDirectory();
61
62  base::Version current_version() const { return current_version_; }
63
64  void set_current_version(const base::Version& v) { current_version_ = v; }
65
66  ComponentUpdateService* cus() const { return cus_; }
67
68  typedef base::Callback<void(bool)> InstallCallback;
69  void AddInstallCallback(const InstallCallback& cb);
70
71  void NotifyInstallError();
72
73  void NotifyInstallSuccess();
74
75 private:
76  // Cancel a particular callback after a timeout.
77  void CancelCallback(int callback_num);
78
79  void NotifyAllWithResult(bool status);
80
81  bool per_user_;
82  bool updates_disabled_;
83  scoped_ptr<PnaclProfileObserver> profile_observer_;
84  base::FilePath current_profile_path_;
85  base::Version current_version_;
86  ComponentUpdateService* cus_;
87  // Counter to issue identifiers to each callback.
88  int callback_nums_;
89  // List of callbacks to issue when an install completes successfully.
90  std::list<std::pair<InstallCallback, int> > install_callbacks_;
91  // Component updater service observer, to determine when an on-demand
92  // install request failed.
93  scoped_ptr<PnaclUpdaterObserver> updater_observer_;
94  DISALLOW_COPY_AND_ASSIGN(PnaclComponentInstaller);
95};
96
97// Returns true if this browser is compatible with the given Pnacl component
98// manifest, with the version specified in the manifest in |version_out|.
99bool CheckPnaclComponentManifest(const base::DictionaryValue& manifest,
100                                 base::Version* version_out);
101
102// Ask the given component updater service to do a first-install for PNaCl.
103// The |installed| callback will be run with |true| on success,
104// or run with |false| on an error. The callback is called on the UI thread.
105void RequestFirstInstall(ComponentUpdateService* cus,
106                         PnaclComponentInstaller* pci,
107                         const base::Callback<void(bool)>& installed);
108
109#endif  // CHROME_BROWSER_COMPONENT_UPDATER_PNACL_PNACL_COMPONENT_INSTALLER_H_
110