1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/version.h"
14 #include "chrome/browser/component_updater/component_updater_service.h"
17 class DictionaryValue;
21 namespace component_updater {
23 // Components should use a DefaultComponentInstaller by defining a class that
24 // implements the members of ComponentInstallerTraits, and then registering a
25 // DefaultComponentInstaller that has been constructed with an instance of that
27 class ComponentInstallerTraits {
29 virtual ~ComponentInstallerTraits();
31 // Verifies that a working installation resides within the directory specified
32 // by |dir|. |dir| is of the form <base directory>/<version>.
33 // Called only from a thread belonging to a blocking thread pool.
34 // The implementation of this function must be efficient since the function
35 // can be called when Chrome starts.
36 virtual bool VerifyInstallation(const base::FilePath& dir) const = 0;
38 // Returns true if the component can be automatically updated. Called once
39 // during component registration from the UI thread.
40 virtual bool CanAutoUpdate() const = 0;
42 // OnCustomInstall is called during the installation process. Components that
43 // require custom installation operations should implement them here.
44 // Returns false if a custom operation failed, and true otherwise.
45 // Called only from a thread belonging to a blocking thread pool.
46 virtual bool OnCustomInstall(const base::DictionaryValue& manifest,
47 const base::FilePath& install_dir) = 0;
49 // ComponentReady is called in two cases:
50 // 1) After an installation is successfully completed.
51 // 2) During component registration if the component is already installed.
52 // In both cases the install is verified before this is called. This method
53 // is guaranteed to be called before any observers of the component are
54 // notified of a successful install, and is meant to support follow-on work
55 // such as updating paths elsewhere in Chrome. Called on the UI thread.
56 // |version| is the version of the component.
57 // |install_dir| is the path to the install directory for this version.
58 // |manifest| is the manifest for this version of the component.
59 virtual void ComponentReady(const base::Version& version,
60 const base::FilePath& install_dir,
61 scoped_ptr<base::DictionaryValue> manifest) = 0;
63 // Returns the directory that the installer will place versioned installs of
64 // the component into.
65 virtual base::FilePath GetBaseDirectory() const = 0;
67 // Returns the component's SHA2 hash as raw bytes.
68 virtual void GetHash(std::vector<uint8>* hash) const = 0;
70 // Returns the human-readable name of the component.
71 virtual std::string GetName() const = 0;
74 // A DefaultComponentInstaller is intended to be final, and not derived from.
75 // Customization must be provided by passing a ComponentInstallerTraits object
76 // to the constructor.
77 class DefaultComponentInstaller : public ComponentInstaller {
79 explicit DefaultComponentInstaller(
80 scoped_ptr<ComponentInstallerTraits> installer_traits);
82 // Registers the component for update checks and installs.
83 void Register(ComponentUpdateService* cus);
85 // Overridden from ComponentInstaller:
86 virtual void OnUpdateError(int error) OVERRIDE;
87 virtual bool Install(const base::DictionaryValue& manifest,
88 const base::FilePath& unpack_path) OVERRIDE;
89 virtual bool GetInstalledFile(const std::string& file,
90 base::FilePath* installed_file) OVERRIDE;
92 virtual ~DefaultComponentInstaller();
95 base::FilePath GetInstallDirectory();
96 bool InstallHelper(const base::DictionaryValue& manifest,
97 const base::FilePath& unpack_path,
98 const base::FilePath& install_path);
99 void StartRegistration(ComponentUpdateService* cus);
100 void FinishRegistration(ComponentUpdateService* cus);
102 base::Version current_version_;
103 std::string current_fingerprint_;
104 scoped_ptr<base::DictionaryValue> current_manifest_;
105 scoped_ptr<ComponentInstallerTraits> installer_traits_;
107 DISALLOW_COPY_AND_ASSIGN(DefaultComponentInstaller);
110 } // namespace component_updater
112 #endif // CHROME_BROWSER_COMPONENT_UPDATER_DEFAULT_COMPONENT_INSTALLER_H_